Skip to content

Commit db91be2

Browse files
committedMar 5, 2020
8240241: Add support for JCov DiffCoverage to make files
Reviewed-by: erikj, ihse
1 parent d75e62e commit db91be2

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed
 

‎doc/testing.html

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ <h4 id="jcov">JCOV</h4>
127127
<p>The simplest way to run tests with JCov coverage report is to use the special target <code>jcov-test</code> instead of <code>test</code>, e.g. <code>make jcov-test TEST=jdk_lang</code>. This will make sure the JCov image is built, and that JCov reporting is enabled.</p>
128128
<p>The JCov report is stored in <code>build/$BUILD/test-results/jcov-output</code>.</p>
129129
<p>Please note that running with JCov reporting can be very memory intensive.</p>
130+
<h4 id="jcov_diff_changeset">JCOV_DIFF_CHANGESET</h4>
131+
<p>While collecting code coverage with JCov, it is also possible to find coverage for only recently changed code. JCOV_DIFF_CHANGESET specifies a source revision. A textual report will be generated showing coverage of the diff between the specified revision and the repository tip.</p>
132+
<p>The report is stored in <code>build/$BUILD/test-results/jcov-output/diff_coverage_report</code> file.</p>
130133
<h3 id="jtreg-keywords">JTReg keywords</h3>
131134
<h4 id="jobs-1">JOBS</h4>
132135
<p>The test concurrency (<code>-concurrency</code>).</p>

‎doc/testing.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,20 @@ The simplest way to run tests with JCov coverage report is to use the special
241241
target `jcov-test` instead of `test`, e.g. `make jcov-test TEST=jdk_lang`. This
242242
will make sure the JCov image is built, and that JCov reporting is enabled.
243243

244-
The JCov report is stored in `build/$BUILD/test-results/jcov-output`.
244+
The JCov report is stored in `build/$BUILD/test-results/jcov-output/report`.
245245

246246
Please note that running with JCov reporting can be very memory intensive.
247247

248+
#### JCOV_DIFF_CHANGESET
249+
250+
While collecting code coverage with JCov, it is also possible to find coverage
251+
for only recently changed code. JCOV_DIFF_CHANGESET specifies a source
252+
revision. A textual report will be generated showing coverage of the diff
253+
between the specified revision and the repository tip.
254+
255+
The report is stored in `build/$BUILD/test-results/jcov-output/diff_coverage_report`
256+
file.
257+
248258
### JTReg keywords
249259

250260
#### JOBS

‎make/RunTests.gmk

+34-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ifneq ($(TEST_VM_OPTS), )
4545
endif
4646

4747
$(eval $(call ParseKeywordVariable, TEST_OPTS, \
48-
SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR JCOV, \
48+
SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR JCOV JCOV_DIFF_CHANGESET, \
4949
STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS AOT_MODULES, \
5050
))
5151

@@ -1266,12 +1266,44 @@ ifeq ($(TEST_OPTS_JCOV), true)
12661266
TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
12671267
jcov-gen-report
12681268

1269+
ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1270+
1271+
JCOV_SOURCE_DIFF := $(JCOV_OUTPUT_DIR)/source_diff
1272+
JCOV_DIFF_COVERAGE_REPORT := $(JCOV_OUTPUT_DIR)/diff_coverage_report
1273+
1274+
ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
1275+
DIFF_COMMAND := $(HG) -R $(TOPDIR) diff -r $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1276+
else ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
1277+
DIFF_COMMAND := $(GIT) -C $(TOPDIR) diff $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1278+
else
1279+
$(info Error: Must be either hg or git source tree for diff coverage.)
1280+
$(error Neither hg nor git source tree.)
1281+
endif
1282+
1283+
jcov-gen-diffcoverage: jcov-stop-grabber
1284+
$(call LogWarn, Generating diff coverage with changeset $(TEST_OPTS_JCOV_DIFF_CHANGESET) ... )
1285+
$(DIFF_COMMAND)
1286+
$(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar \
1287+
DiffCoverage -replaceDiff "src/.*/classes/:" -all \
1288+
$(JCOV_RESULT_FILE) $(JCOV_SOURCE_DIFF) > \
1289+
$(JCOV_DIFF_COVERAGE_REPORT)
1290+
1291+
TARGETS += jcov-gen-diffcoverage
1292+
1293+
endif
1294+
12691295
# Hook this into the framework at appropriate places
12701296
pre-run-test: jcov-start-grabber
12711297

12721298
post-run-test: jcov-gen-report
12731299

1274-
jcov-gen-report: run-all-tests
1300+
ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1301+
1302+
post-run-test: jcov-gen-diffcoverage
1303+
1304+
endif
1305+
1306+
jcov-stop-grabber: run-all-tests
12751307

12761308
endif
12771309

0 commit comments

Comments
 (0)