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