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