8176084: Developer-friendly run-test facility
authorihse
Fri, 03 Mar 2017 12:57:57 +0100
changeset 44027 3a3050924db2
parent 44026 a46c32199211
child 44028 7fa83c9bad59
8176084: Developer-friendly run-test facility Reviewed-by: erikj
make/Help.gmk
make/Init.gmk
make/InitSupport.gmk
make/Main.gmk
make/RunTests.gmk
make/common/FindTests.gmk
make/common/MakeBase.gmk
test/make/TestMakeBase.gmk
--- a/make/Help.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/make/Help.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2017, 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
@@ -54,6 +54,8 @@
 	$(info $(_) make reconfigure       # Rerun configure with the same arguments as last time)
 	$(info $(_) make help              # Give some help on using make)
 	$(info $(_) make test              # Run tests, default is all tests (see TEST below))
+	$(info $(_) make run-test-<test>   # Run test, e.g. run-test-tier1)
+	$(info $(_) make run-test TEST=<t> # Run test(s) given by TEST specification)
 	$(info )
 	$(info Targets for cleaning)
 	$(info $(_) make clean             # Remove all files generated by make, but not those)
@@ -95,6 +97,8 @@
 	$(info $(_)                        # method is 'auto', 'ignore' or 'fail' (default))
 	$(info $(_) make test TEST=<test>  # Only run the given test or tests, e.g.)
 	$(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 )
 	$(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/Init.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/make/Init.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2017, 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
@@ -51,7 +51,7 @@
 
   # Targets provided by Init.gmk.
   ALL_INIT_TARGETS := print-modules print-targets print-configuration \
-      reconfigure pre-compare-build post-compare-build
+      print-tests reconfigure pre-compare-build post-compare-build
 
   # CALLED_TARGETS is the list of targets that the user provided,
   # or "default" if unspecified.
@@ -251,6 +251,11 @@
 	    $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
 	    NO_RECIPES=true print-targets )
 
+  print-tests:
+	( cd $(TOPDIR) && \
+	    $(MAKE) $(MAKE_ARGS) -j 1 -f make/Main.gmk $(USER_MAKE_VARS) \
+	    NO_RECIPES=true print-tests )
+
   print-configuration:
 	  $(ECHO) $(CONFIGURE_COMMAND_LINE)
 
@@ -310,6 +315,9 @@
 	    $(call StopGlobalTimer)
 	    $(call ReportBuildTimes)
           endif
+	  if test -f $(MAKESUPPORT_OUTPUTDIR)/exit-with-error ; then \
+	    exit 1 ; \
+	  fi
 	  $(PRINTF) "Finished building $(TARGET_DESCRIPTION)\n" $(BUILD_LOG_PIPE)
         endif
 
--- a/make/InitSupport.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/make/InitSupport.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -33,6 +33,11 @@
 _INITSUPPORT_GMK := 1
 
 ifeq ($(HAS_SPEC),)
+
+  # Include the corresponding closed file, if present.
+  # Normal hook mechanism cannot be used since we have no SPEC.
+  -include $(topdir)/closed/make/InitSupport.gmk
+
   ##############################################################################
   # Helper functions for the initial part of Init.gmk, before the spec file is
   # loaded. Most of these functions provide parsing and setting up make options
@@ -40,8 +45,8 @@
   ##############################################################################
 
   # Make control variables, handled by Init.gmk
-  INIT_CONTROL_VARIABLES := LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
-      COMPARE_BUILD
+  INIT_CONTROL_VARIABLES += LOG CONF CONF_NAME SPEC JOBS TEST_JOBS CONF_CHECK \
+      COMPARE_BUILD JTREG GTEST
 
   # All known make control variables
   MAKE_CONTROL_VARIABLES := $(INIT_CONTROL_VARIABLES) TEST JDK_FILTER
@@ -498,6 +503,7 @@
   define PrepareFailureLogs
 	$(RM) -r $(MAKESUPPORT_OUTPUTDIR)/failure-logs 2> /dev/null && \
 	$(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR)/failure-logs
+	$(RM) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error 2> /dev/null
   endef
 
   # Remove any javac server logs and port files. This
--- a/make/Main.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/make/Main.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2017, 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
@@ -43,6 +43,7 @@
 # Load the vital tools for all the makefiles.
 include $(SRC_ROOT)/make/common/MakeBase.gmk
 include $(SRC_ROOT)/make/common/Modules.gmk
+include $(SRC_ROOT)/make/common/FindTests.gmk
 
 # Declare ALL_TARGETS as an immediate variable. This variable is a list of all
 # valid top level targets. It's used to declare them all as PHONY and to
@@ -423,6 +424,22 @@
 ALL_TARGETS += $(INTERIM_JMOD_TARGETS) interim-image generate-link-opt-data
 
 ################################################################################
+# Generate test names for all JTReg test groups
+#
+
+define DeclareRunTestRecipe
+  run-test-$1:
+	+($(CD) $(SRC_ROOT)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk run-test TEST="$1")
+
+endef
+
+# ALL_NAMED_TESTS is defined in FindTests.gmk
+$(foreach t, $(ALL_NAMED_TESTS), $(eval $(call DeclareRunTestRecipe,$t)))
+ALL_TEST_TARGETS := $(addprefix run-test-, $(ALL_NAMED_TESTS))
+
+ALL_TARGETS += $(ALL_TEST_TARGETS)
+
+################################################################################
 # Build tests
 #
 
@@ -446,6 +463,9 @@
 	+($(CD) $(JDK_TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f JtregNative.gmk \
 	    test-image-jdk-jtreg-native)
 
+run-test:
+	+($(CD) $(TOPDIR)/make && $(MAKE) $(MAKE_ARGS) -f RunTests.gmk run-test TEST="$(TEST)")
+
 ifeq ($(BUILD_GTEST), true)
   test-image-hotspot-gtest:
 	+($(CD) $(HOTSPOT_TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f GtestImage.gmk)
@@ -474,7 +494,8 @@
 ALL_TARGETS += prepare-test-image build-test-hotspot-jtreg-native \
     test-image-hotspot-jtreg-native build-test-jdk-jtreg-native \
     test-image-jdk-jtreg-native build-test-lib build-test-failure-handler \
-    test-failure-handler test-image-failure-handler test-image-hotspot-gtest
+    test-failure-handler test-image-failure-handler test-image-hotspot-gtest \
+    run-test
 
 ################################################################################
 # Run tests
@@ -757,6 +778,11 @@
 
   test: jdk-image test-image
 
+  run-test: jdk-image test-image
+
+  # Declare dependency for all generated test targets
+  $(foreach t, $(ALL_TEST_TARGETS), $(eval $t: jdk-image test-image))
+
   create-buildjdk-copy: jdk.jlink-java java.base-gendata \
       $(addsuffix -java, $(INTERIM_IMAGE_MODULES))
 
@@ -1031,6 +1057,9 @@
 print-modules:
 	  @$(ECHO) $(sort $(ALL_MODULES))
 
+print-tests:
+	  @$(ECHO) $(sort $(ALL_NAMED_TESTS))
+
 create-main-targets-include:
 	  $(call LogInfo, Generating main target list)
 	  @$(ECHO) ALL_MAIN_TARGETS := $(sort $(ALL_TARGETS)) > \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/RunTests.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -0,0 +1,483 @@
+#
+# Copyright (c) 2016, 2017, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+default: all
+
+include $(SPEC)
+include MakeBase.gmk
+include FindTests.gmk
+
+# We will always run multiple tests serially
+.NOTPARALLEL:
+
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, , RunTests.gmk))
+
+TEST_RESULTS_DIR := $(BUILD_OUTPUT)/test-results
+TEST_SUPPORT_DIR := $(BUILD_OUTPUT)/test-support
+
+
+################################################################################
+# Parse control variables
+################################################################################
+
+$(eval $(call ParseKeywordVariable, JTREG, \
+    KEYWORDS := JOBS TIMEOUT TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM, \
+    STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS, \
+))
+
+ifneq ($(JTREG), )
+  # Inform the user
+  $(info Running tests using JTREG control variable '$(JTREG)')
+endif
+
+$(eval $(call ParseKeywordVariable, GTEST, \
+    KEYWORDS := REPEAT, \
+    STRING_KEYWORDS := OPTIONS, \
+))
+
+ifneq ($(GTEST), )
+  # Inform the user
+  $(info Running tests using GTEST control variable '$(GTEST)')
+endif
+
+
+################################################################################
+# Component-specific Jtreg settings
+################################################################################
+
+ifeq ($(TEST_JOBS), 0)
+  # If TEST_JOBS is not specified, hotspot fallback default is
+  # min(num_cores / 2, 12).
+  hotspot_JTREG_JOBS := $(shell $(EXPR) $(NUM_CORES) / 2)
+  ifeq ($(hotspot_JTREG_JOBS), 0)
+    hotspot_JTREG_JOBS := 1
+  else ifeq ($(shell $(EXPR) $(hotspot_JTREG_JOBS) \> 12), 1)
+    hotspot_JTREG_JOBS := 12
+  endif
+endif
+
+hotspot_JTREG_MAX_MEM := 0
+hotspot_JTREG_ASSERT := false
+hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
+jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
+
+
+################################################################################
+# Parse test selection
+#
+# The user has given a test selection in the TEST variable. We must parse it
+# and determine what that means in terms of actual calls to the test framework.
+#
+# The parse functions take as argument a test specification as given by the
+# user, and returns a fully qualified test descriptor if it was a match, or
+# nothing if not. A single test specification can result in multiple test
+# descriptors being returned. A valid test descriptor must always be accepted
+# and returned identically.
+################################################################################
+
+# Helper function to determine if a test specification is a Gtest test
+#
+# It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
+# test filter string.
+define ParseGtestTestSelection
+  $(if $(filter gtest%, $1), \
+    $(if $(filter gtest, $1), \
+      gtest:all \
+    , \
+      $(if $(filter gtest:, $1), \
+        gtest:all \
+      , \
+        $1 \
+      ) \
+    ) \
+  )
+endef
+
+# Helper function to determine if a test specification is a Jtreg test
+#
+# It is a Jtreg test if it optionally begins with jtreg:, and then is either
+# an unspecified group name (possibly prefixed by :), or a group in a
+# specified <component>/test directory, or a path to a test or test directory,
+# either absolute or relative to TOPDIR.
+define ParseJtregTestSelection
+  $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
+  $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
+    $(eval TEST_NAME := :$(TEST_NAME)) \
+  ) \
+  $(if $(findstring :, $(TEST_NAME)), \
+    $(if $(filter :%, $(TEST_NAME)), \
+      $(foreach component, $(JTREG_COMPONENTS), \
+        $(if $(filter $(patsubst :%, %, $(TEST_NAME)), \
+            $($(component)_JTREG_TEST_GROUPS)), \
+          jtreg:$(component)/test:$(patsubst :%,%,$(TEST_NAME)) \
+        ) \
+      ) \
+    , \
+      $(eval COMPONENT := $(word 1, $(subst /, $(SPACE), $(TEST_NAME)))) \
+      $(eval GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
+      $(if $(filter $(COMPONENT), $(JTREG_COMPONENTS)), \
+        $(if $(filter $(GROUP), $($(COMPONENT)_JTREG_TEST_GROUPS)), \
+          jtreg:$(TEST_NAME) \
+        ) \
+      ) \
+    ) \
+  , \
+    $(if $(filter /%, $(TEST_NAME)), \
+      $(if $(wildcard $(TEST_NAME)), \
+        jtreg:$(TEST_NAME) \
+      ) \
+    , \
+      $(if $(wildcard $(TOPDIR)/$(TEST_NAME)), \
+        jtreg:$(TEST_NAME) \
+      ) \
+    ) \
+  )
+endef
+
+ifeq ($(TEST), )
+  $(info No test selection given in TEST!)
+  $(info Please use e.g. 'run-test TEST=tier1' or 'run-test-tier1')
+  $(error Cannot continue)
+endif
+
+# Now intelligently convert the test selection given by the user in TEST
+# into a list of fully qualified test descriptors of the tests to run.
+TESTS_TO_RUN :=
+$(foreach test, $(TEST), \
+  $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
+  $(if $(strip $(PARSED_TESTS)), , \
+    $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
+  ) \
+  $(if $(strip $(PARSED_TESTS)), , \
+    $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
+  ) \
+  $(if $(strip $(PARSED_TESTS)), , \
+    $(eval UNKNOWN_TEST := $(test)) \
+  ) \
+  $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
+)
+
+ifneq ($(UNKNOWN_TEST), )
+  $(info Unknown test selection: '$(UNKNOWN_TEST)')
+  $(error Cannot continue)
+endif
+
+TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
+
+
+# Present the result of our parsing to the user
+$(info Test selection '$(TEST)', will run:)
+$(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
+
+
+################################################################################
+# Functions for setting up rules for running the selected tests
+#
+# The SetupRun*Test functions all have the same interface:
+#
+# Parameter 1 is the name of the rule. This is the test id, based on the test
+# descriptor, and this is also used as variable prefix, and the targets
+# generated are listed in a variable by that name.
+#
+# Remaining parameters are named arguments. Currently this is only:
+#   TEST -- The properly formatted fully qualified test descriptor
+#
+# After the rule named by the test id has been executed, the following
+# variables will be available:
+# testid_TOTAL - the total number of tests run
+# testid_PASSED - the number of successful tests
+# testid_FAILED - the number of failed tests
+# testid_ERROR - the number of tests was neither successful or failed
+#
+################################################################################
+
+### Rules for Gtest
+
+SetupRunGtestTest = $(NamedParamsMacroTemplate)
+define SetupRunGtestTestBody
+  $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
+  $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
+
+  $1_TEST_NAME := $$(strip $$(patsubst gtest:%, %, $$($1_TEST)))
+  ifneq ($$($1_TEST_NAME), all)
+    $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
+  endif
+
+  ifneq ($$(GTEST_REPEAT), )
+    $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
+  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)/gtest, \
+	    $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/server/gtestLauncher \
+	    -jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
+	    --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
+	    $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) \
+	    > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) || true )
+
+  $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.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))))
+	$$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
+	    test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE)))
+	$$(eval $1_PASSED := $$(shell $$(AWK) '/\[  PASSED  \] .* tests?./ \
+	    { print $$$$4 }' $$($1_RESULT_FILE)))
+	$$(eval $1_FAILED := $$(shell $$(AWK) '/\[  FAILED  \] .* tests?, \
+	    listed below/ { print $$$$4 }' $$($1_RESULT_FILE)))
+	$$(if $$($1_FAILED), , $$(eval $1_FAILED := 0))
+	$$(eval $1_ERROR := $$(shell \
+	    $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED)))
+
+  $1: run-test-$1 parse-test-$1
+
+  TARGETS += $1
+endef
+
+################################################################################
+
+### Rules for Jtreg
+
+# Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
+# 1) Specified by user on command line
+# 2) Component-specific default
+# 3) Generic default
+#
+# Note: No spaces are allowed around the arguments.
+# Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
+# Arg $2 Base variable, e.g. JTREG_JOBS
+# Arg $3 The default value (optional)
+define SetJtregValue
+  ifneq ($$($2), )
+    $1_$2 := $$($2)
+  else
+    ifneq ($$($$($1_COMPONENT)_$2), )
+      $1_$2 := $$($$($1_COMPONENT)_$2)
+    else
+      ifneq ($3, )
+        $1_$2 := $3
+      endif
+    endif
+  endif
+endef
+
+SetupRunJtregTest = $(NamedParamsMacroTemplate)
+define SetupRunJtregTestBody
+  $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
+  $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
+
+  $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
+  $1_COMPONENT := $$(firstword $$(subst /, $$(SPACE), $$($1_TEST_NAME)))
+
+  # Unfortunately, we need different defaults for some JTREG values,
+  # depending on what component we're running.
+
+  # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
+  $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
+  $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
+  $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
+  $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
+  $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
+
+  ifneq ($(TEST_JOBS), 0)
+    # User has specified TEST_JOBS, use that as fallback default
+    $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
+  else
+    # Use JOBS as default (except for hotspot)
+    $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
+  endif
+
+  ifeq ($$(shell $$(EXPR) $$($1_JTREG_JOBS) \> 50), 1)
+    # Until CODETOOLS-7901892 is fixed, JTreg cannot handle more than 50 jobs
+    $1_JTREG_JOBS := 50
+  endif
+
+  # Make sure MaxRAMFraction is high enough to not cause OOM or swapping since
+  # we may end up with a lot of JVM's
+  $1_JTREG_MAX_RAM_FRACTION := $$(shell $$(EXPR) $$($1_JTREG_JOBS) \* 4)
+
+  JTREG_TIMEOUT ?= 4
+  JTREG_VERBOSE ?= fail,error,summary
+  JTREG_RETAIN ?= fail,error
+
+  ifneq ($$($1_JTREG_MAX_MEM), 0)
+    $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
+    $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
+  endif
+
+  $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
+      -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
+      -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT) \
+      -vmoption:-XX:MaxRAMFraction=$$($1_JTREG_MAX_RAM_FRACTION)
+
+  $1_JTREG_BASIC_OPTIONS += -automatic -keywords:\!ignore -ignore:quiet
+
+  # Some tests needs to find a boot JDK using the JDK8_HOME variable.
+  $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
+
+  $1_JTREG_BASIC_OPTIONS += \
+      $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
+      $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
+      #
+
+  ifeq ($$($1_JTREG_ASSERT), true)
+    $1_JTREG_BASIC_OPTIONS += -ea -esa
+  endif
+
+  ifneq ($$($1_JTREG_NATIVEPATH), )
+    $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
+  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)/jtreg, \
+	    $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
+	        -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
+	        $$($1_JTREG_BASIC_OPTIONS) \
+	        -testjdk:$$(JDK_IMAGE_DIR) \
+	        -dir:$$(TOPDIR) \
+	        -reportDir:$$($1_TEST_RESULTS_DIR) \
+	        -workDir:$$($1_TEST_SUPPORT_DIR) \
+	        $$(JTREG_OPTIONS) \
+	        $$($1_TEST_NAME) || true )
+
+  $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.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))))
+	$$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
+	    for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
+	    print $$$$(i+1) } }' $$($1_RESULT_FILE)))
+	$$(if $$($1_PASSED), , $$(eval $1_PASSED := 0))
+	$$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
+	    for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
+	    print $$$$(i+1) } }' $$($1_RESULT_FILE)))
+	$$(if $$($1_FAILED), , $$(eval $1_FAILED := 0))
+	$$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
+	    for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
+	    print $$$$(i+1) } }' $$($1_RESULT_FILE)))
+	$$(if $$($1_ERROR), , $$(eval $1_ERROR := 0))
+	$$(eval $1_TOTAL := $$(shell \
+	    $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR)))
+
+  $1: run-test-$1 parse-test-$1
+
+  TARGETS += $1
+endef
+
+
+################################################################################
+# Setup and execute make rules for all selected tests
+################################################################################
+
+# Helper function to determine which handler to use for the given test
+UseGtestTestHandler = \
+  $(if $(filter gtest:%, $1), true)
+
+UseJtregTestHandler = \
+  $(if $(filter jtreg:%, $1), true)
+
+# Now process each test to run and setup a proper make rule
+$(foreach test, $(TESTS_TO_RUN), \
+  $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
+      $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
+  $(eval ALL_TEST_IDS += $(TEST_ID)) \
+  $(if $(call UseCustomTestHandler, $(test)), \
+    $(eval $(call SetupRunCustomTest, $(TEST_ID), \
+        TEST := $(test), \
+    )) \
+  ) \
+  $(if $(call UseGtestTestHandler, $(test)), \
+    $(eval $(call SetupRunGtestTest, $(TEST_ID), \
+        TEST := $(test), \
+    )) \
+  ) \
+  $(if $(call UseJtregTestHandler, $(test)), \
+    $(eval $(call SetupRunJtregTest, $(TEST_ID), \
+        TEST := $(test), \
+    )) \
+  ) \
+)
+
+# Sort also removes duplicates, so if there is any we'll get fewer words.
+ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
+  $(error Duplicate test specification)
+endif
+
+
+################################################################################
+# The main target for RunTests.gmk
+################################################################################
+
+# The SetupRun*Test functions have populated TARGETS.
+
+TEST_FAILURE := false
+
+run-test: $(TARGETS)
+        # Print a table of the result of all tests run and their result
+	$(ECHO)
+	$(ECHO) ==============================
+	$(ECHO) Test summary
+	$(ECHO) ==============================
+	$(PRINTF) "%2s %-49s %5s %5s %5s %5s %2s\n" "  " TEST \
+	    TOTAL PASS FAIL ERROR " "
+	$(foreach test, $(TESTS_TO_RUN), \
+	  $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
+	      $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
+	  $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
+	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" "  " "$(test)" \
+	        $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
+	        $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
+	  , \
+	    $(PRINTF) "%2s %-49s %5d %5d %5d %5d %2s\n" ">>" "$(test)" \
+	        $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) $($(TEST_ID)_FAILED) \
+	        $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
+	    $(eval TEST_FAILURE := true) \
+	  ) \
+	)
+	$(ECHO) ==============================
+	$(if $(filter true, $(TEST_FAILURE)), \
+	  $(ECHO) TEST FAILURE $(NEWLINE) \
+	  $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
+	, \
+	  $(ECHO) TEST SUCCESS \
+	)
+	$(ECHO)
+
+################################################################################
+
+all: run-test
+
+.PHONY: default all run-test $(TARGETS)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/common/FindTests.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -0,0 +1,76 @@
+#
+# Copyright (c) 2017, 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
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.  Oracle designates this
+# particular file as subject to the "Classpath" exception as provided
+# by Oracle in the LICENSE file that accompanied this code.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+ifndef _FIND_TESTS_GMK
+_FIND_TESTS_GMK := 1
+
+# Hook to include the corresponding custom file, if present.
+$(eval $(call IncludeCustomExtension, , common/FindTests.gmk))
+
+# JTREG_COMPONENTS might have been set by a custom extension
+JTREG_COMPONENTS += hotspot jdk langtools nashorn jaxp
+
+################################################################################
+# Find the Jtreg test groups for the given component.
+#
+# Parameter 1 is the name of the component. This name is used as variable prefix.
+#
+# After this macro has been evaluated, the following variables are defined for
+# the component:
+#   JTREG_TESTROOT - The path to the root of the test directory
+#   JTREG_GROUP_FILES - The file(s) containing the group definitions
+#   JTREG_TEST_GROUPS - The name of the test groups that the component defines
+#
+FindJtregGroups = $(NamedParamsMacroTemplate)
+define FindJtregGroupsBody
+  $1_JTREG_TESTROOT := $$(TOPDIR)/$1/test
+  ifneq ($$(wildcard $$($1_JTREG_TESTROOT)), )
+    $1_JTREG_GROUP_FILENAMES := $$(shell $$(SED) -n -e 's/\[\(.*\)\]/\1/g' \
+        -e 's/^groups\w*=//p' $$($1_JTREG_TESTROOT)/TEST.ROOT)
+    $1_JTREG_GROUP_FILES := $$(addprefix $$($1_JTREG_TESTROOT)/, \
+        $$($1_JTREG_GROUP_FILENAMES))
+    $1_JTREG_TEST_GROUPS := $$(strip $$(shell $$(SED) -n \
+        -e 's/\([^ ]*\)\w*=.*/\1/gp' $$($1_JTREG_GROUP_FILES) | $$(SORT) -u))
+  endif
+endef
+
+# Configure definitions for all available test components
+$(foreach component, $(JTREG_COMPONENTS), \
+    $(eval $(call FindJtregGroups, $(component))))
+
+# Create a list of all available Jtreg test groups in all components
+JTREG_TEST_GROUPS += $(sort $(foreach component, $(JTREG_COMPONENTS), \
+    $($(component)_JTREG_TEST_GROUPS)))
+
+# 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)
+
+# Add Gtest
+ALL_NAMED_TESTS += gtest
+
+################################################################################
+
+endif # _FIND_TESTS_GMK
--- a/make/common/MakeBase.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/make/common/MakeBase.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -755,6 +755,55 @@
 endef
 
 ################################################################################
