Skip to content

Commit

Permalink
Patch: update instrumentation order to fix coverage (#711)
Browse files Browse the repository at this point in the history
Co-authored-by: Kostiantyn Melnik <[email protected]>
Co-authored-by: Fabian Meumertzheim <[email protected]>
  • Loading branch information
3 people committed Apr 26, 2023
1 parent d68158d commit c2e8901
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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

0 comments on commit c2e8901

Please sign in to comment.