1 #
   2 # Copyright (c) 2016, 2020, 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 JCOV JCOV_DIFF_CHANGESET, \
  49     STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS AOT_MODULES, \
  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 ($(call isTargetOs, windows), true)
  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     $(call LogDebug, Rewriting _NT_SYMBOL_PATH to $(_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 # This is the JDK that we will test
  85 JDK_UNDER_TEST := $(JDK_IMAGE_DIR)
  86 
  87 TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
  88 TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
  89 TEST_SUMMARY := $(TEST_RESULTS_DIR)/test-summary.txt
  90 TEST_LAST_IDS := $(TEST_SUPPORT_DIR)/test-last-ids.txt
  91 
  92 ifeq ($(CUSTOM_ROOT), )
  93   JTREG_TOPDIR := $(TOPDIR)
  94 else
  95   JTREG_TOPDIR := $(CUSTOM_ROOT)
  96 endif
  97 
  98 JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler
  99 JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar
 100 
 101 JTREG_FAILURE_HANDLER_TIMEOUT ?= 0
 102 
 103 ifneq ($(wildcard $(JTREG_FAILURE_HANDLER)), )
 104   JTREG_FAILURE_HANDLER_OPTIONS := \
 105       -timeoutHandlerDir:$(JTREG_FAILURE_HANDLER) \
 106       -observerDir:$(JTREG_FAILURE_HANDLER) \
 107       -timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler \
 108       -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \
 109       -timeoutHandlerTimeout:$(JTREG_FAILURE_HANDLER_TIMEOUT)
 110 endif
 111 
 112 GTEST_LAUNCHER_DIRS := $(patsubst %/gtestLauncher, %, \
 113     $(wildcard $(TEST_IMAGE_DIR)/hotspot/gtest/*/gtestLauncher))
 114 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, \
 115     $(GTEST_LAUNCHER_DIRS)))
 116 
 117 COV_ENVIRONMENT :=
 118 JTREG_COV_OPTIONS :=
 119 
 120 ifeq ($(TEST_OPTS_JCOV), true)
 121   JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
 122   JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log
 123   JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml
 124   JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report
 125   JCOV_MEM_OPTIONS := -Xms64m -Xmx4g
 126 
 127   # Replace our normal test JDK with the JCov image.
 128   JDK_UNDER_TEST := $(JCOV_IMAGE_DIR)
 129 
 130   COV_ENVIRONMENT += JAVA_TOOL_OPTIONS="$(JCOV_MEM_OPTIONS)" \
 131       _JAVA_OPTIONS="$(JCOV_MEM_OPTIONS)"
 132   JTREG_COV_OPTIONS += -e:JAVA_TOOL_OPTIONS='$(JCOV_MEM_OPTIONS)' \
 133       -e:_JAVA_OPTIONS='$(JCOV_MEM_OPTIONS)'
 134 endif
 135 
 136 ifeq ($(GCOV_ENABLED), true)
 137   GCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/gcov-output
 138   COV_ENVIRONMENT += GCOV_PREFIX="$(GCOV_OUTPUT_DIR)"
 139   JTREG_COV_OPTIONS += -e:GCOV_PREFIX="$(GCOV_OUTPUT_DIR)"
 140 endif
 141 
 142 ################################################################################
 143 # Optionally create AOT libraries for specified modules before running tests.
 144 # Note, this could not be done during JDK build time.
 145 ################################################################################
 146 
 147 # Note, this could not be done during JDK build time.
 148 
 149 # Parameter 1 is the name of the rule.
 150 #
 151 # Remaining parameters are named arguments.
 152 #   MODULE      The module to generate a library for
 153 #   BIN         Output directory in which to put the library
 154 #   VM_OPTIONS  List of JVM arguments to use when creating library
 155 #   OPTIONS_VAR Name of variable to put AOT java options in
 156 #   PREREQS_VAR Name of variable to put all AOT prerequisite rule targets in
 157 #               for test rules to depend on
 158 #
 159 SetupAotModule = $(NamedParamsMacroTemplate)
 160 define SetupAotModuleBody
 161   $1_AOT_LIB := $$($1_BIN)/$$(call SHARED_LIBRARY,$$($1_MODULE))
 162   $1_AOT_CCLIST := $$(wildcard $$(TOPDIR)/test/hotspot/jtreg/compiler/aot/scripts/$$($1_MODULE)-list.txt)
 163 
 164   # Create jaotc flags.
 165   # VM flags which don't affect AOT code generation are filtered out:
 166   # -Xcomp, -XX:+-TieredCompilation
 167   $1_JAOTC_OPTS := \
 168       -J-Xmx4g --info \
 169       $$(addprefix -J, $$(filter-out -Xcomp %TieredCompilation, $$($1_VM_OPTIONS))) \
 170       $$(addprefix --compile-commands$(SPACE), $$($1_AOT_CCLIST)) \
 171       --linker-path $$(LD_JAOTC) \
 172       #
 173 
 174   ifneq ($$(filter -ea, $$($1_VM_OPTIONS)), )
 175     $1_JAOTC_OPTS += --compile-with-assertions
 176   endif
 177 
 178   $$($1_AOT_LIB): $$(JDK_UNDER_TEST)/release \
 179       $$(call DependOnVariable, $1_JAOTC_OPTS) \
 180       $$(call DependOnVariable, JDK_UNDER_TEST)
 181         $$(call LogWarn, Generating $$(patsubst $$(OUTPUTDIR)/%, %, $$@))
 182         $$(call MakeTargetDir)
 183         $$(call ExecuteWithLog, $$@, \
 184             $((COV_ENVIRONMENT) \
 185             $$(FIXPATH) $$(JDK_UNDER_TEST)/bin/jaotc \
 186                 $$($1_JAOTC_OPTS) --output $$@ --module $$($1_MODULE) \
 187         )
 188         $$(call ExecuteWithLog, $$@.check, ( \
 189             $$(FIXPATH) $$(JDK_UNDER_TEST)/bin/java \
 190                 $$($1_VM_OPTIONS) -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions \
 191                 -XX:+PrintAOT -XX:+UseAOTStrictLoading \
 192                 -XX:AOTLibrary=$$@ -version \
 193                  > $$@.verify-aot \
 194         ))
 195 
 196   $1_AOT_OPTIONS += -XX:+UnlockExperimentalVMOptions
 197   $1_AOT_OPTIONS += -XX:AOTLibrary=$$($1_AOT_LIB)
 198   $1_AOT_TARGETS += $$($1_AOT_LIB)
 199 endef
 200 
 201 # Parameter 1 is the name of the rule.
 202 #
 203 # Remaining parameters are named arguments.
 204 #   MODULES     The modules to generate a library for
 205 #   VM_OPTIONS  List of JVM arguments to use when creating libraries
 206 #
 207 # After calling this, the following variables are defined
 208 #   $1_AOT_OPTIONS List of all java options needed to use the AOT libraries
 209 #   $1_AOT_TARGETS List of all targets that the test rule will need to depend on
 210 #
 211 SetupAot = $(NamedParamsMacroTemplate)
 212 define SetupAotBody
 213   $$(info Running with AOTd libraries for $$($1_MODULES))
 214   # Put aot libraries in a separate directory so they are not deleted between
 215   # test runs and may be reused between make invocations.
 216   $$(foreach m, $$($1_MODULES), \
 217     $$(eval $$(call SetupAotModule, $1_$$m, \
 218         MODULE := $$m, \
 219         BIN := $$(TEST_SUPPORT_DIR)/aot/$1, \
 220         VM_OPTIONS := $$($1_VM_OPTIONS), \
 221     )) \
 222     $$(eval $1_AOT_OPTIONS += $$($1_$$m_AOT_OPTIONS)) \
 223     $$(eval $1_AOT_TARGETS += $$($1_$$m_AOT_TARGETS)) \
 224   )
 225 endef
 226 
 227 ################################################################################
 228 # Setup global test running parameters
 229 ################################################################################
 230 
 231 # Each factor variable comes in 3 variants. The first one is reserved for users
 232 # to use on command line. The other two are for predifined configurations in JDL
 233 # and for machine specific configurations respectively.
 234 TEST_JOBS_FACTOR ?= 1
 235 TEST_JOBS_FACTOR_JDL ?= 1
 236 TEST_JOBS_FACTOR_MACHINE ?= 1
 237 
 238 ifeq ($(TEST_JOBS), 0)
 239   CORES_DIVIDER := 2
 240   # For some big multi-core machines with low ulimit -u setting we hit the max
 241   # threads/process limit. In such a setup the memory/cores-only-guided
 242   # TEST_JOBS config is insufficient. From experience a concurrency setting of
 243   # 14 works reasonably well for low ulimit values (<= 4096). Thus, use
 244   # divider 4096/14. For high ulimit -u values this shouldn't make a difference.
 245   ULIMIT_DIVIDER := (4096/14)
 246   PROC_ULIMIT := -1
 247   ifneq ($(OPENJDK_TARGET_OS), windows)
 248     PROC_ULIMIT := $(shell $(ULIMIT) -u)
 249     ifeq ($(PROC_ULIMIT), unlimited)
 250       PROC_ULIMIT := -1
 251     endif
 252   endif
 253   MEMORY_DIVIDER := 2048
 254   TEST_JOBS := $(shell $(AWK) \
 255     'BEGIN { \
 256       c = $(NUM_CORES) / $(CORES_DIVIDER); \
 257       m = $(MEMORY_SIZE) / $(MEMORY_DIVIDER); \
 258       u = $(PROC_ULIMIT); \
 259       if (u > -1) { \
 260         u = u / $(ULIMIT_DIVIDER); \
 261         if (u < c) c = u; \
 262       } \
 263       if (c > m) c = m; \
 264       c = c * $(TEST_JOBS_FACTOR); \
 265       c = c * $(TEST_JOBS_FACTOR_JDL); \
 266       c = c * $(TEST_JOBS_FACTOR_MACHINE); \
 267       if (c < 1) c = 1; \
 268       printf "%.0f", c; \
 269     }')
 270 endif
 271 
 272 ################################################################################
 273 # Parse control variables
 274 ################################################################################
 275 
 276 ifneq ($(TEST_OPTS), )
 277   # Inform the user
 278   $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
 279 endif
 280 
 281 ### Jtreg
 282 
 283 $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
 284 $(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
 285 $(eval $(call SetTestOpt,AOT_MODULES,JTREG))
 286 
 287 $(eval $(call SetTestOpt,JOBS,JTREG))
 288 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
 289 $(eval $(call SetTestOpt,FAILURE_HANDLER_TIMEOUT,JTREG))
 290 
 291 $(eval $(call ParseKeywordVariable, JTREG, \
 292     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \
 293         TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM RUN_PROBLEM_LISTS \
 294         RETRY_COUNT, \
 295     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \
 296         EXTRA_PROBLEM_LISTS AOT_MODULES, \
 297 ))
 298 
 299 ifneq ($(JTREG), )
 300   # Inform the user
 301   $(info Running tests using JTREG control variable '$(JTREG)')
 302 endif
 303 
 304 ### Gtest
 305 
 306 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
 307 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
 308 $(eval $(call SetTestOpt,AOT_MODULES,GTEST))
 309 
 310 $(eval $(call ParseKeywordVariable, GTEST, \
 311     SINGLE_KEYWORDS := REPEAT, \
 312     STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS AOT_MODULES, \
 313 ))
 314 
 315 ifneq ($(GTEST), )
 316   # Inform the user
 317   $(info Running tests using GTEST control variable '$(GTEST)')
 318 endif
 319 
 320 ### Microbenchmarks
 321 
 322 $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
 323 $(eval $(call SetTestOpt,JAVA_OPTIONS,MICRO))
 324 
 325 $(eval $(call ParseKeywordVariable, MICRO, \
 326     SINGLE_KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
 327     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS RESULTS_FORMAT TEST_JDK \
 328         BENCHMARKS_JAR, \
 329 ))
 330 
 331 ifneq ($(MICRO), )
 332   # Inform the user
 333   $(info Running tests using MICRO control variable '$(MICRO)')
 334 endif
 335 
 336 
 337 ################################################################################
 338 # Component-specific Jtreg settings
 339 ################################################################################
 340 
 341 hotspot_JTREG_MAX_MEM := 0
 342 hotspot_JTREG_ASSERT := false
 343 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
 344 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
 345 
 346 jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
 347 jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
 348 langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
 349 hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
 350 
 351 langtools_JTREG_MAX_MEM := 768m
 352 
 353 ################################################################################
 354 # Parse test selection
 355 #
 356 # The user has given a test selection in the TEST variable. We must parse it
 357 # and determine what that means in terms of actual calls to the test framework.
 358 #
 359 # The parse functions take as argument a test specification as given by the
 360 # user, and returns a fully qualified test descriptor if it was a match, or
 361 # nothing if not. A single test specification can result in multiple test
 362 # descriptors being returned. A valid test descriptor must always be accepted
 363 # and returned identically.
 364 ################################################################################
 365 
 366 # Helper function to determine if a test specification is a Gtest test
 367 #
 368 # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
 369 # test filter string, and an optional "/<variant>" to select a specific JVM
 370 # variant. If no variant is specified, all found variants are tested.
 371 define ParseGtestTestSelection
 372   $(if $(filter gtest%, $1), \
 373     $(if $(filter gtest, $1), \
 374       $(addprefix gtest:all/, $(GTEST_VARIANTS)) \
 375     , \
 376       $(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
 377         $(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
 378       , \
 379         $(if $(filter gtest:%, $1), \
 380           $(if $(findstring /, $1), \
 381             $1 \
 382           , \
 383             $(addprefix $1/, $(GTEST_VARIANTS)) \
 384           ) \
 385         ) \
 386       ) \
 387     ) \
 388   )
 389 endef
 390 
 391 # Helper function to determine if a test specification is a microbenchmark test
 392 #
 393 # It is a microbenchmark test if it is either "micro", or "micro:" followed by
 394 # an optional test filter string.
 395 define ParseMicroTestSelection
 396   $(if $(filter micro%, $1), \
 397     $(if $(filter micro, $1), \
 398       micro:all \
 399     , \
 400       $(if $(filter micro:, $1), \
 401         micro:all \
 402       , \
 403         $1 \
 404       ) \
 405     ) \
 406   )
 407 endef
 408 
 409 # Helper function that removes the TOPDIR part
 410 CleanupJtregPath = \
 411   $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
 412 
 413 # Take a partial Jtreg root path and return a full, absolute path to that Jtreg
 414 # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
 415 ExpandJtregRoot = \
 416   $(call CleanupJtregPath, $(wildcard \
 417     $(if $(filter /%, $1), \
 418       $(if $(wildcard $(strip $1)/TEST.ROOT), \
 419         $1 \
 420       ) \
 421     , \
 422       $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 423       $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 424     ) \
 425   ))
 426 
 427 # Take a partial Jtreg test path and return a full, absolute path to that Jtreg
 428 # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
 429 ExpandJtregPath = \
 430   $(if $(call ExpandJtregRoot, $1), \
 431     $(call ExpandJtregRoot, $1) \
 432   , \
 433     $(call CleanupJtregPath, $(wildcard \
 434       $(if $(filter /%, $1), \
 435         $1 \
 436       , \
 437         $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 438         $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 439       ) \
 440     )) \
 441   )
 442 
 443 # Helper function to determine if a test specification is a Jtreg test
 444 #
 445 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
 446 # an unspecified group name (possibly prefixed by :), or a group in a
 447 # specified test root, or a path to a test or test directory,
 448 # either absolute or relative to any of the TEST_BASEDIRS or test roots.
 449 define ParseJtregTestSelection
 450   $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
 451   $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
 452     $(eval TEST_NAME := :$(TEST_NAME)) \
 453   ) \
 454   $(if $(findstring :, $(TEST_NAME)), \
 455     $(if $(filter :%, $(TEST_NAME)), \
 456       $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
 457       $(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
 458           $(call CleanupJtregPath, $(test_root)))) \
 459     , \
 460       $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
 461       $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
 462       $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
 463     ) \
 464     $(foreach test_root, $(TEST_ROOTS), \
 465       $(if $(filter /%, $(test_root)), \
 466         jtreg:$(test_root):$(TEST_GROUP) \
 467       , \
 468         $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
 469           jtreg:$(test_root):$(TEST_GROUP) \
 470         ) \
 471       ) \
 472     ) \
 473   , \
 474     $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
 475     $(foreach test_path, $(TEST_PATHS), \
 476       jtreg:$(test_path) \
 477     ) \
 478   )
 479 endef
 480 
 481 # Helper function to determine if a test specification is a special test
 482 #
 483 # It is a special test if it is "special:" followed by a test name,
 484 # if it is "make:" or "make-" followed by a make test, or any of the special
 485 # test names as a single word.
 486 define ParseSpecialTestSelection
 487   $(if $(filter special:%, $1), \
 488     $1 \
 489   ) \
 490   $(if $(filter make%, $1), \
 491     $(if $(filter make:%, $1), \
 492       special:$(strip $1) \
 493     ) \
 494     $(if $(filter make-%, $1), \
 495       special:$(patsubst make-%,make:%, $1) \
 496     ) \
 497     $(if $(filter make, $1), \
 498       special:make:all \
 499     )
 500   ) \
 501   $(if $(filter failure-handler, $1), \
 502     special:$(strip $1) \
 503   )
 504 endef
 505 
 506 ifeq ($(TEST), )
 507   $(info No test selection given in TEST!)
 508   $(info Please use e.g. 'make test TEST=tier1' or 'make test-tier1')
 509   $(info See doc/testing.[md|html] for help)
 510   $(error Cannot continue)
 511 endif
 512 
 513 # Now intelligently convert the test selection given by the user in TEST
 514 # into a list of fully qualified test descriptors of the tests to run.
 515 TESTS_TO_RUN :=
 516 $(foreach test, $(TEST), \
 517   $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
 518   $(if $(strip $(PARSED_TESTS)), , \
 519     $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
 520   ) \
 521   $(if $(strip $(PARSED_TESTS)), , \
 522     $(eval PARSED_TESTS += $(call ParseMicroTestSelection, $(test))) \
 523   ) \
 524   $(if $(strip $(PARSED_TESTS)), , \
 525     $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
 526   ) \
 527   $(if $(strip $(PARSED_TESTS)), , \
 528     $(eval PARSED_TESTS += $(call ParseSpecialTestSelection, $(test))) \
 529   ) \
 530   $(if $(strip $(PARSED_TESTS)), , \
 531     $(eval UNKNOWN_TEST := $(test)) \
 532   ) \
 533   $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
 534 )
 535 
 536 ifneq ($(UNKNOWN_TEST), )
 537   $(info Unknown test selection: '$(UNKNOWN_TEST)')
 538   $(info See doc/testing.[md|html] for help)
 539   $(error Cannot continue)
 540 endif
 541 
 542 TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
 543 
 544 
 545 # Present the result of our parsing to the user
 546 $(info Test selection '$(TEST)', will run:)
 547 $(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
 548 
 549 
 550 ################################################################################
 551 # Functions for setting up rules for running the selected tests
 552 #
 553 # The SetupRun*Test functions all have the same interface:
 554 #
 555 # Parameter 1 is the name of the rule. This is the test id, based on the test
 556 # descriptor, and this is also used as variable prefix, and the targets
 557 # generated are listed in a variable by that name.
 558 #
 559 # Remaining parameters are named arguments. Currently this is only:
 560 #   TEST -- The properly formatted fully qualified test descriptor
 561 #
 562 # After the rule named by the test id has been executed, the following
 563 # variables will be available:
 564 # testid_TOTAL - the total number of tests run
 565 # testid_PASSED - the number of successful tests
 566 # testid_FAILED - the number of failed tests
 567 # testid_ERROR - the number of tests was neither successful or failed
 568 #
 569 ################################################################################
 570 
 571 ### Rules for Gtest
 572 
 573 SetupRunGtestTest = $(NamedParamsMacroTemplate)
 574 define SetupRunGtestTestBody
 575   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 576   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 577   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 578 
 579   $1_VARIANT :=  $$(lastword $$(subst /, , $$($1_TEST)))
 580   ifeq ($$(filter $$($1_VARIANT), $$(GTEST_VARIANTS)), )
 581     $$(error Invalid gtest variant '$$($1_VARIANT)'. Valid variants: $$(GTEST_VARIANTS))
 582   endif
 583   $1_TEST_NAME := $$(strip $$(patsubst %/$$($1_VARIANT), %, \
 584       $$(patsubst gtest:%, %, $$($1_TEST))))
 585   ifneq ($$($1_TEST_NAME), all)
 586     $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
 587   endif
 588 
 589   ifneq ($$(GTEST_REPEAT), )
 590     $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
 591   endif
 592 
 593   ifneq ($$(GTEST_AOT_MODULES), )
 594     $$(eval $$(call SetupAot, $1, \
 595         MODULES := $$(GTEST_AOT_MODULES), \
 596         VM_OPTIONS := $$(GTEST_VM_OPTIONS) $$(GTEST_JAVA_OPTIONS), \
 597     ))
 598   endif
 599 
 600   run-test-$1: pre-run-test $$($1_AOT_TARGETS)
 601         $$(call LogWarn)
 602         $$(call LogWarn, Running test '$$($1_TEST)')
 603         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 604         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, ( \
 605             $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \
 606                 -jdk $(JDK_UNDER_TEST) $$($1_GTEST_FILTER) \
 607                 --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
 608                 $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
 609                 $$(GTEST_JAVA_OPTIONS) $$($1_AOT_OPTIONS) \
 610                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
 611             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 612             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 613         ))
 614 
 615   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 616 
 617   parse-test-$1: run-test-$1
 618         $$(call LogWarn, Finished running test '$$($1_TEST)')
 619         $$(call LogWarn, Test report is stored in $$(strip \
 620             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 621         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 622           $$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
 623               test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE))) \
 624           $$(if $$($1_TOTAL), , $$(eval $1_TOTAL := 0)) \
 625           $$(eval $1_PASSED := $$(shell $$(AWK) '/\[  PASSED  \] .* tests?./ \
 626               { print $$$$4 }' $$($1_RESULT_FILE))) \
 627           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 628           $$(eval $1_FAILED := $$(shell $$(AWK) '/\[  FAILED  \] .* tests?, \
 629               listed below/ { print $$$$4 }' $$($1_RESULT_FILE))) \
 630           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 631           $$(eval $1_ERROR := $$(shell \
 632               $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED))) \
 633         , \
 634           $$(eval $1_PASSED := 0) \
 635           $$(eval $1_FAILED := 0) \
 636           $$(eval $1_ERROR := 1) \
 637           $$(eval $1_TOTAL := 1) \
 638         )
 639 
 640   $1: run-test-$1 parse-test-$1
 641 
 642   TARGETS += $1 run-test-$1 parse-test-$1
 643   TEST_TARGETS += parse-test-$1
 644 
 645 endef
 646 
 647 ################################################################################
 648 
 649 ### Rules for Microbenchmarks
 650 
 651 # Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
 652 # 1) Specified by user on command line
 653 # 2) Generic default
 654 #
 655 # Note: No spaces are allowed around the arguments.
 656 # Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
 657 # Arg $2 Base variable, e.g. MICRO_TEST_JDK
 658 # Arg $3 The default value (optional)
 659 define SetMicroValue
 660   ifneq ($$($2), )
 661     $1_$2 := $$($2)
 662   else
 663     ifneq ($3, )
 664       $1_$2 := $3
 665     endif
 666   endif
 667 endef
 668 
 669 SetupRunMicroTest = $(NamedParamsMacroTemplate)
 670 define SetupRunMicroTestBody
 671   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 672   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 673   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 674 
 675   $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
 676 
 677   $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/benchmarks.jar))
 678   $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_UNDER_TEST)))
 679   $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
 680 
 681   # Current tests needs to open java.io
 682   $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
 683   # Set library path for native dependencies
 684   $1_MICRO_JAVA_OPTIONS += -Djava.library.path=$$(TEST_IMAGE_DIR)/micro/native
 685 
 686   # Save output as JSON or CSV file
 687   ifneq ($$(MICRO_RESULTS_FORMAT), )
 688     $1_MICRO_BASIC_OPTIONS += -rf $$(MICRO_RESULTS_FORMAT)
 689     $1_MICRO_BASIC_OPTIONS += -rff $$($1_TEST_RESULTS_DIR)/jmh-result.$(MICRO_RESULTS_FORMAT)
 690   endif
 691 
 692   ifneq ($$(MICRO_VM_OPTIONS)$$(MICRO_JAVA_OPTIONS), )
 693     JMH_JVM_ARGS := $$(MICRO_VM_OPTIONS) $$(MICRO_JAVA_OPTIONS)
 694     $1_MICRO_VM_OPTIONS := -jvmArgs $(call ShellQuote,$$(JMH_JVM_ARGS))
 695   endif
 696 
 697   ifneq ($$(MICRO_ITER), )
 698     $1_MICRO_ITER := -i $$(MICRO_ITER)
 699   endif
 700   ifneq ($$(MICRO_FORK), )
 701     $1_MICRO_FORK := -f $$(MICRO_FORK)
 702   endif
 703   ifneq ($$(MICRO_TIME), )
 704     $1_MICRO_TIME := -r $$(MICRO_TIME)
 705   endif
 706   ifneq ($$(MICRO_WARMUP_ITER), )
 707     $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
 708   endif
 709   ifneq ($$(MICRO_WARMUP_TIME), )
 710     $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
 711   endif
 712 
 713   run-test-$1: pre-run-test
 714         $$(call LogWarn)
 715         $$(call LogWarn, Running test '$$($1_TEST)')
 716         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 717         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, ( \
 718             $$(FIXPATH) $$($1_MICRO_TEST_JDK)/bin/java $$($1_MICRO_JAVA_OPTIONS) \
 719                 -jar $$($1_MICRO_BENCHMARKS_JAR) \
 720                 $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
 721                 $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
 722                 $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS) \
 723                 $$($1_TEST_NAME) \
 724                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
 725             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 726             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 727         ))
 728 
 729   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
 730 
 731   parse-test-$1: run-test-$1
 732         $$(call LogWarn, Finished running test '$$($1_TEST)')
 733         $$(call LogWarn, Test report is stored in $$(strip \
 734             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 735         $$(if $$(wildcard $$($1_EXITCODE)), \
 736           $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
 737           $$(if $$(filter 0, $$($1_EXIT_CODE)), \
 738             $$(eval $1_PASSED := 1) \
 739             $$(eval $1_ERROR := 0) \
 740           , \
 741             $$(eval $1_PASSED := 0) \
 742             $$(eval $1_ERROR := 1) \
 743           ) \
 744           $$(eval $1_FAILED := 0) \
 745           $$(eval $1_TOTAL := $$(shell \
 746               $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
 747         , \
 748           $$(eval $1_PASSED := 0) \
 749           $$(eval $1_FAILED := 0) \
 750           $$(eval $1_ERROR := 1) \
 751           $$(eval $1_TOTAL := 1) \
 752         )
 753 
 754   $1: run-test-$1 parse-test-$1
 755 
 756   TARGETS += $1 run-test-$1 parse-test-$1
 757   TEST_TARGETS += parse-test-$1
 758 
 759 endef
 760 
 761 ################################################################################
 762 
 763 ### Rules for Jtreg
 764 
 765 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
 766 # 1) Specified by user on command line
 767 # 2) Component-specific default
 768 # 3) Generic default
 769 #
 770 # Note: No spaces are allowed around the arguments.
 771 # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
 772 # Arg $2 Base variable, e.g. JTREG_JOBS
 773 # Arg $3 The default value (optional)
 774 define SetJtregValue
 775   ifneq ($$($2), )
 776     $1_$2 := $$($2)
 777   else
 778     ifneq ($$($$($1_COMPONENT)_$2), )
 779       $1_$2 := $$($$($1_COMPONENT)_$2)
 780     else
 781       ifneq ($3, )
 782         $1_$2 := $3
 783       endif
 784     endif
 785   endif
 786 endef
 787 
 788 SetupRunJtregTest = $(NamedParamsMacroTemplate)
 789 define SetupRunJtregTestBody
 790   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 791   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 792   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 793 
 794   $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
 795 
 796   $1_TEST_ROOT := \
 797       $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
 798         $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), $$(root)) \
 799       ))
 800   $1_COMPONENT := $$(lastword $$(subst /, $$(SPACE), $$($1_TEST_ROOT)))
 801   # This will work only as long as just hotspot has the additional "jtreg" directory
 802   ifeq ($$($1_COMPONENT), jtreg)
 803     $1_COMPONENT := hotspot
 804   endif
 805 
 806   ifeq ($$(JT_HOME), )
 807     $$(info Error: jtreg framework is not found.)
 808     $$(info Please run configure using --with-jtreg.)
 809     $$(error Cannot continue)
 810   endif
 811 
 812   # Unfortunately, we need different defaults for some JTREG values,
 813   # depending on what component we're running.
 814 
 815   # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
 816   $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
 817   $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
 818   $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
 819   $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
 820   $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
 821   $$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
 822 
 823   # Only the problem list for the current test root should be used.
 824   $1_JTREG_PROBLEM_LIST := $$(filter $$($1_TEST_ROOT)%, $$($1_JTREG_PROBLEM_LIST))
 825 
 826   ifneq ($(TEST_JOBS), 0)
 827     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
 828   else
 829     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
 830   endif
 831 
 832   # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
 833   # we may end up with a lot of JVM's
 834   $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $$(EXPR) 25 / $$($1_JTREG_JOBS))
 835 
 836   JTREG_TIMEOUT_FACTOR ?= 4
 837 
 838   JTREG_VERBOSE ?= fail,error,summary
 839   JTREG_RETAIN ?= fail,error
 840   JTREG_RUN_PROBLEM_LISTS ?= false
 841   JTREG_RETRY_COUNT ?= 0
 842 
 843   ifneq ($$($1_JTREG_MAX_MEM), 0)
 844     $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
 845     $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
 846   endif
 847 
 848   $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
 849       -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
 850       -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR) \
 851       -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE)
 852 
 853   $1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet
 854 
 855   # Make it possible to specify the JIB_DATA_DIR for tests using the
 856   # JIB Artifact resolver
 857   $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
 858   # Some tests needs to find a boot JDK using the JDK8_HOME variable.
 859   $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
 860   # If running on Windows, propagate the _NT_SYMBOL_PATH to enable
 861   # symbol lookup in hserr files
 862   ifeq ($$(call isTargetOs, windows), true)
 863     $1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH
 864   endif
 865 
 866   $1_JTREG_BASIC_OPTIONS += \
 867       $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
 868       $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
 869       #
 870 
 871   ifeq ($$($1_JTREG_ASSERT), true)
 872     $1_JTREG_BASIC_OPTIONS += -ea -esa
 873   endif
 874 
 875   ifneq ($$($1_JTREG_NATIVEPATH), )
 876     $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
 877   endif
 878 
 879   ifeq ($$(JTREG_RUN_PROBLEM_LISTS), true)
 880     JTREG_PROBLEM_LIST_PREFIX := -match:
 881   else
 882     JTREG_PROBLEM_LIST_PREFIX := -exclude:
 883   endif
 884 
 885   ifneq ($$($1_JTREG_PROBLEM_LIST), )
 886     $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$($1_JTREG_PROBLEM_LIST))
 887   endif
 888 
 889   ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), )
 890     # Accept both absolute paths as well as relative to the current test root.
 891     $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
 892         $$(JTREG_EXTRA_PROBLEM_LISTS) \
 893         $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
 894     ))
 895   endif
 896 
 897   ifneq ($$(JIB_HOME), )
 898     $1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
 899   endif
 900 
 901   $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_DIR=$(TEST_IMAGE_DIR)
 902   $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=$(TEST_IMAGE_DIR)/hotspot/jtreg/graal
 903 
 904   ifneq ($$(JTREG_FAILURE_HANDLER_OPTIONS), )
 905     $1_JTREG_LAUNCHER_OPTIONS += -Djava.library.path="$(JTREG_FAILURE_HANDLER_DIR)"
 906   endif
 907 
 908   ifneq ($$(JTREG_KEYWORDS), )
 909     # The keywords string may contain problematic characters and may be quoted
 910     # already when it arrives here. Remove any existing quotes and replace them
 911     # with one set of single quotes.
 912     $1_JTREG_KEYWORDS := \
 913         $$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS))))
 914     ifneq ($$($1_JTREG_KEYWORDS), )
 915       $1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)'
 916     endif
 917   endif
 918 
 919   ifneq ($$(JTREG_AOT_MODULES), )
 920     $$(eval $$(call SetupAot, $1, \
 921         MODULES := $$(JTREG_AOT_MODULES), \
 922         VM_OPTIONS := $$(JTREG_VM_OPTIONS) $$(JTREG_JAVA_OPTIONS), \
 923     ))
 924   endif
 925 
 926   ifneq ($$($1_AOT_OPTIONS), )
 927     $1_JTREG_BASIC_OPTIONS += -vmoptions:"$$($1_AOT_OPTIONS)"
 928   endif
 929 
 930   clean-workdir-$1:
 931         $$(RM) -r $$($1_TEST_SUPPORT_DIR)
 932 
 933   $1_COMMAND_LINE := \
 934       $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
 935           -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
 936           $$($1_JTREG_BASIC_OPTIONS) \
 937           -testjdk:$$(JDK_UNDER_TEST) \
 938           -dir:$$(JTREG_TOPDIR) \
 939           -reportDir:$$($1_TEST_RESULTS_DIR) \
 940           -workDir:$$($1_TEST_SUPPORT_DIR) \
 941           -status:$$$${JTREG_STATUS} \
 942           $$(JTREG_OPTIONS) \
 943           $$(JTREG_FAILURE_HANDLER_OPTIONS) \
 944           $$(JTREG_COV_OPTIONS) \
 945           $$($1_TEST_NAME) \
 946       && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 947       || $$(ECHO) $$$$? > $$($1_EXITCODE)
 948 
 949 
 950   ifneq ($$(JTREG_RETRY_COUNT), 0)
 951     $1_COMMAND_LINE := \
 952         for i in {0..$$(JTREG_RETRY_COUNT)}; do \
 953           if [ "$$$$i" != 0 ]; then \
 954             $$(PRINTF) "\nRetrying Jtreg run. Attempt: $$$$i\n"; \
 955           fi; \
 956           $$($1_COMMAND_LINE); \
 957           if [ "`$$(CAT) $$($1_EXITCODE)`" = "0" ]; then \
 958             break; \
 959           fi; \
 960           export JTREG_STATUS="-status:error,fail"; \
 961         done
 962   endif
 963 
 964   run-test-$1: pre-run-test clean-workdir-$1 $$($1_AOT_TARGETS)
 965         $$(call LogWarn)
 966         $$(call LogWarn, Running test '$$($1_TEST)')
 967         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 968         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, ( \
 969             $$(COV_ENVIRONMENT) $$($1_COMMAND_LINE) \
 970         ))
 971 
 972   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
 973 
 974   parse-test-$1: run-test-$1
 975         $$(call LogWarn, Finished running test '$$($1_TEST)')
 976         $$(call LogWarn, Test report is stored in $$(strip \
 977             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 978         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 979           $$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
 980               for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
 981               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 982           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 983           $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 984               for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
 985               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 986           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 987           $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 988               for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
 989               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 990           $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
 991           $$(eval $1_TOTAL := $$(shell \
 992               $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR))) \
 993         , \
 994           $$(eval $1_PASSED := 0) \
 995           $$(eval $1_FAILED := 0) \
 996           $$(eval $1_ERROR := 1) \
 997           $$(eval $1_TOTAL := 1) \
 998         )
 999 
1000   $1: run-test-$1 parse-test-$1 clean-workdir-$1
1001 
1002   TARGETS += $1 run-test-$1 parse-test-$1 clean-workdir-$1
1003   TEST_TARGETS += parse-test-$1
1004 
1005 endef
1006 
1007 ################################################################################
1008 
1009 ### Rules for special tests
1010 
1011 SetupRunSpecialTest = $(NamedParamsMacroTemplate)
1012 define SetupRunSpecialTestBody
1013   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
1014   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
1015   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
1016 
1017   $1_FULL_TEST_NAME := $$(strip $$(patsubst special:%, %, $$($1_TEST)))
1018   ifneq ($$(findstring :, $$($1_FULL_TEST_NAME)), )
1019     $1_TEST_NAME := $$(firstword $$(subst :, ,$$($1_FULL_TEST_NAME)))
1020     $1_TEST_ARGS := $$(strip $$(patsubst special:$$($1_TEST_NAME):%, %, $$($1_TEST)))
1021   else
1022     $1_TEST_NAME := $$($1_FULL_TEST_NAME)
1023     $1_TEST_ARGS :=
1024   endif
1025 
1026   ifeq ($$($1_TEST_NAME), failure-handler)
1027     ifeq ($(BUILD_FAILURE_HANDLER), true)
1028       $1_TEST_COMMAND_LINE := \
1029           ($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f \
1030           BuildFailureHandler.gmk test)
1031     else
1032       $$(error Cannot test failure handler if it is not built)
1033     endif
1034   else ifeq ($$($1_TEST_NAME), make)
1035     $1_TEST_COMMAND_LINE := \
1036         ($(CD) $(TOPDIR)/test/make && $(MAKE) $(MAKE_ARGS) -f \
1037         TestMake.gmk $$($1_TEST_ARGS) TEST_SUPPORT_DIR="$$($1_TEST_SUPPORT_DIR)")
1038   else
1039     $$(error Invalid special test specification: $$($1_TEST_NAME))
1040   endif
1041 
1042   run-test-$1: pre-run-test
1043         $$(call LogWarn)
1044         $$(call LogWarn, Running test '$$($1_TEST)')
1045         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
1046         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/test-execution, ( \
1047             $$($1_TEST_COMMAND_LINE) \
1048                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/test-output.txt) \
1049             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
1050             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
1051         ))
1052 
1053   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
1054 
1055   # We can not parse the various "special" tests.
1056   parse-test-$1: run-test-$1
1057         $$(call LogWarn, Finished running test '$$($1_TEST)')
1058         $$(call LogWarn, Test report is stored in $$(strip \
1059             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
1060         $$(call LogWarn, Warning: Special test results are not properly parsed!)
1061         $$(eval $1_PASSED := $$(shell \
1062           if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 1; else $(ECHO) 0; fi \
1063         ))
1064         $$(eval $1_FAILED := $$(shell \
1065           if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 0; else $(ECHO) 1; fi \
1066         ))
1067         $$(eval $1_ERROR := 0)
1068         $$(eval $1_TOTAL := 1)
1069 
1070   $1: run-test-$1 parse-test-$1
1071 
1072   TARGETS += $1 run-test-$1 parse-test-$1
1073   TEST_TARGETS += parse-test-$1
1074 
1075 endef
1076 
1077 ################################################################################
1078 # Setup and execute make rules for all selected tests
1079 ################################################################################
1080 
1081 # Helper function to determine which handler to use for the given test
1082 UseGtestTestHandler = \
1083   $(if $(filter gtest:%, $1), true)
1084 
1085 UseMicroTestHandler = \
1086   $(if $(filter micro:%, $1), true)
1087 
1088 UseJtregTestHandler = \
1089   $(if $(filter jtreg:%, $1), true)
1090 
1091 UseSpecialTestHandler = \
1092   $(if $(filter special:%, $1), true)
1093 
1094 # Now process each test to run and setup a proper make rule
1095 $(foreach test, $(TESTS_TO_RUN), \
1096   $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1097       $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1098   $(eval ALL_TEST_IDS += $(TEST_ID)) \
1099   $(if $(call UseCustomTestHandler, $(test)), \
1100     $(eval $(call SetupRunCustomTest, $(TEST_ID), \
1101         TEST := $(test), \
1102     )) \
1103   ) \
1104   $(if $(call UseGtestTestHandler, $(test)), \
1105     $(eval $(call SetupRunGtestTest, $(TEST_ID), \
1106         TEST := $(test), \
1107     )) \
1108   ) \
1109   $(if $(call UseMicroTestHandler, $(test)), \
1110     $(eval $(call SetupRunMicroTest, $(TEST_ID), \
1111         TEST := $(test), \
1112     )) \
1113   ) \
1114   $(if $(call UseJtregTestHandler, $(test)), \
1115     $(eval $(call SetupRunJtregTest, $(TEST_ID), \
1116         TEST := $(test), \
1117     )) \
1118   ) \
1119   $(if $(call UseSpecialTestHandler, $(test)), \
1120     $(eval $(call SetupRunSpecialTest, $(TEST_ID), \
1121         TEST := $(test), \
1122     )) \
1123   ) \
1124 )
1125 
1126 # Sort also removes duplicates, so if there is any we'll get fewer words.
1127 ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
1128   $(error Duplicate test specification)
1129 endif
1130 
1131 
1132 ################################################################################
1133 # The main target for RunTests.gmk
1134 ################################################################################
1135 
1136 #
1137 # Provide hooks for adding functionality before and after all tests are run.
1138 #
1139 
1140 $(call LogInfo, RunTest setup starting)
1141 
1142 # This target depends on all actual test having been run (TEST_TARGETS has beeen
1143 # populated by the SetupRun*Test functions). If you need to provide a teardown
1144 # hook, you must let it depend on this target.
1145 run-all-tests: $(TEST_TARGETS)
1146         $(call LogInfo, RunTest teardown starting)
1147 
1148 # This is an abstract target that will be run before any actual tests. Add your
1149 # target as a dependency to thisif you need "setup" type functionality executed
1150 # before all tests.
1151 pre-run-test:
1152         $(call LogInfo, RunTest setup done)
1153 
1154 # This is an abstract target that will be run after all actual tests, but before
1155 # the test summary. If you need "teardown" type functionality, add your target
1156 # as a dependency on this, and let the teardown target depend on run-all-tests.
1157 post-run-test: run-all-tests
1158         $(call LogInfo, RunTest teardown done)
1159 
1160 #
1161 # Create and print a table of the result of all tests run
1162 #
1163 TEST_FAILURE := false
1164 
1165 run-test-report: post-run-test
1166         $(RM) $(TEST_SUMMARY).old 2> /dev/null
1167         $(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
1168         $(RM) $(TEST_LAST_IDS).old 2> /dev/null
1169         $(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
1170         $(ECHO) >> $(TEST_SUMMARY) ==============================
1171         $(ECHO) >> $(TEST_SUMMARY) Test summary
1172         $(ECHO) >> $(TEST_SUMMARY) ==============================
1173         $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5s %5s %5s %5s %2s\n" "  " \
1174             TEST TOTAL PASS FAIL ERROR " "
1175         $(foreach test, $(TESTS_TO_RUN), \
1176           $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1177               $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1178             $(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
1179           $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '[_*1000]')) \
1180           $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
1181             $(eval TEST_NAME := ) \
1182             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" "  " "$(test)"  $(NEWLINE) \
1183           , \
1184             $(eval TEST_NAME := $(test)) \
1185           ) \
1186           $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
1187             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1188                 "  " "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1189                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
1190           , \
1191             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1192                  ">>" "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1193                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
1194             $(eval TEST_FAILURE := true) \
1195           ) \
1196         )
1197         $(ECHO) >> $(TEST_SUMMARY) ==============================
1198         $(if $(filter true, $(TEST_FAILURE)), \
1199           $(ECHO) >> $(TEST_SUMMARY) TEST FAILURE $(NEWLINE) \
1200           $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR) $(NEWLINE) \
1201           $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
1202         , \
1203           $(ECHO) >> $(TEST_SUMMARY) TEST SUCCESS \
1204         )
1205         $(ECHO)
1206         $(CAT) $(TEST_SUMMARY)
1207         $(ECHO)
1208 
1209 # The main run-test target
1210 run-test: run-test-report
1211 
1212 TARGETS += run-all-tests pre-run-test post-run-test run-test-report run-test
1213 
1214 ################################################################################
1215 # Setup JCov
1216 ################################################################################
1217 
1218 ifeq ($(TEST_OPTS_JCOV), true)
1219 
1220   jcov-do-start-grabber:
1221         $(call MakeDir, $(JCOV_OUTPUT_DIR))
1222         if $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -status 1>/dev/null 2>&1 ; then \
1223           $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600 ; \
1224         fi
1225         $(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar Grabber -v -t \
1226             $(JCOV_IMAGE_DIR)/template.xml -o $(JCOV_RESULT_FILE) \
1227             1>$(JCOV_GRABBER_LOG) 2>&1 &
1228 
1229   jcov-start-grabber: jcov-do-start-grabber
1230         $(call LogWarn, Starting JCov Grabber...)
1231         $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -t 600 -wait
1232 
1233   jcov-stop-grabber:
1234         $(call LogWarn, Stopping JCov Grabber...)
1235         $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
1236 
1237   JCOV_REPORT_TITLE := JDK code coverage report<br/>
1238   ifneq ($(JCOV_FILTERS), )
1239     JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)<br>
1240   endif
1241   JCOV_REPORT_TITLE += Tests: $(TEST)
1242 
1243   jcov-gen-report: jcov-stop-grabber
1244         $(call LogWarn, Generating JCov report ...)
1245         $(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
1246             `$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
1247             $(JCOV_FILTERS) \
1248             -mainReportTitle "$(JCOV_REPORT_TITLE)" \
1249             -o $(JCOV_REPORT) $(JCOV_RESULT_FILE)
1250 
1251   TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
1252       jcov-gen-report
1253 
1254   ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1255 
1256     JCOV_SOURCE_DIFF := $(JCOV_OUTPUT_DIR)/source_diff
1257     JCOV_DIFF_COVERAGE_REPORT := $(JCOV_OUTPUT_DIR)/diff_coverage_report
1258 
1259     ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
1260       DIFF_COMMAND := $(HG) -R $(TOPDIR) diff -r $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1261     else ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
1262       DIFF_COMMAND := $(GIT) -C $(TOPDIR) diff $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1263     else
1264       $(info Error: Must be either hg or git source tree for diff coverage.)
1265       $(error Neither hg nor git source tree.)
1266     endif
1267 
1268     jcov-gen-diffcoverage: jcov-stop-grabber
1269         $(call LogWarn, Generating diff coverage with changeset $(TEST_OPTS_JCOV_DIFF_CHANGESET) ... )
1270         $(DIFF_COMMAND)
1271         $(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar \
1272           DiffCoverage -replaceDiff "src/.*/classes/:" -all \
1273             $(JCOV_RESULT_FILE) $(JCOV_SOURCE_DIFF) > \
1274             $(JCOV_DIFF_COVERAGE_REPORT)
1275 
1276     TARGETS += jcov-gen-diffcoverage
1277 
1278   endif
1279 
1280   # Hook this into the framework at appropriate places
1281   pre-run-test: jcov-start-grabber
1282 
1283   post-run-test: jcov-gen-report
1284 
1285   ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1286 
1287     post-run-test: jcov-gen-diffcoverage
1288 
1289   endif
1290 
1291   jcov-stop-grabber: run-all-tests
1292 
1293 endif
1294 
1295 ################################################################################
1296 
1297 all: run-test
1298 
1299 .PHONY: default all $(TARGETS)