+# Parse a multiple-keyword variable, like FOO="KEYWORD1=val1;KEYWORD2=val2;..."
+# These will be converted into a series of variables like FOO_KEYWORD1=val1,
+# FOO_KEYWORD2=val2, etc. Unknown keywords will cause an error.
+#
+# Parameter 1 is the name of the rule, and is also the name of the variable.
+#
+# Remaining parameters are named arguments. These include:
+#   KEYWORDS          A list of valid keywords
+#   STRING_KEYWORDS   A list of valid keywords, processed as string. This means
+#       that '%20' will be replaced by ' ' to allow for multi-word strings.
+#
+ParseKeywordVariable = $(NamedParamsMacroTemplate)
+define ParseKeywordVariableBody
+  ifneq ($$($1), )
+    # To preserve spaces, substitute them with a hopefully unique pattern
+    # before splitting and then re-substitute spaces back.
+    $1_MANGLED := $$(subst $$(SPACE),||||,$$($1))
+    $$(foreach mangled_part, $$(subst ;, , $$($1_MANGLED)), \
+      $$(eval mangled_part_eval := $$(call DoubleDollar, $$(mangled_part))) \
+      $$(eval part := $$$$(subst ||||,$$$$(SPACE),$$$$(mangled_part_eval))) \
+      $$(eval $1_NO_MATCH := true) \
+      $$(foreach keyword, $$($1_KEYWORDS), \
+        $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
+        $$(if $$(filter $$(keyword)=%, $$(part)), \
+          $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part)))) \
+          $$(eval $1_NO_MATCH := ) \
+        ) \
+      ) \
+      $$(foreach keyword, $$($1_STRING_KEYWORDS), \
+        $$(eval keyword_eval := $$(call DoubleDollar, $$(keyword))) \
+        $$(if $$(filter $$(keyword)=%, $$(part)), \
+          $$(eval $(strip $1)_$$$$(keyword_eval) := $$$$(strip $$$$(subst %20, , $$$$(patsubst $$$$(keyword_eval)=%, %, $$$$(part))))) \
+          $$(eval $1_NO_MATCH := ) \
+        ) \
+      ) \
+      $$(if $$($1_NO_MATCH), \
+        $$(if $$(filter $$(part), $$($1_KEYWORDS) $$($1_STRING_KEYWORDS)), \
+          $$(info Keyword $$(part) for $1 needs to be assigned a value.) \
+        , \
+          $$(info $$(part) is not a valid keyword for $1.) \
+          $$(info Valid keywords: $$($1_KEYWORDS) $$($1_STRING_KEYWORDS).) \
+        ) \
+        $$(error Cannot continue) \
+      ) \
+    )
+  endif
+endef
+
+################################################################################
 # ShellQuote
 #
 # Quotes a string with single quotes and replaces single quotes with '\'' so
