8282493: Add --with-jcov-modules convenience option

Reviewed-by: erikj
This commit is contained in:
Magnus Ihse Bursie
2025-05-07 13:28:46 +00:00
parent a72f7506bf
commit ca5e0b1848
6 changed files with 46 additions and 8 deletions

View File

@@ -411,6 +411,13 @@ instrumentation
special target <code>jcov-test</code> instead of <code>test</code>, e.g. 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 <code>make jcov-test TEST=jdk_lang</code>. This will make sure the JCov
image is built, and that JCov reporting is enabled.</p> image is built, and that JCov reporting is enabled.</p>
<p>To include JCov coverage for just a subset of all modules, you can
use the <code>--with-jcov-modules</code> arguments to
<code>configure</code>, e.g.
<code>--with-jcov-modules=jdk.compiler,java.desktop</code>.</p>
<p>For more fine-grained control, you can pass arbitrary filters to JCov
using <code>--with-jcov-filters</code>, and you can specify a specific
JDK to instrument using <code>--with-jcov-input-jdk</code>.</p>
<p>The JCov report is stored in <p>The JCov report is stored in
<code>build/$BUILD/test-results/jcov-output/report</code>.</p> <code>build/$BUILD/test-results/jcov-output/report</code>.</p>
<p>Please note that running with JCov reporting can be very memory <p>Please note that running with JCov reporting can be very memory

View File

@@ -345,6 +345,14 @@ The simplest way to run tests with JCov coverage report is to use the special
target `jcov-test` instead of `test`, e.g. `make jcov-test TEST=jdk_lang`. This target `jcov-test` instead of `test`, e.g. `make jcov-test TEST=jdk_lang`. This
will make sure the JCov image is built, and that JCov reporting is enabled. will make sure the JCov image is built, and that JCov reporting is enabled.
To include JCov coverage for just a subset of all modules, you can use the
`--with-jcov-modules` arguments to `configure`, e.g.
`--with-jcov-modules=jdk.compiler,java.desktop`.
For more fine-grained control, you can pass arbitrary filters to JCov using
`--with-jcov-filters`, and you can specify a specific JDK to instrument
using `--with-jcov-input-jdk`.
The JCov report is stored in `build/$BUILD/test-results/jcov-output/report`. The JCov report is stored in `build/$BUILD/test-results/jcov-output/report`.
Please note that running with JCov reporting can be very memory intensive. Please note that running with JCov reporting can be very memory intensive.

View File

