automatically enable chronicles logs for the test harness when DEBUG_TESTHARNESS=1

This commit is contained in:
Eric 2025-01-22 19:23:08 +11:00
parent 53ca896bfc
commit e3b021e44f
No known key found for this signature in database
2 changed files with 35 additions and 12 deletions

View File

@ -148,7 +148,7 @@ endif
ifdef DEBUG_HARDHAT ifdef DEBUG_HARDHAT
TEST_PARAMS := $(TEST_PARAMS) -d:DebugHardhat=$(DEBUG_HARDHAT) TEST_PARAMS := $(TEST_PARAMS) -d:DebugHardhat=$(DEBUG_HARDHAT)
endif endif
ifdef DEBUG_CODEXNODES ifdef DEBUG_CODEXNODES # true by default
TEST_PARAMS := $(TEST_PARAMS) -d:DebugCodexNodes=$(DEBUG_CODEXNODES) TEST_PARAMS := $(TEST_PARAMS) -d:DebugCodexNodes=$(DEBUG_CODEXNODES)
endif endif
ifdef DEBUG_UPDATES ifdef DEBUG_UPDATES

View File

@ -1,10 +1,14 @@
mode = ScriptMode.Verbose mode = ScriptMode.Verbose
import std/os except commandLineParams import std/os except commandLineParams
import std/strutils
### Helper functions ### Helper functions
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") = proc truthy(val: string): bool =
const truthySwitches = @["yes", "1", "on", "true"]
return val in truthySwitches
proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
if not dirExists "build": if not dirExists "build":
mkDir "build" mkDir "build"
@ -14,13 +18,15 @@ proc buildBinary(name: string, srcDir = "./", params = "", lang = "c") =
for param in commandLineParams(): for param in commandLineParams():
extra_params &= " " & param extra_params &= " " & param
else: else:
for i in 2..<paramCount(): for i in 2 ..< paramCount():
extra_params &= " " & paramStr(i) extra_params &= " " & paramStr(i)
let let
# Place build output in 'build' folder, even if name includes a longer path. # Place build output in 'build' folder, even if name includes a longer path.
outName = os.lastPathPart(name) outName = os.lastPathPart(name)
cmd = "nim " & lang & " --out:build/" & outName & " " & extra_params & " " & srcDir & name & ".nim" cmd =
"nim " & lang & " --out:build/" & outName & " " & extra_params & " " & srcDir &
name & ".nim"
exec(cmd) exec(cmd)
@ -29,7 +35,8 @@ proc test(name: string, srcDir = "tests/", params = "", lang = "c") =
exec "build/" & name exec "build/" & name
task codex, "build codex binary": task codex, "build codex binary":
buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE" buildBinary "codex",
params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE"
task toolsCirdl, "build tools/cirdl binary": task toolsCirdl, "build tools/cirdl binary":
buildBinary "tools/cirdl/cirdl" buildBinary "tools/cirdl/cirdl"
@ -41,8 +48,14 @@ task testContracts, "Build & run Codex Contract tests":
test "testContracts" test "testContracts"
task testIntegration, "Run integration tests": task testIntegration, "Run integration tests":
buildBinary "codex", params = "-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:codex_enable_proof_failures=true" buildBinary "codex",
test "testIntegration" params =
"-d:chronicles_runtime_filtering -d:chronicles_log_level=TRACE -d:codex_enable_proof_failures=true"
var testParams = ""
for i in 2 ..< paramCount():
if "DebugTestHarness" in paramStr(i) and truthy paramStr(i).split('=')[1]:
testParams = "-d:chronicles_log_level=TRACE -d:chronicles_sinks=textlines[stdout]"
test "testIntegration", params = testParams
# use params to enable logging from the integration test executable # use params to enable logging from the integration test executable
# test "testIntegration", params = "-d:chronicles_sinks=textlines[notimestamps,stdout],textlines[dynamic] " & # test "testIntegration", params = "-d:chronicles_sinks=textlines[notimestamps,stdout],textlines[dynamic] " &
# "-d:chronicles_enabled_topics:integration:TRACE" # "-d:chronicles_enabled_topics:integration:TRACE"
@ -90,15 +103,25 @@ task coverage, "generates code coverage report":
var nimSrcs = " " var nimSrcs = " "
for f in walkDirRec("codex", {pcFile}): for f in walkDirRec("codex", {pcFile}):
if f.endswith(".nim"): nimSrcs.add " " & f.absolutePath.quoteShell() if f.endswith(".nim"):
nimSrcs.add " " & f.absolutePath.quoteShell()
echo "======== Running Tests ======== " echo "======== Running Tests ======== "
test "coverage", srcDir = "tests/", params = " --nimcache:nimcache/coverage -d:release -d:codex_enable_proof_failures=true" test "coverage",
srcDir = "tests/",
params =
" --nimcache:nimcache/coverage -d:release -d:codex_enable_proof_failures=true"
exec("rm nimcache/coverage/*.c") exec("rm nimcache/coverage/*.c")
rmDir("coverage"); mkDir("coverage") rmDir("coverage")
mkDir("coverage")
echo " ======== Running LCOV ======== " echo " ======== Running LCOV ======== "
exec("lcov --capture --directory nimcache/coverage --output-file coverage/coverage.info") exec(
exec("lcov --extract coverage/coverage.info --output-file coverage/coverage.f.info " & nimSrcs) "lcov --capture --directory nimcache/coverage --output-file coverage/coverage.info"
)
exec(
"lcov --extract coverage/coverage.info --output-file coverage/coverage.f.info " &
nimSrcs
)
echo " ======== Generating HTML coverage report ======== " echo " ======== Generating HTML coverage report ======== "
exec("genhtml coverage/coverage.f.info --output-directory coverage/report ") exec("genhtml coverage/coverage.f.info --output-directory coverage/report ")
echo " ======== Coverage report Done ======== " echo " ======== Coverage report Done ======== "