@@ -764,6 +813,22 @@
     $(SQUOTE)$(subst $(SQUOTE),$(SQUOTE)\$(SQUOTE)$(SQUOTE),$(strip $1))$(SQUOTE)
 
 ################################################################################
+# FixPath
+#
+# On Windows, converts a path from cygwin/unix style (e.g. /bin/foo) into
+# "mixed mode" (e.g. c:/cygwin/bin/foo). On other platforms, return the path
+# unchanged.
+# This is normally not needed since we use the FIXPATH prefix for command lines,
+# but might be needed in certain circumstances.
+ifeq ($(OPENJDK_TARGET_OS), windows)
+  FixPath = \
+      $(shell $(CYGPATH) -m $1)
+else
+  FixPath = \
+      $1
+endif
+
+################################################################################
 # Write to and read from file
 
 # Param 1 - File to read
--- a/test/make/TestMakeBase.gmk	Fri Mar 03 01:44:55 2017 +0000
+++ b/test/make/TestMakeBase.gmk	Fri Mar 03 12:57:57 2017 +0100
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2017, 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
@@ -179,7 +179,7 @@
 	test "some string value1" = "`$(CAT) $(VARDEP_DIR)/target-file`"
 	test -e $(VARDEP_FLAG_FILE)
         #
-        # Make the target file again and verify that the value is updated with 
+        # Make the target file again and verify that the value is updated with
         # the new value
         #
 	$(SLEEP_ON_MAC)
