Skip to content

feat:code coverage calculation treat switch case statements correctly #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion instrumentation/BasicBlockWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void BasicBlockWalker::basicBlockWalk() noexcept {
}

void BasicBlockWalker::visitExpression(wasm::Expression *curr) noexcept {
if (currBasicBlock == nullptr) {
if (currBasicBlock == nullptr || curr->is<wasm::Block>()) {
return;
}
// push information
Expand All @@ -33,6 +33,14 @@ void BasicBlockWalker::visitExpression(wasm::Expression *curr) noexcept {
}
}

void BasicBlockWalker::doEndBlock(BasicBlockWalker *self, wasm::Expression **currp) {
wasm::CFGWalker<BasicBlockWalker, wasm::UnifiedExpressionVisitor<BasicBlockWalker>,
BasicBlockInfo>::doEndBlock(self, currp);
if (self->currBasicBlock != nullptr) {
self->currBasicBlock->contents.exprs.push_back(*currp);
}
}

static bool
isBasicBlockContainUnreachable(BasicBlockWalker::BasicBlock &block,
std::set<BasicBlockWalker::BasicBlock *> unreachableBlocks) {
Expand Down
2 changes: 2 additions & 0 deletions instrumentation/BasicBlockWalker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
[0, 7, 18]
],
[[0, 4, 2]],
[[0, 4, 2]],
[[0, 8, 9]]
]
}
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/lit/covInstrument/do_while_break.wast.run.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"debugInfos": {
"main": {
"branchInfo": [
[1, 2],
[1, 3],
[4, 5],
[4, 1]
[1, 2],
[3, 4],
[3, 1]
],
"index": 0,
"lineInfo": [
Expand All @@ -21,7 +21,6 @@
[0, 6, 16]
],
[[0, 6, 19]],
[[0, 4, 2]],
[
[0, 7, 10],
[0, 7, 18]
Expand Down
2 changes: 0 additions & 2 deletions tests/cpp/lit/covInstrument/do_while_continue.wast.run.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 1 addition & 5 deletions tests/cpp/lit/covInstrument/do_while_once.wast.debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/lit/covInstrument/do_while_once.wast.run.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
[0, 6, 13]
],
[[0, 4, 19]],
[[0, 4, 19]],
[[0, 8, 9]]
]
}
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/lit/covInstrument/for_loop_break.wast.run.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
],
[[0, 5, 24]],
[
[0, 4, 30],
[0, 6, 4],
[0, 6, 13]
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[0, 12, 15],
[0, 13, 6]
],
[[0, 10, 2]],
[],
[
[0, 17, 6],
[0, 17, 15],
Expand Down
5 changes: 1 addition & 4 deletions tests/cpp/lit/covInstrument/while.wast.debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
[0, 6, 13]
],
[[0, 4, 2]],
[
[0, 4, 2],
[0, 8, 9]
]
[[0, 8, 9]]
]
}
}
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/lit/covInstrument/while_break.wast.debug.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
[0, 7, 13]
],
[[0, 4, 2]],
[[0, 4, 2]],
[[0, 9, 9]]
]
}
Expand Down
1 change: 0 additions & 1 deletion tests/cpp/lit/covInstrument/while_break.wast.run.log
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
[0, 7, 13]
],
[[0, 4, 2]],
[
[0, 4, 2],
[0, 9, 9]
]
[[0, 9, 9]]
]
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/assertFailed/stdout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

14 changes: 5 additions & 9 deletions transform/listFunctions.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down