diff --git a/bin/cli.js b/bin/cli.js index 941539a..3f7f851 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -59,7 +59,7 @@ const onlyFailures = options.onlyFailures || false; const collectCoverage = Boolean(options.collectCoverage) || config.collectCoverage || - (testFiles !== undefined && options.testNamePattern !== undefined && !onlyFailures); + (testFiles === undefined && options.testNamePattern === undefined && !onlyFailures); const testOption = { includes, diff --git a/instrumentation/BasicBlockWalker.cpp b/instrumentation/BasicBlockWalker.cpp index 2f6fbea..ee1c909 100644 --- a/instrumentation/BasicBlockWalker.cpp +++ b/instrumentation/BasicBlockWalker.cpp @@ -20,7 +20,7 @@ void BasicBlockWalker::basicBlockWalk() noexcept { } void BasicBlockWalker::visitExpression(wasm::Expression *curr) noexcept { - if (currBasicBlock == nullptr) { + if (currBasicBlock == nullptr || curr->is()) { return; } // push information @@ -33,6 +33,14 @@ void BasicBlockWalker::visitExpression(wasm::Expression *curr) noexcept { } } +void BasicBlockWalker::doEndBlock(BasicBlockWalker *self, wasm::Expression **currp) { + wasm::CFGWalker, + BasicBlockInfo>::doEndBlock(self, currp); + if (self->currBasicBlock != nullptr) { + self->currBasicBlock->contents.exprs.push_back(*currp); + } +} + static bool isBasicBlockContainUnreachable(BasicBlockWalker::BasicBlock &block, std::set unreachableBlocks) { diff --git a/instrumentation/BasicBlockWalker.hpp b/instrumentation/BasicBlockWalker.hpp index db03685..d113c92 100644 --- a/instrumentation/BasicBlockWalker.hpp +++ b/instrumentation/BasicBlockWalker.hpp @@ -120,6 +120,8 @@ class BasicBlockWalker final ///@param curr Current expression void visitExpression(wasm::Expression *const curr) noexcept; + static void doEndBlock(BasicBlockWalker* self, wasm::Expression** currp); + /// ///@brief Inherit from CFGWalker for function visitor /// diff --git a/tests/cpp/lit/covInstrument/do_while_break.wast.debug.json b/tests/cpp/lit/covInstrument/do_while_break.wast.debug.json index b5c0fec..2ed7372 100644 --- a/tests/cpp/lit/covInstrument/do_while_break.wast.debug.json +++ b/tests/cpp/lit/covInstrument/do_while_break.wast.debug.json @@ -26,7 +26,6 @@ [0, 7, 18] ], [[0, 4, 2]], - [[0, 4, 2]], [[0, 8, 9]] ] } diff --git a/tests/cpp/lit/covInstrument/do_while_break.wast.run.log b/tests/cpp/lit/covInstrument/do_while_break.wast.run.log index 2a3bbe6..aa9ac4c 100644 --- a/tests/cpp/lit/covInstrument/do_while_break.wast.run.log +++ b/tests/cpp/lit/covInstrument/do_while_break.wast.run.log @@ -11,4 +11,3 @@ basic block entry trace to: function=0, basic block=3 basic block entry trace to: function=0, basic block=1 basic block entry trace to: function=0, basic block=2 basic block entry trace to: function=0, basic block=5 -basic block entry trace to: function=0, basic block=6 diff --git a/tests/cpp/lit/covInstrument/do_while_continue.wast.debug.json b/tests/cpp/lit/covInstrument/do_while_continue.wast.debug.json index e283660..0813c4c 100644 --- a/tests/cpp/lit/covInstrument/do_while_continue.wast.debug.json +++ b/tests/cpp/lit/covInstrument/do_while_continue.wast.debug.json @@ -3,10 +3,10 @@ "debugInfos": { "main": { "branchInfo": [ - [1, 2], [1, 3], - [4, 5], - [4, 1] + [1, 2], + [3, 4], + [3, 1] ], "index": 0, "lineInfo": [ @@ -21,7 +21,6 @@ [0, 6, 16] ], [[0, 6, 19]], - [[0, 4, 2]], [ [0, 7, 10], [0, 7, 18] diff --git a/tests/cpp/lit/covInstrument/do_while_continue.wast.run.log b/tests/cpp/lit/covInstrument/do_while_continue.wast.run.log index 407dc41..a076cfb 100644 --- a/tests/cpp/lit/covInstrument/do_while_continue.wast.run.log +++ b/tests/cpp/lit/covInstrument/do_while_continue.wast.run.log @@ -2,10 +2,8 @@ make directly call to function index=0 basic block entry trace to: function=0, basic block=0 basic block entry trace to: function=0, basic block=1 basic block entry trace to: function=0, basic block=3 -basic block entry trace to: function=0, basic block=4 basic block entry trace to: function=0, basic block=1 basic block entry trace to: function=0, basic block=2 basic block entry trace to: function=0, basic block=3 basic block entry trace to: function=0, basic block=4 basic block entry trace to: function=0, basic block=5 -basic block entry trace to: function=0, basic block=6 diff --git a/tests/cpp/lit/covInstrument/do_while_once.wast.debug.json b/tests/cpp/lit/covInstrument/do_while_once.wast.debug.json index 5abcf4c..3183683 100644 --- a/tests/cpp/lit/covInstrument/do_while_once.wast.debug.json +++ b/tests/cpp/lit/covInstrument/do_while_once.wast.debug.json @@ -29,13 +29,9 @@ [0, 8, 16] ], [[0, 8, 20]], - [ - [0, 4, 2], - [0, 9, 4] - ], + [[0, 9, 4]], [[0, 10, 11]], [[0, 4, 2]], - [[0, 4, 2]], [ [0, 11, 9], [0, 11, 17] diff --git a/tests/cpp/lit/covInstrument/do_while_once.wast.run.log b/tests/cpp/lit/covInstrument/do_while_once.wast.run.log index 25482e7..eff7a6b 100644 --- a/tests/cpp/lit/covInstrument/do_while_once.wast.run.log +++ b/tests/cpp/lit/covInstrument/do_while_once.wast.run.log @@ -6,4 +6,3 @@ basic block entry trace to: function=0, basic block=4 basic block entry trace to: function=0, basic block=6 basic block entry trace to: function=0, basic block=7 basic block entry trace to: function=0, basic block=8 -basic block entry trace to: function=0, basic block=9 diff --git a/tests/cpp/lit/covInstrument/for_loop_break.wast.debug.json b/tests/cpp/lit/covInstrument/for_loop_break.wast.debug.json index a7956dd..b52c523 100644 --- a/tests/cpp/lit/covInstrument/for_loop_break.wast.debug.json +++ b/tests/cpp/lit/covInstrument/for_loop_break.wast.debug.json @@ -30,7 +30,6 @@ [0, 6, 13] ], [[0, 4, 19]], - [[0, 4, 19]], [[0, 8, 9]] ] } diff --git a/tests/cpp/lit/covInstrument/for_loop_break.wast.run.log b/tests/cpp/lit/covInstrument/for_loop_break.wast.run.log index 1868300..7334fe6 100644 --- a/tests/cpp/lit/covInstrument/for_loop_break.wast.run.log +++ b/tests/cpp/lit/covInstrument/for_loop_break.wast.run.log @@ -22,4 +22,3 @@ basic block entry trace to: function=0, basic block=1 basic block entry trace to: function=0, basic block=2 basic block entry trace to: function=0, basic block=3 basic block entry trace to: function=0, basic block=6 -basic block entry trace to: function=0, basic block=7 diff --git a/tests/cpp/lit/covInstrument/for_loop_continue.wast.debug.json b/tests/cpp/lit/covInstrument/for_loop_continue.wast.debug.json index 3cc31e6..5663d9d 100644 --- a/tests/cpp/lit/covInstrument/for_loop_continue.wast.debug.json +++ b/tests/cpp/lit/covInstrument/for_loop_continue.wast.debug.json @@ -26,7 +26,6 @@ ], [[0, 5, 24]], [ - [0, 4, 30], [0, 6, 4], [0, 6, 13] ], diff --git a/tests/cpp/lit/covInstrument/switch_case_fallthrough.wast.debug.json b/tests/cpp/lit/covInstrument/switch_case_fallthrough.wast.debug.json index 4ff1773..e629b32 100644 --- a/tests/cpp/lit/covInstrument/switch_case_fallthrough.wast.debug.json +++ b/tests/cpp/lit/covInstrument/switch_case_fallthrough.wast.debug.json @@ -32,7 +32,7 @@ [0, 12, 15], [0, 13, 6] ], - [[0, 10, 2]], + [], [ [0, 17, 6], [0, 17, 15], diff --git a/tests/cpp/lit/covInstrument/while.wast.debug.json b/tests/cpp/lit/covInstrument/while.wast.debug.json index f57c598..fc7a781 100644 --- a/tests/cpp/lit/covInstrument/while.wast.debug.json +++ b/tests/cpp/lit/covInstrument/while.wast.debug.json @@ -23,10 +23,7 @@ [0, 6, 13] ], [[0, 4, 2]], - [ - [0, 4, 2], - [0, 8, 9] - ] + [[0, 8, 9]] ] } } diff --git a/tests/cpp/lit/covInstrument/while_break.wast.debug.json b/tests/cpp/lit/covInstrument/while_break.wast.debug.json index be4d6e2..313e31d 100644 --- a/tests/cpp/lit/covInstrument/while_break.wast.debug.json +++ b/tests/cpp/lit/covInstrument/while_break.wast.debug.json @@ -30,7 +30,6 @@ [0, 7, 13] ], [[0, 4, 2]], - [[0, 4, 2]], [[0, 9, 9]] ] } diff --git a/tests/cpp/lit/covInstrument/while_break.wast.run.log b/tests/cpp/lit/covInstrument/while_break.wast.run.log index 8deec4e..a647e10 100644 --- a/tests/cpp/lit/covInstrument/while_break.wast.run.log +++ b/tests/cpp/lit/covInstrument/while_break.wast.run.log @@ -16,4 +16,3 @@ basic block entry trace to: function=0, basic block=1 basic block entry trace to: function=0, basic block=2 basic block entry trace to: function=0, basic block=3 basic block entry trace to: function=0, basic block=6 -basic block entry trace to: function=0, basic block=7 diff --git a/tests/cpp/lit/covInstrument/while_continue.wast.debug.json b/tests/cpp/lit/covInstrument/while_continue.wast.debug.json index 3d2032a..cfd0bff 100644 --- a/tests/cpp/lit/covInstrument/while_continue.wast.debug.json +++ b/tests/cpp/lit/covInstrument/while_continue.wast.debug.json @@ -30,10 +30,7 @@ [0, 7, 13] ], [[0, 4, 2]], - [ - [0, 4, 2], - [0, 9, 9] - ] + [[0, 9, 9]] ] } } diff --git a/tests/e2e/assertFailed/stdout.txt b/tests/e2e/assertFailed/stdout.txt index 07b3671..753547b 100644 --- a/tests/e2e/assertFailed/stdout.txt +++ b/tests/e2e/assertFailed/stdout.txt @@ -11,11 +11,11 @@ Error Message: This test will fail due to an assertion error Reason: unreachable at start:tests/e2e/assertFailed/assertOnTest.test~anonymous|0 (tests/e2e/assertFailed/assertOnTest.test.ts:6:2) - at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:637) + at executeTestFunction (tests/e2e/assertFailed/tmp/assertOnTest.test.instrumented.wasm:1:675) tests/e2e/assertFailed/tmp/assertOnInit.test - init: Test Crashed! Reason: unreachable at start:tests/e2e/assertFailed/assertOnInit.test (tests/e2e/assertFailed/assertOnInit.test.ts:1:0) - at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:206) + at ~start (tests/e2e/assertFailed/tmp/assertOnInit.test.instrumented.wasm:1:244) diff --git a/transform/listFunctions.mts b/transform/listFunctions.mts index b15de28..40a7d69 100644 --- a/transform/listFunctions.mts +++ b/transform/listFunctions.mts @@ -494,15 +494,11 @@ class SourceFunctionTransform extends Transform { startLine = LineRange.source.lineAt(LineRange.start); endLine = LineRange.source.lineAt(LineRange.end); } - } else { - const LineRange = node.range; - startLine = LineRange.source.lineAt(LineRange.start); - endLine = LineRange.source.lineAt(LineRange.end); - } - this.functionInfos.push({ - name: this.#elementsByDeclaration.get(node)?.internalName ?? node.name.text, - range: [startLine, endLine], - }); + this.functionInfos.push({ + name: this.#elementsByDeclaration.get(node)?.internalName ?? node.name.text, + range: [startLine, endLine], + }); + } } if (node.body) { this.visitNode(node.body);