8215729: Enhance makefiles to allow collecting code coverage with JCov
Reviewed-by: erikj
--- a/make/Main.gmk Mon Jan 14 23:05:26 2019 +0100
+++ b/make/Main.gmk Mon Jan 14 08:22:49 2019 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -484,18 +484,27 @@
exploded-test-$1:
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk run-test \
TEST="$1" JDK_IMAGE_DIR=$(JDK_OUTPUTDIR))
-
endef
# ALL_NAMED_TESTS is defined in FindTests.gmk
$(foreach t, $(ALL_NAMED_TESTS), $(eval $(call DeclareRunTestRecipe,$t)))
ALL_TEST_TARGETS := $(addprefix test-, $(ALL_NAMED_TESTS))
+define DeclareRunJCovTestRecipe
+ jcov-test-$1:
+ +($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
+ TEST="$1" TEST_OPTS_JCOV=true)
+endef
+
+# jcov-test only makes sense for some of the tests
+$(foreach t, $(JCOV_NAMED_TESTS), $(eval $(call DeclareRunJCovTestRecipe,$t)))
+ALL_JCOV_TEST_TARGETS := $(addprefix jcov-test-, $(JCOV_NAMED_TESTS))
+
# We only support the "exploded-test-gtest" shortcut
ALL_EXPLODED_TESTS := gtest
ALL_EXPLODED_TEST_TARGETS := $(addprefix exploded-test-, $(ALL_EXPLODED_TESTS))
-ALL_TARGETS += $(ALL_TEST_TARGETS) $(ALL_EXPLODED_TEST_TARGETS)
+ALL_TARGETS += $(ALL_TEST_TARGETS) $(ALL_EXPLODED_TEST_TARGETS) $(ALL_JCOV_TEST_TARGETS)
################################################################################
# Build tests and microbenchmarks
@@ -568,7 +577,11 @@
+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk run-test \
TEST="$(TEST)" JDK_IMAGE_DIR=$(JDK_OUTPUTDIR))
-ALL_TARGETS += test exploded-test
+jcov-test:
+ +($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk \
+ TEST="$(TEST)" TEST_OPTS_JCOV=true)
+
+ALL_TARGETS += test exploded-test jcov-test
################################################################################
# Bundles
@@ -869,6 +882,8 @@
exploded-test: exploded-image test-image
+ jcov-test: jcov-image test-image
+
test-make: clean-test-make compile-commands
test-make-compile-commands: compile-commands
@@ -876,6 +891,7 @@
# Declare dependency for all generated test targets
$(foreach t, $(filter-out test-make%, $(ALL_TEST_TARGETS)), $(eval $t: jdk-image test-image))
$(foreach t, $(ALL_EXPLODED_TEST_TARGETS), $(eval $t: exploded-image test-image))
+ $(ALL_JCOV_TEST_TARGETS): jcov-image test-image
create-buildjdk-copy: jdk.jlink-java java.base-gendata \
$(addsuffix -java, $(INTERIM_IMAGE_MODULES))
--- a/make/RunTests.gmk Mon Jan 14 23:05:26 2019 +0100
+++ b/make/RunTests.gmk Mon Jan 14 08:22:49 2019 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -45,7 +45,7 @@
endif
$(eval $(call ParseKeywordVariable, TEST_OPTS, \
- SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR AOT_MODULES, \
+ SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR AOT_MODULES JCOV, \
STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS, \
))
@@ -595,9 +595,7 @@
$$(eval $1_TOTAL := 1) \
)
- $1: run-test-$1 parse-test-$1
-
- TARGETS += $1
+ TARGETS += run-test-$1 parse-test-$1
endef
################################################################################
@@ -702,9 +700,7 @@
$$(eval $1_TOTAL := 1) \
)
- $1: run-test-$1 parse-test-$1
-
- TARGETS += $1
+ TARGETS += run-test-$1 parse-test-$1
endef
################################################################################
@@ -879,6 +875,7 @@
$$(call LogWarn, Running test '$$($1_TEST)')
$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
+ $$(JCOV_ENVIRONMENT) \
$$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
-Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
$$($1_JTREG_BASIC_OPTIONS) \
@@ -888,6 +885,7 @@
-workDir:$$($1_TEST_SUPPORT_DIR) \
$$(JTREG_OPTIONS) \
$$(JTREG_FAILURE_HANDLER_OPTIONS) \
+ $$(JTREG_JCOV_OPTIONS) \
$$($1_TEST_NAME) \
&& $$(ECHO) $$$$? > $$($1_EXITCODE) \
|| $$(ECHO) $$$$? > $$($1_EXITCODE) \
@@ -921,9 +919,7 @@
$$(eval $1_TOTAL := 1) \
)
- $1: run-test-$1 parse-test-$1
-
- TARGETS += $1
+ TARGETS += run-test-$1 parse-test-$1
endef
################################################################################
@@ -985,9 +981,7 @@
$$(eval $1_ERROR := 0)
$$(eval $1_TOTAL := 0)
- $1: run-test-$1 parse-test-$1
-
- TARGETS += $1
+ TARGETS += run-test-$1 parse-test-$1
endef
################################################################################
@@ -1099,6 +1093,55 @@
$(ECHO)
################################################################################
+# Setup JCov
+################################################################################
+
+ifeq ($(TEST_OPTS_JCOV), true)
+
+ JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
+ JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log
+ JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml
+ JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report
+ JCOV_MEM_OPTIONS := -Xms64m -Xmx4g
+
+ ifneq ($(JCOV_IMAGE_DIR), )
+ JDK_IMAGE_DIR := $(JCOV_IMAGE_DIR)
+ endif
+
+ JCOV_ENVIRONMENT := JAVA_TOOL_OPTIONS="$(JCOV_MEM_OPTIONS)" \
+ _JAVA_OPTIONS="$(JCOV_MEM_OPTIONS)"
+ JTREG_JCOV_OPTIONS := -e:JAVA_TOOL_OPTIONS='$(JCOV_MEM_OPTIONS)' \
+ -e:_JAVA_OPTIONS='$(JCOV_MEM_OPTIONS)'
+
+ jcov-do-start-grabber:
+ $(call MakeDir, $(JCOV_OUTPUT_DIR))
+ if $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -status 1>/dev/null 2>&1 ; then \
+ $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600 ; \
+ fi
+ $(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar Grabber -v -t \
+ $(JCOV_IMAGE_DIR)/template.xml -o $(JCOV_RESULT_FILE) \
+ 1>$(JCOV_GRABBER_LOG) 2>&1 &
+
+ jcov-start-grabber: jcov-do-start-grabber
+ $(call LogWarn, Starting JCov Grabber...)
+ $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -t 600 -wait
+
+ jcov-stop-grabber:
+ $(call LogWarn, Stopping JCov Grabber...)
+ $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
+
+ jcov-gen-report: run-test jcov-stop-grabber
+ $(call LogWarn, Generating JCov report ...)
+ $(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
+ `$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
+ -o $(JCOV_REPORT) $(JCOV_RESULT_FILE)
+
+ $(TARGETS): jcov-start-grabber
+ all: jcov-gen-report
+
+endif
+
+################################################################################
all: run-test
--- a/make/common/FindTests.gmk Mon Jan 14 23:05:26 2019 +0100
+++ b/make/common/FindTests.gmk Mon Jan 14 08:22:49 2019 -0800
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -68,6 +68,7 @@
# Add Jtreg test groups to list of named tests (test groups, test list, etc)
# ALL_NAMED_TESTS might have been set by a custom extension
ALL_NAMED_TESTS += $(JTREG_TEST_GROUPS)
+JCOV_NAMED_TESTS += $(JTREG_TEST_GROUPS)
# Add Gtest
ALL_NAMED_TESTS += gtest