Skip to content
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

Patch: update instrumentation order to fix coverage #711

Merged
merged 3 commits into from
Apr 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,9 @@ class RuntimeInstrumentor(
}
return ClassInstrumentor(internalClassName, bytecode).run {
if (fullInstrumentation) {
// Hook instrumentation must be performed after data flow tracing as the injected
// bytecode would trigger the GEP callbacks for byte[]. Coverage instrumentation
// must be performed after hook instrumentation as the injected bytecode would
// trigger the GEP callbacks for ByteBuffer.
traceDataFlow(instrumentationTypes)
hooks(includedHooks + customHooks, classWithHooksEnabledField)
// Coverage instrumentation must be performed before any other code updates
// or there will be additional coverage points injected if any calls are inserted
// and JaCoCo will produce a broken coverage report.
coverageIdSynchronizer.withIdForClass(internalClassName) { firstId ->
coverage(firstId).also { actualNumEdgeIds ->
CoverageRecorder.recordInstrumentedClass(
Expand All @@ -230,6 +227,10 @@ class RuntimeInstrumentor(
)
}
}
// Hook instrumentation must be performed after data flow tracing as the injected
// bytecode would trigger the GEP callbacks for byte[].
traceDataFlow(instrumentationTypes)
hooks(includedHooks + customHooks, classWithHooksEnabledField)
} else {
hooks(customHooks, classWithHooksEnabledField)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/test/java/com/example/CoverageFuzzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private static void assertCoverageDump() throws IOException {
assertEquals(7, countHits(coverageFuzzerCoverage.getProbes()));

assertEquals("com/example/CoverageFuzzer$ClassToCover", classToCoverCoverage.getName());
assertEquals(11, countHits(classToCoverCoverage.getProbes()));
assertEquals(10, countHits(classToCoverCoverage.getProbes()));
}

private static int countHits(boolean[] probes) {
Expand Down