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