@@ -34,21 +34,28 @@ else
JCOV_INPUT_IMAGE_DIR := $(JDK_IMAGE_DIR) JCOV_INPUT_IMAGE_DIR := $(JDK_IMAGE_DIR)
endif endif
JCOV_SUPPORT_DIR := $(SUPPORT_OUTPUTDIR)/jcov
#moving instrumented jdk image in and out of jcov_temp because of CODETOOLS-7902299 #moving instrumented jdk image in and out of jcov_temp because of CODETOOLS-7902299
JCOV_TEMP := $(SUPPORT_OUTPUTDIR)/jcov_temp JCOV_TEMP := $(JCOV_SUPPORT_DIR)/temp
ifneq ($(JCOV_MODULES), )
JCOV_MODULES_FILTER := $(foreach m, $(JCOV_MODULES), -include_module $m)
endif
$(JCOV_IMAGE_DIR)/release: $(JCOV_INPUT_IMAGE_DIR)/release $(JCOV_IMAGE_DIR)/release: $(JCOV_INPUT_IMAGE_DIR)/release
$(call LogWarn, Creating instrumented jdk image with JCov) $(call LogWarn, Creating instrumented jdk image with JCov)
$(call MakeDir, $(JCOV_TEMP) $(IMAGES_OUTPUTDIR)) $(call MakeDir, $(JCOV_TEMP) $(IMAGES_OUTPUTDIR))
$(RM) -r $(JCOV_IMAGE_DIR) $(JCOV_TEMP)/* $(RM) -r $(JCOV_IMAGE_DIR) $(JCOV_TEMP)/*
$(CP) -r $(JCOV_INPUT_IMAGE_DIR) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(CP) -r $(JCOV_INPUT_IMAGE_DIR) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)
$(call ExecuteWithLog, $(JCOV_SUPPORT_DIR)/run-jcov, \
$(JAVA) -Xmx3g -jar $(JCOV_HOME)/lib/jcov.jar JREInstr \ $(JAVA) -Xmx3g -jar $(JCOV_HOME)/lib/jcov.jar JREInstr \
-t $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)/template.xml \ -t $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR)/template.xml \
-rt $(JCOV_HOME)/lib/jcov_network_saver.jar \ -rt $(JCOV_HOME)/lib/jcov_network_saver.jar \
-exclude 'java.lang.Object' \ -exclude 'java.lang.Object' \
-exclude jdk.test.Main -exclude '**\$Proxy*' \ -exclude jdk.test.Main -exclude '**\$Proxy*' \
$(JCOV_FILTERS) \ $(JCOV_MODULES_FILTER) $(JCOV_FILTERS) \
$(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR))
$(MV) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(JCOV_IMAGE_DIR) $(MV) $(JCOV_TEMP)/$(JCOV_IMAGE_SUBDIR) $(JCOV_IMAGE_DIR)
$(RMDIR) $(JCOV_TEMP) $(RMDIR) $(JCOV_TEMP)

View File

@@ -115,6 +115,7 @@ JTREG_COV_OPTIONS :=
ifeq ($(TEST_OPTS_JCOV), true) ifeq ($(TEST_OPTS_JCOV), true)
JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
JCOV_SUPPORT_DIR := $(TEST_SUPPORT_DIR)/jcov-support
JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log
JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml
JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report
@@ -1363,6 +1364,10 @@ ifeq ($(TEST_OPTS_JCOV), true)
$(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600 $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
JCOV_REPORT_TITLE := JDK code coverage report<br/> JCOV_REPORT_TITLE := JDK code coverage report<br/>
ifneq ($(JCOV_MODULES), )
JCOV_MODULES_FILTER := $(foreach m, $(JCOV_MODULES), -include_module $m)
JCOV_REPORT_TITLE += Included modules: $(JCOV_MODULES)<br>
endif
ifneq ($(JCOV_FILTERS), ) ifneq ($(JCOV_FILTERS), )
JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)<br> JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)<br>
endif endif
@@ -1370,11 +1375,12 @@ ifeq ($(TEST_OPTS_JCOV), true)
jcov-gen-report: jcov-stop-grabber jcov-gen-report: jcov-stop-grabber
$(call LogWarn, Generating JCov report ...) $(call LogWarn, Generating JCov report ...)
$(call ExecuteWithLog, $(JCOV_SUPPORT_DIR)/run-jcov-repgen, \
$(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \ $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
`$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \ `$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
$(JCOV_FILTERS) \ $(JCOV_MODULES_FILTER) $(JCOV_FILTERS) \
-mainReportTitle "$(JCOV_REPORT_TITLE)" \ -mainReportTitle "$(JCOV_REPORT_TITLE)" \
-o $(JCOV_REPORT) $(JCOV_RESULT_FILE) -o $(JCOV_REPORT) $(JCOV_RESULT_FILE))
TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \ TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
jcov-gen-report jcov-gen-report

View File

@@ -405,10 +405,19 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_CODE_COVERAGE],
JCOV_FILTERS="$with_jcov_filters" JCOV_FILTERS="$with_jcov_filters"
fi fi
fi fi
UTIL_ARG_WITH(NAME: jcov-modules, TYPE: string,
DEFAULT: [], RESULT: JCOV_MODULES_COMMMA_SEPARATED,
DESC: [which modules to include in jcov (comma-separated)],
OPTIONAL: true)
# Replace "," with " ".
JCOV_MODULES=${JCOV_MODULES_COMMMA_SEPARATED//,/ }
AC_SUBST(JCOV_ENABLED) AC_SUBST(JCOV_ENABLED)
AC_SUBST(JCOV_HOME) AC_SUBST(JCOV_HOME)
AC_SUBST(JCOV_INPUT_JDK) AC_SUBST(JCOV_INPUT_JDK)
AC_SUBST(JCOV_FILTERS) AC_SUBST(JCOV_FILTERS)
AC_SUBST(JCOV_MODULES)
]) ])
################################################################################ ################################################################################

View File

@@ -1,5 +1,5 @@
# #
# Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2011, 2025, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
@@ -454,6 +454,7 @@ JCOV_ENABLED := @JCOV_ENABLED@
JCOV_HOME := @JCOV_HOME@ JCOV_HOME := @JCOV_HOME@
JCOV_INPUT_JDK := @JCOV_INPUT_JDK@ JCOV_INPUT_JDK := @JCOV_INPUT_JDK@
JCOV_FILTERS := @JCOV_FILTERS@ JCOV_FILTERS := @JCOV_FILTERS@
JCOV_MODULES := @JCOV_MODULES@
# AddressSanitizer # AddressSanitizer
ASAN_ENABLED := @ASAN_ENABLED@ ASAN_ENABLED := @ASAN_ENABLED@