Add support for running microbenchmarks using run-test. JEP-230-microbenchmarks-branch
authorihse
Wed, 03 Oct 2018 15:54:35 +0200
branchJEP-230-microbenchmarks-branch
changeset 56920 e0750e33f818
parent 56919 fe0fad5aebf5
child 56921 69544f53b8bf
Add support for running microbenchmarks using run-test.
make/Help.gmk
make/InitSupport.gmk
make/RunTests.gmk
make/common/FindTests.gmk
--- a/make/Help.gmk	Wed Oct 03 12:51:14 2018 +0200
+++ b/make/Help.gmk	Wed Oct 03 15:54:35 2018 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2018, 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
@@ -103,6 +103,7 @@
 	$(info $(_)                        # make test TEST="jdk_lang jdk_net")
 	$(info $(_) JTREG="OPT1=x;OPT2=y"  # Control the JTREG test harness for run-test)
 	$(info $(_) GTEST="OPT1=x;OPT2=y"  # Control the GTEST test harness for run-test)
+	$(info $(_) MICRO="OPT1=x;OPT2=y"  # Control the MICRO test harness for run-test)
 	$(info )
 	$(if $(all_confs), $(info Available configurations in $(build_dir):) $(foreach var,$(all_confs),$(info * $(var))),\
 	    $(info No configurations were found in $(build_dir).) $(info Run 'bash configure' to create a configuration.))
--- a/make/InitSupport.gmk	Wed Oct 03 12:51:14 2018 +0200
+++ b/make/InitSupport.gmk	Wed Oct 03 15:54:35 2018 +0200
@@ -50,7 +50,7 @@
 
   # Make control variables, handled by Init.gmk
   INIT_CONTROL_VARIABLES += LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
-      COMPARE_BUILD JTREG GTEST TEST_OPTS TEST_VM_OPTS
+      COMPARE_BUILD JTREG GTEST MICRO TEST_OPTS TEST_VM_OPTS
 
   # All known make control variables
   MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
--- a/make/RunTests.gmk	Wed Oct 03 12:51:14 2018 +0200
+++ b/make/RunTests.gmk	Wed Oct 03 15:54:35 2018 +0200
@@ -107,12 +107,15 @@
 # Parse control variables
 ################################################################################
 
+### Jtreg
+
 ifneq ($(TEST_OPTS), )
   # Inform the user
   $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
 
   $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
   $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
+  $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
 
   $(eval $(call SetTestOpt,JOBS,JTREG))
   $(eval $(call SetTestOpt,TIMEOUT,JTREG))
@@ -128,6 +131,8 @@
   $(info Running tests using JTREG control variable '$(JTREG)')
 endif
 
+### Gtest
+
 $(eval $(call ParseKeywordVariable, GTEST, \
     KEYWORDS := REPEAT, \
     STRING_KEYWORDS := OPTIONS VM_OPTIONS, \
@@ -138,6 +143,18 @@
   $(info Running tests using GTEST control variable '$(GTEST)')
 endif
 
+### Microbenchmarks
+
+$(eval $(call ParseKeywordVariable, MICRO, \
+    KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
+    STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS TEST_JDK BENCHMARKS_JAR, \
+))
+
+ifneq ($(MICRO), )
+  # Inform the user
+  $(info Running tests using MICRO control variable '$(MICRO)')
+endif
+
 
 ################################################################################
 # Component-specific Jtreg settings
@@ -203,6 +220,24 @@
   )
 endef
 
+# Helper function to determine if a test specification is a microbenchmark test
+#
+# It is a microbenchmark test if it is either "micro", or "micro:" followed by an optional
+# test filter string.
+define ParseMicroTestSelection
+  $(if $(filter micro%, $1), \
+    $(if $(filter micro, $1), \
+      micro:all \
+    , \
+      $(if $(filter micro:, $1), \
+        micro:all \
+      , \
+        $1 \
+      ) \
+    ) \
+  )
+endef
+
 # Helper function that removes the TOPDIR part
 CleanupJtregPath = \
   $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
@@ -300,6 +335,9 @@
     $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
   ) \
   $(if $(strip $(PARSED_TESTS)), , \
+    $(eval PARSED_TESTS += $(call ParseMicroTestSelection, $(test))) \
+  ) \
+  $(if $(strip $(PARSED_TESTS)), , \
     $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
   ) \
   $(if $(strip $(PARSED_TESTS)), , \
@@ -414,6 +452,114 @@
 
 ################################################################################
 
+### Rules for Microbenchmarks
+
+# Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
+# 1) Specified by user on command line
+# 2) Generic default
+#
+# Note: No spaces are allowed around the arguments.
+# Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
+# Arg $2 Base variable, e.g. MICRO_TEST_JDK
+# Arg $3 The default value (optional)
+define SetMicroValue
+  ifneq ($$($2), )
+    $1_$2 := $$($2)
+  else
+    ifneq ($3, )
+      $1_$2 := $3
+    endif
+  endif
+endef
+
+SetupRunMicroTest = $(NamedParamsMacroTemplate)
+define SetupRunMicroTestBody
+  $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
+  $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
+  $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
+
+  $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
+
+  $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/microbenchmarks.jar))
+  $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_IMAGE_DIR)))
+  $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
+
+  # Current tests needs to open java.io
+  $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
+
+  # Save output as CSV file
+  $1_MICRO_BASIC_OPTIONS += -rf csv -rff $$($1_TEST_RESULTS_DIR)/jmh-result.csv
+
+  # Always specify test JVM
+  $1_MICRO_BASIC_OPTIONS += -jvm $$($1_MICRO_TEST_JDK)/bin/java
+
+  ifneq ($$(MICRO_VM_OPTIONS), )
+    $1_MICRO_VM_OPTIONS := -jvmArgs $$(MICRO_VM_OPTIONS)
+  endif
+
+  ifneq ($$(MICRO_ITER), )
+    $1_MICRO_ITER := -i $$(MICRO_ITER)
+  endif
+  ifneq ($$(MICRO_FORK), )
+    $1_MICRO_FORK := -f $$(MICRO_FORK)
+  endif
+  ifneq ($$(MICRO_TIME), )
+    $1_MICRO_TIME := -r $$(MICRO_TIME)
+  endif
+  ifneq ($$(MICRO_WARMUP_ITER), )
+    $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
+  endif
+  ifneq ($$(MICRO_WARMUP_TIME), )
+    $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
+  endif
+
+  run-test-$1:
+	$$(call LogWarn)
+	$$(call LogWarn, Running test '$$($1_TEST)')
+	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
+	$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, \
+	    $$(JAVA) $$($1_MICRO_JAVA_OPTIONS) -jar $$($1_MICRO_BENCHMARKS_JAR) \
+	        $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
+	        $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
+	        $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS)  \
+	        $$($1_TEST_NAME) \
+	        > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
+	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
+	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \
+	)
+
+  $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
+
+  parse-test-$1: run-test-$1
+	$$(call LogWarn, Finished running test '$$($1_TEST)')
+	$$(call LogWarn, Test report is stored in $$(strip \
+	    $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
+	$$(if $$(wildcard $$($1_EXITCODE)), \
+	  $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
+	  $$(if $$(filter 0, $$($1_EXIT_CODE)), \
+	    $$(eval $1_PASSED := 1) \
+	    $$(eval $1_ERROR := 0) \
+	  , \
+	    $$(eval $1_PASSED := 0) \
+	    $$(eval $1_ERROR := 1) \
+	  ) \
+	  $$(eval $1_FAILED := 0) \
+	  $$(eval $1_TOTAL := $$(shell \
+	      $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
+	, \
+	  $$(eval $1_PASSED := 0) \
+	  $$(eval $1_FAILED := 0) \
+	  $$(eval $1_ERROR := 1) \
+	  $$(eval $1_TOTAL := 1) \
+	)
+
+  $1: run-test-$1 parse-test-$1
+
+  TARGETS += $1
+endef
+
+################################################################################
+
 ### Rules for Jtreg
 
 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
@@ -668,6 +814,9 @@
 UseGtestTestHandler = \
   $(if $(filter gtest:%, $1), true)
 
+UseMicroTestHandler = \
+  $(if $(filter micro:%, $1), true)
+
 UseJtregTestHandler = \
   $(if $(filter jtreg:%, $1), true)
 
@@ -689,6 +838,11 @@
         TEST := $(test), \
     )) \
   ) \
+  $(if $(call UseMicroTestHandler, $(test)), \
+    $(eval $(call SetupRunMicroTest, $(TEST_ID), \
+        TEST := $(test), \
+    )) \
+  ) \
   $(if $(call UseJtregTestHandler, $(test)), \
     $(eval $(call SetupRunJtregTest, $(TEST_ID), \
         TEST := $(test), \
--- a/make/common/FindTests.gmk	Wed Oct 03 12:51:14 2018 +0200
+++ b/make/common/FindTests.gmk	Wed Oct 03 15:54:35 2018 +0200
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2018, 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
@@ -72,6 +72,9 @@
 # Add Gtest
 ALL_NAMED_TESTS += gtest
 
+# Add microbenchmarks
+ALL_NAMED_TESTS += micro
+
 ################################################################################
 
 endif # _FIND_TESTS_GMK