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