1 #
   2 # Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 default: all
  27 
  28 include $(SPEC)
  29 include MakeBase.gmk
  30 include FindTests.gmk
  31 
  32 # We will always run multiple tests serially
  33 .NOTPARALLEL:
  34 
  35 ################################################################################
  36 # Parse global control variables
  37 ################################################################################
  38 
  39 ifneq ($(TEST_VM_OPTS), )
  40   ifneq ($(TEST_OPTS), )
  41     TEST_OPTS := $(TEST_OPTS);VM_OPTIONS=$(TEST_VM_OPTS)
  42   else
  43     TEST_OPTS := VM_OPTIONS=$(TEST_VM_OPTS)
  44   endif
  45 endif
  46 
  47 $(eval $(call ParseKeywordVariable, TEST_OPTS, \
  48     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR AOT_MODULES, \
  49     STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS, \
  50 ))
  51 
  52 # Helper function to propagate TEST_OPTS values.
  53 #
  54 # Note: No spaces are allowed around the arguments.
  55 # Arg $1 The variable in TEST_OPTS to propagate
  56 # Arg $2 The control variable to propagate it to
  57 define SetTestOpt
  58   ifneq ($$(TEST_OPTS_$1), )
  59     $2_$1 := $$(TEST_OPTS_$1)
  60   endif
  61 endef
  62 
  63 # Setup _NT_SYMBOL_PATH on Windows
  64 ifeq ($(OPENJDK_TARGET_OS), windows)
  65   ifndef _NT_SYMBOL_PATH
  66     # Can't use PathList here as it adds quotes around the value.
  67     _NT_SYMBOL_PATH := \
  68         $(subst $(SPACE),;,$(strip \
  69             $(foreach p, $(sort $(dir $(wildcard \
  70                 $(addprefix $(SYMBOLS_IMAGE_DIR)/bin/, *.pdb */*.pdb)))), \
  71               $(call FixPath, $p) \
  72             ) \
  73         ))
  74     export _NT_SYMBOL_PATH
  75     $(info _NT_SYMBOL_PATH=$(_NT_SYMBOL_PATH))
  76   endif
  77 endif
  78 
  79 ################################################################################
  80 # Hook to include the corresponding custom file, if present.
  81 $(eval $(call IncludeCustomExtension, RunTests.gmk))
  82 ################################################################################
  83 
  84 TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
  85 TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
  86 TEST_SUMMARY := $(TEST_RESULTS_DIR)/test-summary.txt
  87 TEST_LAST_IDS := $(TEST_SUPPORT_DIR)/test-last-ids.txt
  88 
  89 ifeq ($(CUSTOM_ROOT), )
  90   JTREG_TOPDIR := $(TOPDIR)
  91 else
  92   JTREG_TOPDIR := $(CUSTOM_ROOT)
  93 endif
  94 
  95 JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler
  96 JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar
  97 
  98 ifneq ($(wildcard $(JTREG_FAILURE_HANDLER)), )
  99   JTREG_FAILURE_HANDLER_OPTIONS := \
 100       -timeoutHandlerDir:$(JTREG_FAILURE_HANDLER) \
 101       -observerDir:$(JTREG_FAILURE_HANDLER) \
 102       -timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler \
 103       -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \
 104       -timeoutHandlerTimeout:0
 105 endif
 106 
 107 GTEST_LAUNCHER_DIRS := $(patsubst %/gtestLauncher, %, $(wildcard $(TEST_IMAGE_DIR)/hotspot/gtest/*/gtestLauncher))
 108 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, $(GTEST_LAUNCHER_DIRS)))
 109 
 110 ################################################################################
 111 # Optionally create AOT libraries for specified modules before running tests.
 112 # Note, this could not be done during JDK build time.
 113 ################################################################################
 114 
 115 # Note, this could not be done during JDK build time.
 116 
 117 # Parameter 1 is the name of the rule.
 118 #
 119 # Remaining parameters are named arguments.
 120 #   MODULE      The module to generate a library for
 121 #   BIN         Output directory in which to put the library
 122 #   VM_OPTIONS  List of JVM arguments to use when creating library
 123 #   OPTIONS_VAR Name of variable to put AOT java options in
 124 #   PREREQS_VAR Name of variable to put all AOT prerequisite rule targets in
 125 #               for test rules to depend on
 126 #
 127 SetupAotModule = $(NamedParamsMacroTemplate)
 128 define SetupAotModuleBody
 129   $1_AOT_LIB := $$($1_BIN)/$$(call SHARED_LIBRARY,$$($1_MODULE))
 130   $1_AOT_CCLIST := $$(wildcard $$(TOPDIR)/test/hotspot/jtreg/compiler/aot/scripts/$$($1_MODULE)-list.txt)
 131 
 132   ifeq ($(OPENJDK_TARGET_OS), windows)
 133     $1_LD := $$(addsuffix $$(EXE_SUFFIX), $$(filter-out $$(FIXPATH), $$(LD)))
 134   else
 135     $1_LD := $$(LD)
 136   endif
 137 
 138   $1_JAOTC_OPTS := \
 139       -J-Xmx4g --info \
 140       $$(addprefix -J, $$($1_VM_OPTIONS)) \
 141       $$(addprefix --compile-commands$(SPACE), $$($1_AOT_CCLIST)) \
 142       --linker-path $$($1_LD) \
 143       #
 144 
 145   ifneq ($$(filter -ea, $$($1_VM_OPTIONS)), )
 146     $1_JAOTC_OPTS += --compile-with-assertions
 147   endif
 148 
 149   $$($1_AOT_LIB): $$(JDK_IMAGE_DIR)/release \
 150       $$(call DependOnVariable, $1_JAOTC_OPTS) \
 151       $$(call DependOnVariable, JDK_IMAGE_DIR)
 152         $$(call LogWarn, Generating $$(patsubst $$(OUTPUTDIR)/%, %, $$@))
 153         $$(call MakeTargetDir)
 154         $$(call ExecuteWithLog, $$@, \
 155             $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/jaotc \
 156             $$($1_JAOTC_OPTS) --output $$@ --module $$($1_MODULE) \
 157         )
 158         $$(call ExecuteWithLog, $$@.check, \
 159           $$(FIXPATH) $$(JDK_IMAGE_DIR)/bin/java \
 160           $$($1_VM_OPTIONS) -XX:+PrintAOT -XX:+UseAOTStrictLoading -XX:AOTLibrary=$$@ -version \
 161           > $$@.verify-aot \
 162         )
 163 
 164   $1_AOT_OPTIONS += -XX:AOTLibrary=$$($1_AOT_LIB)
 165   $1_AOT_TARGETS += $$($1_AOT_LIB)
 166 endef
 167 
 168 # Parameter 1 is the name of the rule.
 169 #
 170 # Remaining parameters are named arguments.
 171 #   MODULES     The modules to generate a library for
 172 #   VM_OPTIONS  List of JVM arguments to use when creating libraries
 173 #
 174 # After calling this, the following variables are defined
 175 #   $1_AOT_OPTIONS List of all java options needed to use the AOT libraries
 176 #   $1_AOT_TARGETS List of all targets that the test rule will need to depend on
 177 #
 178 SetupAot = $(NamedParamsMacroTemplate)
 179 define SetupAotBody
 180   $$(info Running with AOTd libraries for $$($1_MODULES))
 181   # Put aot libraries in a separate directory so they are not deleted between
 182   # test runs and may be reused between make invocations.
 183   $$(foreach m, $$($1_MODULES), \
 184     $$(eval $$(call SetupAotModule, $1_$$m, \
 185         MODULE := $$m, \
 186         BIN := $$(TEST_SUPPORT_DIR)/aot/$1, \
 187         VM_OPTIONS := $$($1_VM_OPTIONS), \
 188     )) \
 189     $$(eval $1_AOT_OPTIONS += $$($1_$$m_AOT_OPTIONS)) \
 190     $$(eval $1_AOT_TARGETS += $$($1_$$m_AOT_TARGETS)) \
 191   )
 192 endef
 193 
 194 ################################################################################
 195 # Setup global test running parameters
 196 ################################################################################
 197 
 198 # Each factor variable comes in 3 variants. The first one is reserved for users
 199 # to use on command line. The other two are for predifined configurations in JDL
 200 # and for machine specific configurations respectively.
 201 TEST_JOBS_FACTOR ?= 1
 202 TEST_JOBS_FACTOR_JDL ?= 1
 203 TEST_JOBS_FACTOR_MACHINE ?= 1
 204 
 205 ifeq ($(TEST_JOBS), 0)
 206   CORES_DIVIDER := 2
 207   ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
 208     # For smaller SPARC machines we see reasonable scaling of throughput up to
 209     # cpus/4 without affecting test reliability. On the bigger machines, cpus/4
 210     # causes intermittent timeouts.
 211     ifeq ($(shell $(EXPR) $(NUM_CORES) \> 16), 1)
 212       CORES_DIVIDER := 5
 213     else
 214       CORES_DIVIDER := 4
 215     endif
 216   endif
 217   MEMORY_DIVIDER := 2048
 218   TEST_JOBS := $(shell $(AWK) \
 219     'BEGIN { \
 220       c = $(NUM_CORES) / $(CORES_DIVIDER); \
 221       m = $(MEMORY_SIZE) / $(MEMORY_DIVIDER); \
 222       if (c > m) c = m; \
 223       c = c * $(TEST_JOBS_FACTOR); \
 224       c = c * $(TEST_JOBS_FACTOR_JDL); \
 225       c = c * $(TEST_JOBS_FACTOR_MACHINE); \
 226       if (c < 1) c = 1; \
 227       printf "%.0f", c; \
 228     }')
 229 endif
 230 
 231 ################################################################################
 232 # Parse control variables
 233 ################################################################################
 234 
 235 ifneq ($(TEST_OPTS), )
 236   # Inform the user
 237   $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
 238 endif
 239 
 240 ### Jtreg
 241 
 242 $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
 243 $(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
 244 $(eval $(call SetTestOpt,AOT_MODULES,JTREG))
 245 
 246 $(eval $(call SetTestOpt,JOBS,JTREG))
 247 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
 248 
 249 $(eval $(call ParseKeywordVariable, JTREG, \
 250     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM \
 251         EXTRA_PROBLEM_LISTS KEYWORDS AOT_MODULES, \
 252     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS, \
 253 ))
 254 
 255 ifneq ($(JTREG), )
 256   # Inform the user
 257   $(info Running tests using JTREG control variable '$(JTREG)')
 258 endif
 259 
 260 ### Gtest
 261 
 262 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
 263 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
 264 $(eval $(call SetTestOpt,AOT_MODULES,GTEST))
 265 
 266 $(eval $(call ParseKeywordVariable, GTEST, \
 267     SINGLE_KEYWORDS := REPEAT AOT_MODULES, \
 268     STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
 269 ))
 270 
 271 ifneq ($(GTEST), )
 272   # Inform the user
 273   $(info Running tests using GTEST control variable '$(GTEST)')
 274 endif
 275 
 276 ### Microbenchmarks
 277 
 278 $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
 279 $(eval $(call SetTestOpt,JAVA_OPTIONS,MICRO))
 280 
 281 $(eval $(call ParseKeywordVariable, MICRO, \
 282     SINGLE_KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
 283     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS RESULTS_FORMAT TEST_JDK BENCHMARKS_JAR, \
 284 ))
 285 
 286 ifneq ($(MICRO), )
 287   # Inform the user
 288   $(info Running tests using MICRO control variable '$(MICRO)')
 289 endif
 290 
 291 
 292 ################################################################################
 293 # Component-specific Jtreg settings
 294 ################################################################################
 295 
 296 hotspot_JTREG_MAX_MEM := 0
 297 hotspot_JTREG_ASSERT := false
 298 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
 299 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
 300 
 301 jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
 302 jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
 303 langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
 304 nashorn_JTREG_PROBLEM_LIST += $(TOPDIR)/test/nashorn/ProblemList.txt
 305 hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
 306 
 307 langtools_JTREG_MAX_MEM := 768m
 308 
 309 ################################################################################
 310 # Parse test selection
 311 #
 312 # The user has given a test selection in the TEST variable. We must parse it
 313 # and determine what that means in terms of actual calls to the test framework.
 314 #
 315 # The parse functions take as argument a test specification as given by the
 316 # user, and returns a fully qualified test descriptor if it was a match, or
 317 # nothing if not. A single test specification can result in multiple test
 318 # descriptors being returned. A valid test descriptor must always be accepted
 319 # and returned identically.
 320 ################################################################################
 321 
 322 # Helper function to determine if a test specification is a Gtest test
 323 #
 324 # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
 325 # test filter string, and an optional "/<variant>" to select a specific JVM
 326 # variant. If no variant is specified, all found variants are tested.
 327 define ParseGtestTestSelection
 328   $(if $(filter gtest%, $1), \
 329     $(if $(filter gtest, $1), \
 330       $(addprefix gtest:all/, $(GTEST_VARIANTS)) \
 331     , \
 332       $(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
 333         $(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
 334       , \
 335         $(if $(filter gtest:%, $1), \
 336           $(if $(findstring /, $1), \
 337             $1 \
 338           , \
 339             $(addprefix $1/, $(GTEST_VARIANTS)) \
 340           ) \
 341         ) \
 342       ) \
 343     ) \
 344   )
 345 endef
 346 
 347 # Helper function to determine if a test specification is a microbenchmark test
 348 #
 349 # It is a microbenchmark test if it is either "micro", or "micro:" followed by an optional
 350 # test filter string.
 351 define ParseMicroTestSelection
 352   $(if $(filter micro%, $1), \
 353     $(if $(filter micro, $1), \
 354       micro:all \
 355     , \
 356       $(if $(filter micro:, $1), \
 357         micro:all \
 358       , \
 359         $1 \
 360       ) \
 361     ) \
 362   )
 363 endef
 364 
 365 # Helper function that removes the TOPDIR part
 366 CleanupJtregPath = \
 367   $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
 368 
 369 # Take a partial Jtreg root path and return a full, absolute path to that Jtreg
 370 # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
 371 ExpandJtregRoot = \
 372   $(call CleanupJtregPath, $(wildcard \
 373     $(if $(filter /%, $1), \
 374       $(if $(wildcard $(strip $1)/TEST.ROOT), \
 375         $1 \
 376       ) \
 377     , \
 378       $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 379       $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 380     ) \
 381   ))
 382 
 383 # Take a partial Jtreg test path and return a full, absolute path to that Jtreg
 384 # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
 385 ExpandJtregPath = \
 386   $(if $(call ExpandJtregRoot, $1), \
 387     $(call ExpandJtregRoot, $1) \
 388   , \
 389     $(call CleanupJtregPath, $(wildcard \
 390       $(if $(filter /%, $1), \
 391         $1 \
 392       , \
 393         $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 394         $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 395       ) \
 396     )) \
 397   )
 398 
 399 # Helper function to determine if a test specification is a Jtreg test
 400 #
 401 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
 402 # an unspecified group name (possibly prefixed by :), or a group in a
 403 # specified test root, or a path to a test or test directory,
 404 # either absolute or relative to any of the TEST_BASEDIRS or test roots.
 405 define ParseJtregTestSelection
 406   $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
 407   $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
 408     $(eval TEST_NAME := :$(TEST_NAME)) \
 409   ) \
 410   $(if $(findstring :, $(TEST_NAME)), \
 411     $(if $(filter :%, $(TEST_NAME)), \
 412       $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
 413       $(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
 414           $(call CleanupJtregPath, $(test_root)))) \
 415     , \
 416       $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
 417       $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
 418       $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
 419     ) \
 420     $(foreach test_root, $(TEST_ROOTS), \
 421       $(if $(filter /%, $(test_root)), \
 422         jtreg:$(test_root):$(TEST_GROUP) \
 423       , \
 424         $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
 425           jtreg:$(test_root):$(TEST_GROUP) \
 426         ) \
 427       ) \
 428     ) \
 429   , \
 430     $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
 431     $(foreach test_path, $(TEST_PATHS), \
 432       jtreg:$(test_path) \
 433     ) \
 434   )
 435 endef
 436 
 437 # Helper function to determine if a test specification is a special test
 438 #
 439 # It is a special test if it is "special:" followed by a test name,
 440 # if it is "make:" or "make-" followed by a make test, or any of the special test names
 441 # as a single word.
 442 define ParseSpecialTestSelection
 443   $(if $(filter special:%, $1), \
 444     $1 \
 445   ) \
 446   $(if $(filter make%, $1), \
 447     $(if $(filter make:%, $1), \
 448       special:$(strip $1) \
 449     ) \
 450     $(if $(filter make-%, $1), \
 451       special:$(patsubst make-%,make:%, $1) \
 452     ) \
 453     $(if $(filter make, $1), \
 454       special:make:all \
 455     )
 456   ) \
 457   $(if $(filter failure-handler, $1), \
 458     special:$(strip $1) \
 459   )
 460 endef
 461 
 462 ifeq ($(TEST), )
 463   $(info No test selection given in TEST!)
 464   $(info Please use e.g. 'make test TEST=tier1' or 'make test-tier1')
 465   $(info See doc/testing.[md|html] for help)
 466   $(error Cannot continue)
 467 endif
 468 
 469 # Now intelligently convert the test selection given by the user in TEST
 470 # into a list of fully qualified test descriptors of the tests to run.
 471 TESTS_TO_RUN :=
 472 $(foreach test, $(TEST), \
 473   $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
 474   $(if $(strip $(PARSED_TESTS)), , \
 475     $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
 476   ) \
 477   $(if $(strip $(PARSED_TESTS)), , \
 478     $(eval PARSED_TESTS += $(call ParseMicroTestSelection, $(test))) \
 479   ) \
 480   $(if $(strip $(PARSED_TESTS)), , \
 481     $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
 482   ) \
 483   $(if $(strip $(PARSED_TESTS)), , \
 484     $(eval PARSED_TESTS += $(call ParseSpecialTestSelection, $(test))) \
 485   ) \
 486   $(if $(strip $(PARSED_TESTS)), , \
 487     $(eval UNKNOWN_TEST := $(test)) \
 488   ) \
 489   $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
 490 )
 491 
 492 ifneq ($(UNKNOWN_TEST), )
 493   $(info Unknown test selection: '$(UNKNOWN_TEST)')
 494   $(info See doc/testing.[md|html] for help)
 495   $(error Cannot continue)
 496 endif
 497 
 498 TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
 499 
 500 
 501 # Present the result of our parsing to the user
 502 $(info Test selection '$(TEST)', will run:)
 503 $(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
 504 
 505 
 506 ################################################################################
 507 # Functions for setting up rules for running the selected tests
 508 #
 509 # The SetupRun*Test functions all have the same interface:
 510 #
 511 # Parameter 1 is the name of the rule. This is the test id, based on the test
 512 # descriptor, and this is also used as variable prefix, and the targets
 513 # generated are listed in a variable by that name.
 514 #
 515 # Remaining parameters are named arguments. Currently this is only:
 516 #   TEST -- The properly formatted fully qualified test descriptor
 517 #
 518 # After the rule named by the test id has been executed, the following
 519 # variables will be available:
 520 # testid_TOTAL - the total number of tests run
 521 # testid_PASSED - the number of successful tests
 522 # testid_FAILED - the number of failed tests
 523 # testid_ERROR - the number of tests was neither successful or failed
 524 #
 525 ################################################################################
 526 
 527 ### Rules for Gtest
 528 
 529 SetupRunGtestTest = $(NamedParamsMacroTemplate)
 530 define SetupRunGtestTestBody
 531   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 532   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 533   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 534 
 535   $1_VARIANT :=  $$(lastword $$(subst /, , $$($1_TEST)))
 536   ifeq ($$(filter $$($1_VARIANT), $$(GTEST_VARIANTS)), )
 537     $$(error Invalid gtest variant '$$($1_VARIANT)'. Valid variants: $$(GTEST_VARIANTS))
 538   endif
 539   $1_TEST_NAME := $$(strip $$(patsubst %/$$($1_VARIANT), %, \
 540       $$(patsubst gtest:%, %, $$($1_TEST))))
 541   ifneq ($$($1_TEST_NAME), all)
 542     $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
 543   endif
 544 
 545   ifneq ($$(GTEST_REPEAT), )
 546     $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
 547   endif
 548 
 549   ifneq ($$(GTEST_AOT_MODULES), )
 550     $$(eval $$(call SetupAot, $1, \
 551         MODULES := $$(GTEST_AOT_MODULES), \
 552         VM_OPTIONS := $$(GTEST_VM_OPTIONS) $$(GTEST_JAVA_OPTIONS), \
 553     ))
 554   endif
 555 
 556   run-test-$1: $$($1_AOT_TARGETS)
 557         $$(call LogWarn)
 558         $$(call LogWarn, Running test '$$($1_TEST)')
 559         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 560         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, \
 561             $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \
 562                 -jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
 563                 --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
 564                 $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
 565                 $$(GTEST_JAVA_OPTIONS) $$($1_AOT_OPTIONS) \
 566                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
 567             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 568             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 569         )
 570 
 571   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 572 
 573   parse-test-$1: run-test-$1
 574         $$(call LogWarn, Finished running test '$$($1_TEST)')
 575         $$(call LogWarn, Test report is stored in $$(strip \
 576             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 577         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 578           $$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
 579               test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE))) \
 580           $$(if $$($1_TOTAL), , $$(eval $1_TOTAL := 0)) \
 581           $$(eval $1_PASSED := $$(shell $$(AWK) '/\[  PASSED  \] .* tests?./ \
 582               { print $$$$4 }' $$($1_RESULT_FILE))) \
 583           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 584           $$(eval $1_FAILED := $$(shell $$(AWK) '/\[  FAILED  \] .* tests?, \
 585               listed below/ { print $$$$4 }' $$($1_RESULT_FILE))) \
 586           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 587           $$(eval $1_ERROR := $$(shell \
 588               $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED))) \
 589         , \
 590           $$(eval $1_PASSED := 0) \
 591           $$(eval $1_FAILED := 0) \
 592           $$(eval $1_ERROR := 1) \
 593           $$(eval $1_TOTAL := 1) \
 594         )
 595 
 596   $1: run-test-$1 parse-test-$1
 597 
 598   TARGETS += $1
 599 endef
 600 
 601 ################################################################################
 602 
 603 ### Rules for Microbenchmarks
 604 
 605 # Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
 606 # 1) Specified by user on command line
 607 # 2) Generic default
 608 #
 609 # Note: No spaces are allowed around the arguments.
 610 # Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
 611 # Arg $2 Base variable, e.g. MICRO_TEST_JDK
 612 # Arg $3 The default value (optional)
 613 define SetMicroValue
 614   ifneq ($$($2), )
 615     $1_$2 := $$($2)
 616   else
 617     ifneq ($3, )
 618       $1_$2 := $3
 619     endif
 620   endif
 621 endef
 622 
 623 SetupRunMicroTest = $(NamedParamsMacroTemplate)
 624 define SetupRunMicroTestBody
 625   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 626   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 627   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 628 
 629   $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
 630 
 631   $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/benchmarks.jar))
 632   $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_IMAGE_DIR)))
 633   $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
 634 
 635   # Current tests needs to open java.io
 636   $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
 637 
 638   # Save output as JSON or CSV file
 639   ifneq ($$(MICRO_RESULTS_FORMAT), )
 640     $1_MICRO_BASIC_OPTIONS += -rf $$(MICRO_RESULTS_FORMAT) -rff $$($1_TEST_RESULTS_DIR)/jmh-result.$(MICRO_RESULTS_FORMAT)
 641   endif
 642 
 643   ifneq ($$(MICRO_VM_OPTIONS)$$(MICRO_JAVA_OPTIONS), )
 644     $1_MICRO_VM_OPTIONS := -jvmArgs $$(MICRO_VM_OPTIONS) $$(MICRO_JAVA_OPTIONS)
 645   endif
 646 
 647   ifneq ($$(MICRO_ITER), )
 648     $1_MICRO_ITER := -i $$(MICRO_ITER)
 649   endif
 650   ifneq ($$(MICRO_FORK), )
 651     $1_MICRO_FORK := -f $$(MICRO_FORK)
 652   endif
 653   ifneq ($$(MICRO_TIME), )
 654     $1_MICRO_TIME := -r $$(MICRO_TIME)
 655   endif
 656   ifneq ($$(MICRO_WARMUP_ITER), )
 657     $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
 658   endif
 659   ifneq ($$(MICRO_WARMUP_TIME), )
 660     $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
 661   endif
 662 
 663   run-test-$1:
 664         $$(call LogWarn)
 665         $$(call LogWarn, Running test '$$($1_TEST)')
 666         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 667         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, \
 668             $$($1_MICRO_TEST_JDK)/bin/java $$($1_MICRO_JAVA_OPTIONS) -jar $$($1_MICRO_BENCHMARKS_JAR) \
 669                 $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
 670                 $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
 671                 $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS)  \
 672                 $$($1_TEST_NAME) \
 673                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
 674             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 675             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 676         )
 677 
 678   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
 679 
 680   parse-test-$1: run-test-$1
 681         $$(call LogWarn, Finished running test '$$($1_TEST)')
 682         $$(call LogWarn, Test report is stored in $$(strip \
 683             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 684         $$(if $$(wildcard $$($1_EXITCODE)), \
 685           $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
 686           $$(if $$(filter 0, $$($1_EXIT_CODE)), \
 687             $$(eval $1_PASSED := 1) \
 688             $$(eval $1_ERROR := 0) \
 689           , \
 690             $$(eval $1_PASSED := 0) \
 691             $$(eval $1_ERROR := 1) \
 692           ) \
 693           $$(eval $1_FAILED := 0) \
 694           $$(eval $1_TOTAL := $$(shell \
 695               $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
 696         , \
 697           $$(eval $1_PASSED := 0) \
 698           $$(eval $1_FAILED := 0) \
 699           $$(eval $1_ERROR := 1) \
 700           $$(eval $1_TOTAL := 1) \
 701         )
 702 
 703   $1: run-test-$1 parse-test-$1
 704 
 705   TARGETS += $1
 706 endef
 707 
 708 ################################################################################
 709 
 710 ### Rules for Jtreg
 711 
 712 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
 713 # 1) Specified by user on command line
 714 # 2) Component-specific default
 715 # 3) Generic default
 716 #
 717 # Note: No spaces are allowed around the arguments.
 718 # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
 719 # Arg $2 Base variable, e.g. JTREG_JOBS
 720 # Arg $3 The default value (optional)
 721 define SetJtregValue
 722   ifneq ($$($2), )
 723     $1_$2 := $$($2)
 724   else
 725     ifneq ($$($$($1_COMPONENT)_$2), )
 726       $1_$2 := $$($$($1_COMPONENT)_$2)
 727     else
 728       ifneq ($3, )
 729         $1_$2 := $3
 730       endif
 731     endif
 732   endif
 733 endef
 734 
 735 SetupRunJtregTest = $(NamedParamsMacroTemplate)
 736 define SetupRunJtregTestBody
 737   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 738   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 739   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 740 
 741   $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
 742 
 743   $1_TEST_ROOT := \
 744       $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
 745         $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), $$(root)) \
 746       ))
 747   $1_COMPONENT := $$(lastword $$(subst /, $$(SPACE), $$($1_TEST_ROOT)))
 748   # This will work only as long as just hotspot has the additional "jtreg" directory
 749   ifeq ($$($1_COMPONENT), jtreg)
 750     $1_COMPONENT := hotspot
 751   endif
 752 
 753   ifeq ($$(JT_HOME), )
 754     $$(info Error: jtreg framework is not found.)
 755     $$(info Please run configure using --with-jtreg.)
 756     $$(error Cannot continue)
 757   endif
 758 
 759   # Unfortunately, we need different defaults for some JTREG values,
 760   # depending on what component we're running.
 761 
 762   # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
 763   $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
 764   $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
 765   $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
 766   $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
 767   $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
 768   $$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
 769 
 770   # Only the problem list for the current test root should be used.
 771   $1_JTREG_PROBLEM_LIST := $$(filter $$($1_TEST_ROOT)%, $$($1_JTREG_PROBLEM_LIST))
 772 
 773   ifneq ($(TEST_JOBS), 0)
 774     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
 775   else
 776     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
 777   endif
 778 
 779   # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
 780   # we may end up with a lot of JVM's
 781   $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $$(EXPR) 25 / $$($1_JTREG_JOBS))
 782 
 783   # SPARC is in general slower per core so need to scale up timeouts a bit.
 784   ifeq ($(OPENJDK_TARGET_CPU_ARCH), sparc)
 785     JTREG_TIMEOUT_FACTOR ?= 8
 786   else
 787     JTREG_TIMEOUT_FACTOR ?= 4
 788   endif
 789   JTREG_VERBOSE ?= fail,error,summary
 790   JTREG_RETAIN ?= fail,error
 791 
 792   ifneq ($$($1_JTREG_MAX_MEM), 0)
 793     $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
 794     $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
 795   endif
 796 
 797   $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
 798       -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
 799       -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR) \
 800       -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE)
 801 
 802   $1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet
 803 
 804   # Make it possible to specify the JIB_DATA_DIR for tests using the
 805   # JIB Artifact resolver
 806   $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
 807   # Some tests needs to find a boot JDK using the JDK8_HOME variable.
 808   $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
 809   # If running on Windows, propagate the _NT_SYMBOL_PATH to enable
 810   # symbol lookup in hserr files
 811   ifeq ($$(OPENJDK_TARGET_OS), windows)
 812     $1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH
 813   endif
 814 
 815   $1_JTREG_BASIC_OPTIONS += \
 816       $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
 817       $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
 818       #
 819 
 820   ifeq ($$($1_JTREG_ASSERT), true)
 821     $1_JTREG_BASIC_OPTIONS += -ea -esa
 822   endif
 823 
 824   ifneq ($$($1_JTREG_NATIVEPATH), )
 825     $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
 826   endif
 827 
 828   ifneq ($$($1_JTREG_PROBLEM_LIST), )
 829     $1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$($1_JTREG_PROBLEM_LIST))
 830   endif
 831 
 832   ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), )
 833     # Accept both absolute paths as well as relative to the current test root.
 834     $1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$(wildcard \
 835         $$(JTREG_EXTRA_PROBLEM_LISTS) \
 836         $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
 837     ))
 838   endif
 839 
 840   ifneq ($$(JIB_HOME), )
 841     $1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
 842   endif
 843 
 844   $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=${TEST_IMAGE_DIR}/hotspot/jtreg/graal
 845 
 846   ifneq ($$(JTREG_FAILURE_HANDLER_OPTIONS), )
 847     $1_JTREG_LAUNCHER_OPTIONS += -Djava.library.path="$(JTREG_FAILURE_HANDLER_DIR)"
 848   endif
 849 
 850   ifneq ($$(JTREG_KEYWORDS), )
 851     # The keywords string may contain problematic characters and may be quoted
 852     # already when it arrives here. Remove any existing quotes and replace them
 853     # with one set of single quotes.
 854     $1_JTREG_KEYWORDS := \
 855         $$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS))))
 856     ifneq ($$($1_JTREG_KEYWORDS), )
 857       $1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)'
 858     endif
 859   endif
 860 
 861   ifneq ($$(JTREG_AOT_MODULES), )
 862     $$(eval $$(call SetupAot, $1, \
 863         MODULES := $$(JTREG_AOT_MODULES), \
 864         VM_OPTIONS := $$(JTREG_VM_OPTIONS) $$(JTREG_JAVA_OPTIONS), \
 865     ))
 866   endif
 867 
 868   ifneq ($$($1_AOT_OPTIONS), )
 869     $1_JTREG_BASIC_OPTIONS += -vmoptions:"$$($1_AOT_OPTIONS)"
 870   endif
 871 
 872   clean-workdir-$1:
 873         $$(RM) -r $$($1_TEST_SUPPORT_DIR)
 874 
 875   run-test-$1: clean-workdir-$1 $$($1_AOT_TARGETS)
 876         $$(call LogWarn)
 877         $$(call LogWarn, Running test '$$($1_TEST)')
 878         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 879         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
 880             $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
 881                 -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
 882                 $$($1_JTREG_BASIC_OPTIONS) \
 883                 -testjdk:$$(JDK_IMAGE_DIR) \
 884                 -dir:$$(JTREG_TOPDIR) \
 885                 -reportDir:$$($1_TEST_RESULTS_DIR) \
 886                 -workDir:$$($1_TEST_SUPPORT_DIR) \
 887                 $$(JTREG_OPTIONS) \
 888                 $$(JTREG_FAILURE_HANDLER_OPTIONS) \
 889                 $$($1_TEST_NAME) \
 890             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 891             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 892         )
 893 
 894   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
 895 
 896   parse-test-$1: run-test-$1
 897         $$(call LogWarn, Finished running test '$$($1_TEST)')
 898         $$(call LogWarn, Test report is stored in $$(strip \
 899             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 900         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 901           $$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
 902               for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
 903               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 904           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 905           $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 906               for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
 907               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 908           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 909           $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 910               for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
 911               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 912           $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
 913           $$(eval $1_TOTAL := $$(shell \
 914               $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR))) \
 915         , \
 916           $$(eval $1_PASSED := 0) \
 917           $$(eval $1_FAILED := 0) \
 918           $$(eval $1_ERROR := 1) \
 919           $$(eval $1_TOTAL := 1) \
 920         )
 921 
 922   $1: run-test-$1 parse-test-$1
 923 
 924   TARGETS += $1
 925 endef
 926 
 927 ################################################################################
 928 
 929 ### Rules for special tests
 930 
 931 SetupRunSpecialTest = $(NamedParamsMacroTemplate)
 932 define SetupRunSpecialTestBody
 933   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 934   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 935   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 936 
 937   $1_FULL_TEST_NAME := $$(strip $$(patsubst special:%, %, $$($1_TEST)))
 938   ifneq ($$(findstring :, $$($1_FULL_TEST_NAME)), )
 939     $1_TEST_NAME := $$(firstword $$(subst :, ,$$($1_FULL_TEST_NAME)))
 940     $1_TEST_ARGS := $$(strip $$(patsubst special:$$($1_TEST_NAME):%, %, $$($1_TEST)))
 941   else
 942     $1_TEST_NAME := $$($1_FULL_TEST_NAME)
 943     $1_TEST_ARGS :=
 944   endif
 945 
 946   ifeq ($$($1_TEST_NAME), failure-handler)
 947     ifeq ($(BUILD_FAILURE_HANDLER), true)
 948       $1_TEST_COMMAND_LINE := \
 949           ($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f \
 950           BuildFailureHandler.gmk test)
 951     else
 952       $$(error Cannot test failure handler if it is not built)
 953     endif
 954   else ifeq ($$($1_TEST_NAME), make)
 955     $1_TEST_COMMAND_LINE := \
 956         ($(CD) $(TOPDIR)/test/make && $(MAKE) $(MAKE_ARGS) -f \
 957         TestMake.gmk $$($1_TEST_ARGS))
 958   else
 959     $$(error Invalid special test specification: $$($1_TEST_NAME))
 960   endif
 961 
 962   run-test-$1: $(TEST_PREREQS)
 963         $$(call LogWarn)
 964         $$(call LogWarn, Running test '$$($1_TEST)')
 965         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 966         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/test-execution, \
 967             $$($1_TEST_COMMAND_LINE) \
 968                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/test-output.txt) \
 969             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 970             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 971         )
 972 
 973   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 974 
 975   # We can not parse the various "special" tests.
 976   parse-test-$1: run-test-$1
 977         $$(call LogWarn, Finished running test '$$($1_TEST)')
 978         $$(call LogWarn, Test report is stored in $$(strip \
 979             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 980         $$(call LogWarn, Warning: Special test results are not properly parsed!)
 981         $$(eval $1_PASSED := 0)
 982         $$(eval $1_FAILED := 0)
 983         $$(eval $1_ERROR := 0)
 984         $$(eval $1_TOTAL := 0)
 985 
 986   $1: run-test-$1 parse-test-$1
 987 
 988   TARGETS += $1
 989 endef
 990 
 991 ################################################################################
 992 # Setup and execute make rules for all selected tests
 993 ################################################################################
 994 
 995 # Helper function to determine which handler to use for the given test
 996 UseGtestTestHandler = \
 997   $(if $(filter gtest:%, $1), true)
 998 
 999 UseMicroTestHandler = \
1000   $(if $(filter micro:%, $1), true)
1001 
1002 UseJtregTestHandler = \
1003   $(if $(filter jtreg:%, $1), true)
1004 
1005 UseSpecialTestHandler = \
1006   $(if $(filter special:%, $1), true)
1007 
1008 # Now process each test to run and setup a proper make rule
1009 $(foreach test, $(TESTS_TO_RUN), \
1010   $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1011       $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1012   $(eval ALL_TEST_IDS += $(TEST_ID)) \
1013   $(if $(call UseCustomTestHandler, $(test)), \
1014     $(eval $(call SetupRunCustomTest, $(TEST_ID), \
1015         TEST := $(test), \
1016     )) \
1017   ) \
1018   $(if $(call UseGtestTestHandler, $(test)), \
1019     $(eval $(call SetupRunGtestTest, $(TEST_ID), \
1020         TEST := $(test), \
1021     )) \
1022   ) \
1023   $(if $(call UseMicroTestHandler, $(test)), \
1024     $(eval $(call SetupRunMicroTest, $(TEST_ID), \
1025         TEST := $(test), \
1026     )) \
1027   ) \
1028   $(if $(call UseJtregTestHandler, $(test)), \
1029     $(eval $(call SetupRunJtregTest, $(TEST_ID), \
1030         TEST := $(test), \
1031     )) \
1032   ) \
1033   $(if $(call UseSpecialTestHandler, $(test)), \
1034     $(eval $(call SetupRunSpecialTest, $(TEST_ID), \
1035         TEST := $(test), \
1036     )) \
1037   ) \
1038 )
1039 
1040 # Sort also removes duplicates, so if there is any we'll get fewer words.
1041 ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
1042   $(error Duplicate test specification)
1043 endif
1044 
1045 
1046 ################################################################################
1047 # The main target for RunTests.gmk
1048 ################################################################################
1049 
1050 # The SetupRun*Test functions have populated TARGETS.
1051 
1052 TEST_FAILURE := false
1053 
1054 run-test: $(TARGETS)
1055         # Create and print a table of the result of all tests run
1056         $(RM) $(TEST_SUMMARY).old 2> /dev/null
1057         $(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
1058         $(RM) $(TEST_LAST_IDS).old 2> /dev/null
1059         $(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
1060         $(ECHO) >> $(TEST_SUMMARY) ==============================
1061         $(ECHO) >> $(TEST_SUMMARY) Test summary
1062         $(ECHO) >> $(TEST_SUMMARY) ==============================
1063         $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5s %5s %5s %5s %2s\n" "  " \
1064             TEST TOTAL PASS FAIL ERROR " "
1065         $(foreach test, $(TESTS_TO_RUN), \
1066           $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1067               $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1068             $(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
1069           $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '[_*1000]')) \
1070           $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
1071             $(eval TEST_NAME := ) \
1072             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" "  " "$(test)"  $(NEWLINE) \
1073           , \
1074             $(eval TEST_NAME := $(test)) \
1075           ) \
1076           $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
1077             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1078                 "  " "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1079                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
1080           , \
1081             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1082                  ">>" "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1083                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
1084             $(eval TEST_FAILURE := true) \
1085           ) \
1086         )
1087         $(ECHO) >> $(TEST_SUMMARY) ==============================
1088         $(if $(filter true, $(TEST_FAILURE)), \
1089           $(ECHO) >> $(TEST_SUMMARY) TEST FAILURE $(NEWLINE) \
1090           $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR) $(NEWLINE) \
1091           $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
1092         , \
1093           $(ECHO) >> $(TEST_SUMMARY) TEST SUCCESS \
1094         )
1095         $(ECHO)
1096         $(CAT) $(TEST_SUMMARY)
1097         $(ECHO)
1098 
1099 ################################################################################
1100 
1101 all: run-test
1102 
1103 .PHONY: default all run-test $(TARGETS)