@@ -341,5 +341,60 @@
 ))
 
 ################################################################################
+# Test ParseKeywordVariable
+
+KWBASE := APA=banan;GURKA=tomat;COUNT=1%202%203%204%205;SUM=1+2+3+4+5;MANY_WORDS=I have the best words.
+
+$(eval $(call ParseKeywordVariable, KWBASE, \
+    KEYWORDS := APA GURKA SUM, \
+    STRING_KEYWORDS := COUNT MANY_WORDS, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_APA), \
+    banan, \
+    ParseKeywordVariable failed to parse APA, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_COUNT), \
+    1 2 3 4 5, \
+    ParseKeywordVariable failed to parse COUNT, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_SUM), \
+    1+2+3+4+5, \
+    ParseKeywordVariable failed to parse SUM, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_MANY_WORDS), \
+    I have the best words., \
+    ParseKeywordVariable failed to parse MANY_WORDS, \
+))
+
+# Simulate variable set from command line by using "override"
+override KWBASE_WEIRD_GURKA := paprika
+KWBASE_WEIRD := ;;APA=banan;;;GURKA=apelsin;APA=skansen;;
+
+$(eval $(call ParseKeywordVariable, KWBASE_WEIRD, \
+    KEYWORDS := APA GURKA SUM, \
+    STRING_KEYWORDS := COUNT, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_WEIRD_APA), \
+    skansen, \
+    ParseKeywordVariable failed to overwrite APA, \
+))
+
+$(eval $(call assert-equals, \
+    $(KWBASE_WEIRD_GURKA), \
+    paprika, \
+    ParseKeywordVariable failed to preserve GURKA, \
+))
+
+################################################################################
 
 all: $(TEST_TARGETS)