1 #
   2 # Copyright (c) 2016, 2021, 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_FAILURE_HANDLER_TIMEOUT ?= 0
  97 
  98 ifneq ($(wildcard $(JTREG_FAILURE_HANDLER)), )
  99   JTREG_FAILURE_HANDLER_OPTIONS := \
 100       -timeoutHandlerDir:$(JTREG_FAILURE_HANDLER) \
 101       -observerDir:$(JTREG_FAILURE_HANDLER) \
 102       -timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler \
 103       -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \
 104       -timeoutHandlerTimeout:$(JTREG_FAILURE_HANDLER_TIMEOUT)
 105 endif
 106 
 107 GTEST_LAUNCHER_DIRS := $(patsubst %/gtestLauncher, %, \
 108     $(wildcard $(TEST_IMAGE_DIR)/hotspot/gtest/*/gtestLauncher))
 109 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, \
 110     $(GTEST_LAUNCHER_DIRS)))
 111 
 112 COV_ENVIRONMENT :=
 113 JTREG_COV_OPTIONS :=
 114 
 115 ifeq ($(TEST_OPTS_JCOV), true)
 116   JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
 117   JCOV_GRABBER_LOG := $(JCOV_OUTPUT_DIR)/grabber.log
 118   JCOV_RESULT_FILE := $(JCOV_OUTPUT_DIR)/result.xml
 119   JCOV_REPORT := $(JCOV_OUTPUT_DIR)/report
 120   JCOV_MEM_OPTIONS := -Xms64m -Xmx4g
 121 
 122   # Replace our normal test JDK with the JCov image.
 123   JDK_UNDER_TEST := $(JCOV_IMAGE_DIR)
 124 
 125   COV_ENVIRONMENT += JAVA_TOOL_OPTIONS="$(JCOV_MEM_OPTIONS)" \
 126       _JAVA_OPTIONS="$(JCOV_MEM_OPTIONS)"
 127   JTREG_COV_OPTIONS += -e:JAVA_TOOL_OPTIONS='$(JCOV_MEM_OPTIONS)' \
 128       -e:_JAVA_OPTIONS='$(JCOV_MEM_OPTIONS)'
 129 endif
 130 
 131 ifeq ($(GCOV_ENABLED), true)
 132   GCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/gcov-output
 133   COV_ENVIRONMENT += GCOV_PREFIX="$(GCOV_OUTPUT_DIR)"
 134   JTREG_COV_OPTIONS += -e:GCOV_PREFIX="$(GCOV_OUTPUT_DIR)"
 135 endif
 136 
 137 ################################################################################
 138 # Setup global test running parameters
 139 ################################################################################
 140 
 141 # Each factor variable comes in 3 variants. The first one is reserved for users
 142 # to use on command line. The other two are for predefined configurations in JDL
 143 # and for machine specific configurations respectively.
 144 TEST_JOBS_FACTOR ?= 1
 145 TEST_JOBS_FACTOR_JDL ?= 1
 146 TEST_JOBS_FACTOR_MACHINE ?= 1
 147 
 148 ifeq ($(TEST_JOBS), 0)
 149   CORES_DIVIDER := 2
 150   # For some big multi-core machines with low ulimit -u setting we hit the max
 151   # threads/process limit. In such a setup the memory/cores-only-guided
 152   # TEST_JOBS config is insufficient. From experience a concurrency setting of
 153   # 14 works reasonably well for low ulimit values (<= 4096). Thus, use
 154   # divider 4096/14. For high ulimit -u values this shouldn't make a difference.
 155   ULIMIT_DIVIDER := (4096/14)
 156   PROC_ULIMIT := -1
 157   ifneq ($(OPENJDK_TARGET_OS), windows)
 158     PROC_ULIMIT := $(shell $(ULIMIT) -u)
 159     ifeq ($(PROC_ULIMIT), unlimited)
 160       PROC_ULIMIT := -1
 161     endif
 162   endif
 163   MEMORY_DIVIDER := 2048
 164   TEST_JOBS := $(shell $(AWK) \
 165     'BEGIN { \
 166       c = $(NUM_CORES) / $(CORES_DIVIDER); \
 167       m = $(MEMORY_SIZE) / $(MEMORY_DIVIDER); \
 168       u = $(PROC_ULIMIT); \
 169       if (u > -1) { \
 170         u = u / $(ULIMIT_DIVIDER); \
 171         if (u < c) c = u; \
 172       } \
 173       if (c > m) c = m; \
 174       c = c * $(TEST_JOBS_FACTOR); \
 175       c = c * $(TEST_JOBS_FACTOR_JDL); \
 176       c = c * $(TEST_JOBS_FACTOR_MACHINE); \
 177       if (c < 1) c = 1; \
 178       printf "%.0f", c; \
 179     }')
 180 endif
 181 
 182 ################################################################################
 183 # Parse control variables
 184 ################################################################################
 185 
 186 ifneq ($(TEST_OPTS), )
 187   # Inform the user
 188   $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
 189 endif
 190 
 191 ### Jtreg
 192 
 193 $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
 194 $(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
 195 
 196 $(eval $(call SetTestOpt,JOBS,JTREG))
 197 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
 198 $(eval $(call SetTestOpt,FAILURE_HANDLER_TIMEOUT,JTREG))
 199 
 200 $(eval $(call ParseKeywordVariable, JTREG, \
 201     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \
 202         TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM RUN_PROBLEM_LISTS \
 203         RETRY_COUNT REPEAT_COUNT MAX_OUTPUT $(CUSTOM_JTREG_SINGLE_KEYWORDS), \
 204     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \
 205         EXTRA_PROBLEM_LISTS LAUNCHER_OPTIONS \
 206         $(CUSTOM_JTREG_STRING_KEYWORDS), \
 207 ))
 208 
 209 ifneq ($(JTREG), )
 210   # Inform the user
 211   $(info Running tests using JTREG control variable '$(JTREG)')
 212 endif
 213 
 214 ### Gtest
 215 
 216 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
 217 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
 218 
 219 $(eval $(call ParseKeywordVariable, GTEST, \
 220     SINGLE_KEYWORDS := REPEAT, \
 221     STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
 222 ))
 223 
 224 ifneq ($(GTEST), )
 225   # Inform the user
 226   $(info Running tests using GTEST control variable '$(GTEST)')
 227 endif
 228 
 229 ### Microbenchmarks
 230 
 231 $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
 232 $(eval $(call SetTestOpt,JAVA_OPTIONS,MICRO))
 233 
 234 $(eval $(call ParseKeywordVariable, MICRO, \
 235     SINGLE_KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
 236     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS RESULTS_FORMAT TEST_JDK \
 237         BENCHMARKS_JAR, \
 238 ))
 239 
 240 ifneq ($(MICRO), )
 241   # Inform the user
 242   $(info Running tests using MICRO control variable '$(MICRO)')
 243 endif
 244 
 245 
 246 ################################################################################
 247 # Component-specific Jtreg settings
 248 ################################################################################
 249 
 250 hotspot_JTREG_MAX_MEM := 0
 251 hotspot_JTREG_ASSERT := false
 252 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
 253 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
 254 lib-test_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/lib-test/jtreg/native
 255 
 256 jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
 257 jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
 258 langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
 259 hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
 260 lib-test_JTREG_PROBLEM_LIST += $(TOPDIR)/test/lib-test/ProblemList.txt
 261 
 262 ################################################################################
 263 # Parse test selection
 264 #
 265 # The user has given a test selection in the TEST variable. We must parse it
 266 # and determine what that means in terms of actual calls to the test framework.
 267 #
 268 # The parse functions take as argument a test specification as given by the
 269 # user, and returns a fully qualified test descriptor if it was a match, or
 270 # nothing if not. A single test specification can result in multiple test
 271 # descriptors being returned. A valid test descriptor must always be accepted
 272 # and returned identically.
 273 ################################################################################
 274 
 275 # Helper function to determine if a test specification is a Gtest test
 276 #
 277 # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
 278 # test filter string, and an optional "/<variant>" to select a specific JVM
 279 # variant. If no variant is specified, all found variants are tested.
 280 define ParseGtestTestSelection
 281   $(if $(filter gtest%, $1), \
 282     $(if $(filter gtest, $1), \
 283       $(addprefix gtest:all/, $(GTEST_VARIANTS)) \
 284     , \
 285       $(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
 286         $(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
 287       , \
 288         $(if $(filter gtest:%, $1), \
 289           $(if $(findstring /, $1), \
 290             $1 \
 291           , \
 292             $(addprefix $1/, $(GTEST_VARIANTS)) \
 293           ) \
 294         ) \
 295       ) \
 296     ) \
 297   )
 298 endef
 299 
 300 # Helper function to determine if a test specification is a microbenchmark test
 301 #
 302 # It is a microbenchmark test if it is either "micro", or "micro:" followed by
 303 # an optional test filter string.
 304 define ParseMicroTestSelection
 305   $(if $(filter micro%, $1), \
 306     $(if $(filter micro, $1), \
 307       micro:all \
 308     , \
 309       $(if $(filter micro:, $1), \
 310         micro:all \
 311       , \
 312         $1 \
 313       ) \
 314     ) \
 315   )
 316 endef
 317 
 318 # Helper function that removes the TOPDIR part
 319 CleanupJtregPath = \
 320   $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
 321 
 322 # Take a partial Jtreg root path and return a full, absolute path to that Jtreg
 323 # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
 324 ExpandJtregRoot = \
 325   $(call CleanupJtregPath, $(wildcard \
 326     $(if $(filter /%, $1), \
 327       $(if $(wildcard $(strip $1)/TEST.ROOT), \
 328         $1 \
 329       ) \
 330     , \
 331       $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 332       $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 333     ) \
 334   ))
 335 
 336 # Take a partial Jtreg test path and return a full, absolute path to that Jtreg
 337 # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
 338 ExpandJtregPath = \
 339   $(if $(call ExpandJtregRoot, $1), \
 340     $(call ExpandJtregRoot, $1) \
 341   , \
 342     $(call CleanupJtregPath, $(wildcard \
 343       $(if $(filter /%, $1), \
 344         $1 \
 345       , \
 346         $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 347         $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 348       ) \
 349     )) \
 350   )
 351 
 352 # Helper function to determine if a test specification is a Jtreg test
 353 #
 354 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
 355 # an unspecified group name (possibly prefixed by :), or a group in a
 356 # specified test root, or a path to a test or test directory,
 357 # either absolute or relative to any of the TEST_BASEDIRS or test roots.
 358 define ParseJtregTestSelection
 359   $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
 360   $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
 361     $(eval TEST_NAME := :$(TEST_NAME)) \
 362   ) \
 363   $(if $(findstring :, $(TEST_NAME)), \
 364     $(if $(filter :%, $(TEST_NAME)), \
 365       $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
 366       $(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
 367           $(call CleanupJtregPath, $(test_root)))) \
 368     , \
 369       $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
 370       $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
 371       $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
 372     ) \
 373     $(foreach test_root, $(TEST_ROOTS), \
 374       $(if $(filter /%, $(test_root)), \
 375         jtreg:$(test_root):$(TEST_GROUP) \
 376       , \
 377         $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
 378           jtreg:$(test_root):$(TEST_GROUP) \
 379         ) \
 380       ) \
 381     ) \
 382   , \
 383     $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
 384     $(foreach test_path, $(TEST_PATHS), \
 385       jtreg:$(test_path) \
 386     ) \
 387   )
 388 endef
 389 
 390 # Helper function to determine if a test specification is a special test
 391 #
 392 # It is a special test if it is "special:" followed by a test name,
 393 # if it is "make:" or "make-" followed by a make test, or any of the special
 394 # test names as a single word.
 395 define ParseSpecialTestSelection
 396   $(if $(filter special:%, $1), \
 397     $1 \
 398   ) \
 399   $(if $(filter make%, $1), \
 400     $(if $(filter make:%, $1), \
 401       special:$(strip $1) \
 402     ) \
 403     $(if $(filter make-%, $1), \
 404       special:$(patsubst make-%,make:%, $1) \
 405     ) \
 406     $(if $(filter make, $1), \
 407       special:make:all \
 408     )
 409   ) \
 410   $(if $(filter failure-handler, $1), \
 411     special:$(strip $1) \
 412   )
 413 endef
 414 
 415 ifeq ($(TEST), )
 416   $(info No test selection given in TEST!)
 417   $(info Please use e.g. 'make test TEST=tier1' or 'make test-tier1')
 418   $(info See doc/testing.[md|html] for help)
 419   $(error Cannot continue)
 420 endif
 421 
 422 # Now intelligently convert the test selection given by the user in TEST
 423 # into a list of fully qualified test descriptors of the tests to run.
 424 TESTS_TO_RUN :=
 425 $(foreach test, $(TEST), \
 426   $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
 427   $(if $(strip $(PARSED_TESTS)), , \
 428     $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
 429   ) \
 430   $(if $(strip $(PARSED_TESTS)), , \
 431     $(eval PARSED_TESTS += $(call ParseMicroTestSelection, $(test))) \
 432   ) \
 433   $(if $(strip $(PARSED_TESTS)), , \
 434     $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
 435   ) \
 436   $(if $(strip $(PARSED_TESTS)), , \
 437     $(eval PARSED_TESTS += $(call ParseSpecialTestSelection, $(test))) \
 438   ) \
 439   $(if $(strip $(PARSED_TESTS)), , \
 440     $(eval UNKNOWN_TEST := $(test)) \
 441   ) \
 442   $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
 443 )
 444 
 445 ifneq ($(UNKNOWN_TEST), )
 446   $(info Unknown test selection: '$(UNKNOWN_TEST)')
 447   $(info See doc/testing.[md|html] for help)
 448   $(error Cannot continue)
 449 endif
 450 
 451 TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
 452 
 453 
 454 # Present the result of our parsing to the user
 455 $(info Test selection '$(TEST)', will run:)
 456 $(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
 457 
 458 
 459 ################################################################################
 460 # Functions for setting up rules for running the selected tests
 461 #
 462 # The SetupRun*Test functions all have the same interface:
 463 #
 464 # Parameter 1 is the name of the rule. This is the test id, based on the test
 465 # descriptor, and this is also used as variable prefix, and the targets
 466 # generated are listed in a variable by that name.
 467 #
 468 # Remaining parameters are named arguments. Currently this is only:
 469 #   TEST -- The properly formatted fully qualified test descriptor
 470 #
 471 # After the rule named by the test id has been executed, the following
 472 # variables will be available:
 473 # testid_TOTAL - the total number of tests run
 474 # testid_PASSED - the number of successful tests
 475 # testid_FAILED - the number of failed tests
 476 # testid_ERROR - the number of tests was neither successful or failed
 477 #
 478 ################################################################################
 479 
 480 ### Rules for Gtest
 481 
 482 SetupRunGtestTest = $(NamedParamsMacroTemplate)
 483 define SetupRunGtestTestBody
 484   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 485   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 486   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 487 
 488   $1_VARIANT :=  $$(lastword $$(subst /, , $$($1_TEST)))
 489   ifeq ($$(filter $$($1_VARIANT), $$(GTEST_VARIANTS)), )
 490     $$(error Invalid gtest variant '$$($1_VARIANT)'. Valid variants: $$(GTEST_VARIANTS))
 491   endif
 492   $1_TEST_NAME := $$(strip $$(patsubst %/$$($1_VARIANT), %, \
 493       $$(patsubst gtest:%, %, $$($1_TEST))))
 494   ifneq ($$($1_TEST_NAME), all)
 495     $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
 496   endif
 497 
 498   ifneq ($$(GTEST_REPEAT), )
 499     $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
 500   endif
 501 
 502   run-test-$1: pre-run-test
 503 	$$(call LogWarn)
 504 	$$(call LogWarn, Running test '$$($1_TEST)')
 505 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 506 	$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, ( \
 507 	    $$(CD) $$($1_TEST_SUPPORT_DIR) && \
 508 	    $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \
 509 	        -jdk $(JDK_UNDER_TEST) $$($1_GTEST_FILTER) \
 510 	        --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
 511 	        --gtest_catch_exceptions=0 \
 512 	        $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
 513 	        $$(GTEST_JAVA_OPTIONS) \
 514 	        > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
 515 	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 516 	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 517 	))
 518 
 519   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 520 
 521   parse-test-$1: run-test-$1
 522 	$$(call LogWarn, Finished running test '$$($1_TEST)')
 523 	$$(call LogWarn, Test report is stored in $$(strip \
 524 	    $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 525 	$$(if $$(wildcard $$($1_RESULT_FILE)), \
 526 	  $$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
 527 	      test (cases?|suites?) ran/ { print $$$$2 }' $$($1_RESULT_FILE))) \
 528 	  $$(if $$($1_TOTAL), , $$(eval $1_TOTAL := 0)) \
 529 	  $$(eval $1_PASSED := $$(shell $$(AWK) '/\[  PASSED  \] .* tests?./ \
 530 	      { print $$$$4 }' $$($1_RESULT_FILE))) \
 531 	  $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 532 	  $$(eval $1_FAILED := $$(shell $$(AWK) '/\[  FAILED  \] .* tests?, \
 533 	      listed below/ { print $$$$4 }' $$($1_RESULT_FILE))) \
 534 	  $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 535 	  $$(eval $1_ERROR := $$(shell \
 536 	      $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED))) \
 537 	, \
 538 	  $$(eval $1_PASSED := 0) \
 539 	  $$(eval $1_FAILED := 0) \
 540 	  $$(eval $1_ERROR := 1) \
 541 	  $$(eval $1_TOTAL := 1) \
 542 	)
 543 
 544   $1: run-test-$1 parse-test-$1
 545 
 546   TARGETS += $1 run-test-$1 parse-test-$1
 547   TEST_TARGETS += parse-test-$1
 548 
 549 endef
 550 
 551 ################################################################################
 552 
 553 ### Rules for Microbenchmarks
 554 
 555 # Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
 556 # 1) Specified by user on command line
 557 # 2) Generic default
 558 #
 559 # Note: No spaces are allowed around the arguments.
 560 # Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
 561 # Arg $2 Base variable, e.g. MICRO_TEST_JDK
 562 # Arg $3 The default value (optional)
 563 define SetMicroValue
 564   ifneq ($$($2), )
 565     $1_$2 := $$($2)
 566   else
 567     ifneq ($3, )
 568       $1_$2 := $3
 569     endif
 570   endif
 571 endef
 572 
 573 SetupRunMicroTest = $(NamedParamsMacroTemplate)
 574 define SetupRunMicroTestBody
 575   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 576   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 577   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 578 
 579   $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
 580 
 581   $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/benchmarks.jar))
 582   $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_UNDER_TEST)))
 583   $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
 584 
 585   # Current tests needs to open java.io
 586   $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
 587 
 588   # Save output as JSON or CSV file
 589   ifneq ($$(MICRO_RESULTS_FORMAT), )
 590     $1_MICRO_BASIC_OPTIONS += -rf $$(MICRO_RESULTS_FORMAT)
 591     $1_MICRO_BASIC_OPTIONS += -rff $$($1_TEST_RESULTS_DIR)/jmh-result.$(MICRO_RESULTS_FORMAT)
 592   endif
 593 
 594   # Set library path for native dependencies
 595   $1_JMH_JVM_ARGS := -Djava.library.path=$$(TEST_IMAGE_DIR)/micro/native
 596 



 597   ifneq ($$(MICRO_VM_OPTIONS)$$(MICRO_JAVA_OPTIONS), )
 598     $1_JMH_JVM_ARGS += $$(MICRO_VM_OPTIONS) $$(MICRO_JAVA_OPTIONS)
 599   endif
 600 
 601   $1_MICRO_VM_OPTIONS := -jvmArgs $(call ShellQuote,$$($1_JMH_JVM_ARGS))
 602 
 603   ifneq ($$(MICRO_ITER), )
 604     $1_MICRO_ITER := -i $$(MICRO_ITER)
 605   endif
 606   ifneq ($$(MICRO_FORK), )
 607     $1_MICRO_FORK := -f $$(MICRO_FORK)
 608   endif
 609   ifneq ($$(MICRO_TIME), )
 610     $1_MICRO_TIME := -r $$(MICRO_TIME)
 611   endif
 612   ifneq ($$(MICRO_WARMUP_ITER), )
 613     $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
 614   endif
 615   ifneq ($$(MICRO_WARMUP_TIME), )
 616     $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
 617   endif
 618 
 619   run-test-$1: pre-run-test
 620 	$$(call LogWarn)
 621 	$$(call LogWarn, Running test '$$($1_TEST)')
 622 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 623 	$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, ( \
 624 	    $$(FIXPATH) $$($1_MICRO_TEST_JDK)/bin/java $$($1_MICRO_JAVA_OPTIONS) \
 625 	        -jar $$($1_MICRO_BENCHMARKS_JAR) \
 626 	        $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
 627 	        $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
 628 	        $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS) \
 629 	        $$($1_TEST_NAME) \
 630 	        > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
 631 	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 632 	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 633 	))
 634 
 635   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
 636 
 637   parse-test-$1: run-test-$1
 638 	$$(call LogWarn, Finished running test '$$($1_TEST)')
 639 	$$(call LogWarn, Test report is stored in $$(strip \
 640 	    $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 641 	$$(if $$(wildcard $$($1_EXITCODE)), \
 642 	  $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
 643 	  $$(if $$(filter 0, $$($1_EXIT_CODE)), \
 644 	    $$(eval $1_PASSED := 1) \
 645 	    $$(eval $1_ERROR := 0) \
 646 	  , \
 647 	    $$(eval $1_PASSED := 0) \
 648 	    $$(eval $1_ERROR := 1) \
 649 	  ) \
 650 	  $$(eval $1_FAILED := 0) \
 651 	  $$(eval $1_TOTAL := $$(shell \
 652 	      $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
 653 	, \
 654 	  $$(eval $1_PASSED := 0) \
 655 	  $$(eval $1_FAILED := 0) \
 656 	  $$(eval $1_ERROR := 1) \
 657 	  $$(eval $1_TOTAL := 1) \
 658 	)
 659 
 660   $1: run-test-$1 parse-test-$1
 661 
 662   TARGETS += $1 run-test-$1 parse-test-$1
 663   TEST_TARGETS += parse-test-$1
 664 
 665 endef
 666 
 667 ################################################################################
 668 
 669 ### Rules for Jtreg
 670 
 671 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
 672 # 1) Specified by user on command line
 673 # 2) Component-specific default
 674 # 3) Generic default
 675 #
 676 # Note: No spaces are allowed around the arguments.
 677 # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
 678 # Arg $2 Base variable, e.g. JTREG_JOBS
 679 # Arg $3 The default value (optional)
 680 define SetJtregValue
 681   ifneq ($$($2), )
 682     $1_$2 := $$($2)
 683   else
 684     ifneq ($$($$($1_COMPONENT)_$2), )
 685       $1_$2 := $$($$($1_COMPONENT)_$2)
 686     else
 687       ifneq ($3, )
 688         $1_$2 := $3
 689       endif
 690     endif
 691   endif
 692 endef
 693 
 694 SetupRunJtregTest = $(NamedParamsMacroTemplate)
 695 define SetupRunJtregTestBody
 696   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 697   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 698   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 699 
 700   $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
 701 
 702   $1_TEST_ROOT := \
 703       $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
 704         $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), $$(root)) \
 705       ))
 706   $1_COMPONENT := $$(lastword $$(subst /, $$(SPACE), $$($1_TEST_ROOT)))
 707   # This will work only as long as just hotspot has the additional "jtreg" directory
 708   ifeq ($$($1_COMPONENT), jtreg)
 709     $1_COMPONENT := hotspot
 710   endif
 711 
 712   ifeq ($$(JT_HOME), )
 713     $$(info Error: jtreg framework is not found.)
 714     $$(info Please run configure using --with-jtreg.)
 715     $$(error Cannot continue)
 716   endif
 717 
 718   # Unfortunately, we need different defaults for some JTREG values,
 719   # depending on what component we're running.
 720 
 721   # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
 722   $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
 723   $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
 724   $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,768m))
 725   $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
 726   $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
 727   $$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
 728 
 729   # Only the problem list for the current test root should be used.
 730   $1_JTREG_PROBLEM_LIST := $$(filter $$($1_TEST_ROOT)%, $$($1_JTREG_PROBLEM_LIST))
 731 
 732   ifneq ($(TEST_JOBS), 0)
 733     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
 734   else
 735     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
 736   endif
 737 
 738   # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
 739   # we may end up with a lot of JVM's
 740   $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $(AWK) 'BEGIN { print 25 / $$($1_JTREG_JOBS); }')
 741 
 742   JTREG_TIMEOUT_FACTOR ?= 4
 743 
 744   JTREG_VERBOSE ?= fail,error,summary
 745   JTREG_RETAIN ?= fail,error

 746   JTREG_RUN_PROBLEM_LISTS ?= false
 747   JTREG_RETRY_COUNT ?= 0
 748   JTREG_REPEAT_COUNT ?= 0
 749 
 750   ifneq ($$(JTREG_RETRY_COUNT), 0)
 751     ifneq ($$(JTREG_REPEAT_COUNT), 0)
 752       $$(info Error: Cannot use both JTREG_RETRY_COUNT and JTREG_REPEAT_COUNT together.)
 753       $$(info Please choose one or the other.)
 754       $$(error Cannot continue)
 755     endif
 756   endif
 757 





 758   ifneq ($$(JTREG_LAUNCHER_OPTIONS), )
 759     $1_JTREG_LAUNCHER_OPTIONS += $$(JTREG_LAUNCHER_OPTIONS)
 760   endif
 761 
 762   ifneq ($$(JTREG_MAX_OUTPUT), )
 763     $1_JTREG_LAUNCHER_OPTIONS += -Djavatest.maxOutputSize=$$(JTREG_MAX_OUTPUT)
 764   endif
 765 
 766   ifneq ($$($1_JTREG_MAX_MEM), 0)
 767     $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
 768     $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
 769   endif
 770 
 771   # Make sure the tmp dir is normalized as some tests will react badly otherwise
 772   $1_TEST_TMP_DIR := $$(abspath $$($1_TEST_SUPPORT_DIR)/tmp)
 773 
 774   $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
 775       -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
 776       -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR) \
 777       -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE) \
 778       -vmoption:-Djava.io.tmpdir="$$($1_TEST_TMP_DIR)"
 779 
 780   $1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet
 781 
 782   # Make it possible to specify the JIB_DATA_DIR for tests using the
 783   # JIB Artifact resolver
 784   $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
 785   # If running on Windows, propagate the _NT_SYMBOL_PATH to enable
 786   # symbol lookup in hserr files
 787   ifeq ($$(call isTargetOs, windows), true)
 788     $1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH
 789   endif
 790 
 791   $1_JTREG_BASIC_OPTIONS += \
 792       $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
 793       $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
 794       #
 795 
 796   ifeq ($$($1_JTREG_ASSERT), true)
 797     $1_JTREG_BASIC_OPTIONS += -ea -esa
 798   endif
 799 
 800   ifneq ($$($1_JTREG_NATIVEPATH), )
 801     $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
 802   endif
 803 
 804   ifeq ($$(JTREG_RUN_PROBLEM_LISTS), true)
 805     JTREG_PROBLEM_LIST_PREFIX := -match:
 806   else
 807     JTREG_PROBLEM_LIST_PREFIX := -exclude:
 808   endif
 809 
 810   ifneq ($$($1_JTREG_PROBLEM_LIST), )
 811     $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$($1_JTREG_PROBLEM_LIST))
 812   endif
 813 
 814   ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), )
 815     # Accept both absolute paths as well as relative to the current test root.
 816     $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
 817         $$(JTREG_EXTRA_PROBLEM_LISTS) \
 818         $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
 819     ))
 820   endif
 821 
 822   ifneq ($$(JIB_HOME), )
 823     $1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
 824   endif
 825 
 826   $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_DIR=$(TEST_IMAGE_DIR)
 827 
 828   ifneq ($$(JTREG_FAILURE_HANDLER_OPTIONS), )
 829     $1_JTREG_LAUNCHER_OPTIONS += -Djava.library.path="$(JTREG_FAILURE_HANDLER_DIR)"
 830   endif
 831 
 832   ifneq ($$(JTREG_KEYWORDS), )
 833     # The keywords string may contain problematic characters and may be quoted
 834     # already when it arrives here. Remove any existing quotes and replace them
 835     # with one set of single quotes.
 836     $1_JTREG_KEYWORDS := \
 837         $$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS))))
 838     ifneq ($$($1_JTREG_KEYWORDS), )
 839       $1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)'
 840     endif
 841   endif
 842 
 843   $$(eval $$(call SetupRunJtregTestCustom, $1))
 844 
 845   clean-workdir-$1:
 846 	$$(RM) -r $$($1_TEST_SUPPORT_DIR)
 847 
 848   $1_COMMAND_LINE := \
 849       $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
 850           -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
 851           $$($1_JTREG_BASIC_OPTIONS) \
 852           -testjdk:$$(JDK_UNDER_TEST) \
 853           -dir:$$(JTREG_TOPDIR) \
 854           -reportDir:$$($1_TEST_RESULTS_DIR) \
 855           -workDir:$$($1_TEST_SUPPORT_DIR) \
 856           -status:$$$${JTREG_STATUS} \
 857           $$(JTREG_OPTIONS) \
 858           $$(JTREG_FAILURE_HANDLER_OPTIONS) \
 859           $$(JTREG_COV_OPTIONS) \
 860           $$($1_TEST_NAME) \
 861       && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 862       || $$(ECHO) $$$$? > $$($1_EXITCODE)
 863 
 864 
 865   ifneq ($$(JTREG_RETRY_COUNT), 0)
 866     $1_COMMAND_LINE := \
 867         for i in {0..$$(JTREG_RETRY_COUNT)}; do \
 868           if [ "$$$$i" != 0 ]; then \
 869             $$(PRINTF) "\nRetrying Jtreg run. Attempt: $$$$i\n"; \
 870           fi; \
 871           $$($1_COMMAND_LINE); \
 872           if [ "`$$(CAT) $$($1_EXITCODE)`" = "0" ]; then \
 873             break; \
 874           fi; \
 875           export JTREG_STATUS="-status:error,fail"; \
 876         done
 877   endif
 878 
 879   ifneq ($$(JTREG_REPEAT_COUNT), 0)
 880     $1_COMMAND_LINE := \
 881         for i in {1..$$(JTREG_REPEAT_COUNT)}; do \
 882           $$(PRINTF) "\nRepeating Jtreg run: $$$$i out of $$(JTREG_REPEAT_COUNT)\n"; \
 883           $$($1_COMMAND_LINE); \
 884           if [ "`$$(CAT) $$($1_EXITCODE)`" != "0" ]; then \
 885             $$(PRINTF) "\nFailures detected, no more repeats.\n"; \
 886             break; \
 887           fi; \
 888         done
 889   endif
 890 
 891   run-test-$1: pre-run-test clean-workdir-$1
 892 	$$(call LogWarn)
 893 	$$(call LogWarn, Running test '$$($1_TEST)')
 894 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \
 895 	    $$($1_TEST_TMP_DIR))
 896 	$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, ( \
 897             $$(COV_ENVIRONMENT) $$($1_COMMAND_LINE) \
 898 	))
 899 
 900   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
 901 
 902   parse-test-$1: run-test-$1
 903 	$$(call LogWarn, Finished running test '$$($1_TEST)')
 904 	$$(call LogWarn, Test report is stored in $$(strip \
 905 	    $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 906 	$$(if $$(wildcard $$($1_RESULT_FILE)), \
 907 	  $$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
 908 	      for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
 909 	      print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 910 	  $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 911 	  $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 912 	      for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
 913 	      print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 914 	  $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 915 	  $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 916 	      for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
 917 	      print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 918 	  $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
 919 	  $$(eval $1_TOTAL := $$(shell \
 920 	      $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR))) \
 921 	, \
 922 	  $$(eval $1_PASSED := 0) \
 923 	  $$(eval $1_FAILED := 0) \
 924 	  $$(eval $1_ERROR := 1) \
 925 	  $$(eval $1_TOTAL := 1) \
 926 	)
 927 
 928   $1: run-test-$1 parse-test-$1 clean-workdir-$1
 929 
 930   TARGETS += $1 run-test-$1 parse-test-$1 clean-workdir-$1
 931   TEST_TARGETS += parse-test-$1
 932 
 933 endef
 934 
 935 ################################################################################
 936 
 937 ### Rules for special tests
 938 
 939 SetupRunSpecialTest = $(NamedParamsMacroTemplate)
 940 define SetupRunSpecialTestBody
 941   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 942   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 943   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 944 
 945   $1_FULL_TEST_NAME := $$(strip $$(patsubst special:%, %, $$($1_TEST)))
 946   ifneq ($$(findstring :, $$($1_FULL_TEST_NAME)), )
 947     $1_TEST_NAME := $$(firstword $$(subst :, ,$$($1_FULL_TEST_NAME)))
 948     $1_TEST_ARGS := $$(strip $$(patsubst special:$$($1_TEST_NAME):%, %, $$($1_TEST)))
 949   else
 950     $1_TEST_NAME := $$($1_FULL_TEST_NAME)
 951     $1_TEST_ARGS :=
 952   endif
 953 
 954   ifeq ($$($1_TEST_NAME), failure-handler)
 955     ifeq ($(BUILD_FAILURE_HANDLER), true)
 956       $1_TEST_COMMAND_LINE := \
 957           ($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f \
 958           BuildFailureHandler.gmk test)
 959     else
 960       $$(error Cannot test failure handler if it is not built)
 961     endif
 962   else ifeq ($$($1_TEST_NAME), make)
 963     $1_TEST_COMMAND_LINE := \
 964         ($(CD) $(TOPDIR)/test/make && $(MAKE) $(MAKE_ARGS) -f \
 965         TestMake.gmk $$($1_TEST_ARGS) TEST_SUPPORT_DIR="$$($1_TEST_SUPPORT_DIR)")
 966   else
 967     $$(error Invalid special test specification: $$($1_TEST_NAME))
 968   endif
 969 
 970   run-test-$1: pre-run-test
 971 	$$(call LogWarn)
 972 	$$(call LogWarn, Running test '$$($1_TEST)')
 973 	$$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 974 	$$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/test-execution, ( \
 975 	    $$($1_TEST_COMMAND_LINE) \
 976 	        > >($(TEE) $$($1_TEST_RESULTS_DIR)/test-output.txt) \
 977 	    && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 978 	    || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 979 	))
 980 
 981   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 982 
 983   # We can not parse the various "special" tests.
 984   parse-test-$1: run-test-$1
 985 	$$(call LogWarn, Finished running test '$$($1_TEST)')
 986 	$$(call LogWarn, Test report is stored in $$(strip \
 987 	    $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 988 	$$(call LogWarn, Warning: Special test results are not properly parsed!)
 989 	$$(eval $1_PASSED := $$(shell \
 990 	  if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 1; else $(ECHO) 0; fi \
 991 	))
 992 	$$(eval $1_FAILED := $$(shell \
 993 	  if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 0; else $(ECHO) 1; fi \
 994 	))
 995 	$$(eval $1_ERROR := 0)
 996 	$$(eval $1_TOTAL := 1)
 997 
 998   $1: run-test-$1 parse-test-$1
 999 
1000   TARGETS += $1 run-test-$1 parse-test-$1
1001   TEST_TARGETS += parse-test-$1
1002 
1003 endef
1004 
1005 ################################################################################
1006 # Setup and execute make rules for all selected tests
1007 ################################################################################
1008 
1009 # Helper function to determine which handler to use for the given test
1010 UseGtestTestHandler = \
1011   $(if $(filter gtest:%, $1), true)
1012 
1013 UseMicroTestHandler = \
1014   $(if $(filter micro:%, $1), true)
1015 
1016 UseJtregTestHandler = \
1017   $(if $(filter jtreg:%, $1), true)
1018 
1019 UseSpecialTestHandler = \
1020   $(if $(filter special:%, $1), true)
1021 
1022 # Now process each test to run and setup a proper make rule
1023 $(foreach test, $(TESTS_TO_RUN), \
1024   $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1025       $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1026   $(eval ALL_TEST_IDS += $(TEST_ID)) \
1027   $(if $(call UseCustomTestHandler, $(test)), \
1028     $(eval $(call SetupRunCustomTest, $(TEST_ID), \
1029         TEST := $(test), \
1030     )) \
1031   ) \
1032   $(if $(call UseGtestTestHandler, $(test)), \
1033     $(eval $(call SetupRunGtestTest, $(TEST_ID), \
1034         TEST := $(test), \
1035     )) \
1036   ) \
1037   $(if $(call UseMicroTestHandler, $(test)), \
1038     $(eval $(call SetupRunMicroTest, $(TEST_ID), \
1039         TEST := $(test), \
1040     )) \
1041   ) \
1042   $(if $(call UseJtregTestHandler, $(test)), \
1043     $(eval $(call SetupRunJtregTest, $(TEST_ID), \
1044         TEST := $(test), \
1045     )) \
1046   ) \
1047   $(if $(call UseSpecialTestHandler, $(test)), \
1048     $(eval $(call SetupRunSpecialTest, $(TEST_ID), \
1049         TEST := $(test), \
1050     )) \
1051   ) \
1052 )
1053 
1054 # Sort also removes duplicates, so if there is any we'll get fewer words.
1055 ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
1056   $(error Duplicate test specification)
1057 endif
1058 
1059 
1060 ################################################################################
1061 # The main target for RunTests.gmk
1062 ################################################################################
1063 
1064 #
1065 # Provide hooks for adding functionality before and after all tests are run.
1066 #
1067 
1068 $(call LogInfo, RunTest setup starting)
1069 
1070 # This target depends on all actual test having been run (TEST_TARGETS has beeen
1071 # populated by the SetupRun*Test functions). If you need to provide a teardown
1072 # hook, you must let it depend on this target.
1073 run-all-tests: $(TEST_TARGETS)
1074 	$(call LogInfo, RunTest teardown starting)
1075 
1076 # This is an abstract target that will be run before any actual tests. Add your
1077 # target as a dependency to thisif you need "setup" type functionality executed
1078 # before all tests.
1079 pre-run-test:
1080 	$(call LogInfo, RunTest setup done)
1081 
1082 # This is an abstract target that will be run after all actual tests, but before
1083 # the test summary. If you need "teardown" type functionality, add your target
1084 # as a dependency on this, and let the teardown target depend on run-all-tests.
1085 post-run-test: run-all-tests
1086 	$(call LogInfo, RunTest teardown done)
1087 
1088 #
1089 # Create and print a table of the result of all tests run
1090 #
1091 TEST_FAILURE := false
1092 
1093 run-test-report: post-run-test
1094 	$(RM) $(TEST_SUMMARY).old 2> /dev/null
1095 	$(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
1096 	$(RM) $(TEST_LAST_IDS).old 2> /dev/null
1097 	$(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
1098 	$(ECHO) >> $(TEST_SUMMARY) ==============================
1099 	$(ECHO) >> $(TEST_SUMMARY) Test summary
1100 	$(ECHO) >> $(TEST_SUMMARY) ==============================
1101 	$(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5s %5s %5s %5s %2s\n" "  " \
1102 	    TEST TOTAL PASS FAIL ERROR " "
1103 	$(foreach test, $(TESTS_TO_RUN), \
1104 	  $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1105 	      $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
1106 	    $(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
1107 	  $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '[_*1000]')) \
1108 	  $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
1109 	    $(eval TEST_NAME := ) \
1110 	    $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" "  " "$(test)"  $(NEWLINE) \
1111 	  , \
1112 	    $(eval TEST_NAME := $(test)) \
1113 	  ) \
1114 	  $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
1115 	    $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1116 	        "  " "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1117 	        $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
1118 	  , \
1119 	    $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
1120 	         ">>" "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1121 	        $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
1122 	    $(eval TEST_FAILURE := true) \
1123 	  ) \
1124 	)
1125 	$(ECHO) >> $(TEST_SUMMARY) ==============================
1126 	$(if $(filter true, $(TEST_FAILURE)), \
1127 	  $(ECHO) >> $(TEST_SUMMARY) TEST FAILURE $(NEWLINE) \
1128 	  $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR) $(NEWLINE) \
1129 	  $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
1130 	, \
1131 	  $(ECHO) >> $(TEST_SUMMARY) TEST SUCCESS \
1132 	)
1133 	$(ECHO)
1134 	$(CAT) $(TEST_SUMMARY)
1135 	$(ECHO)
1136 
1137 # The main run-test target
1138 run-test: run-test-report
1139 
1140 TARGETS += run-all-tests pre-run-test post-run-test run-test-report run-test
1141 
1142 ################################################################################
1143 # Setup JCov
1144 ################################################################################
1145 
1146 ifeq ($(TEST_OPTS_JCOV), true)
1147 
1148   jcov-do-start-grabber:
1149 	$(call MakeDir, $(JCOV_OUTPUT_DIR))
1150 	if $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -status 1>/dev/null 2>&1 ; then \
1151 	  $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600 ; \
1152 	fi
1153 	$(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar Grabber -v -t \
1154 	    $(JCOV_IMAGE_DIR)/template.xml -o $(JCOV_RESULT_FILE) \
1155 	    1>$(JCOV_GRABBER_LOG) 2>&1 &
1156 
1157   jcov-start-grabber: jcov-do-start-grabber
1158 	$(call LogWarn, Starting JCov Grabber...)
1159 	$(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -t 600 -wait
1160 
1161   jcov-stop-grabber:
1162 	$(call LogWarn, Stopping JCov Grabber...)
1163 	$(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
1164 
1165   JCOV_REPORT_TITLE := JDK code coverage report<br/>
1166   ifneq ($(JCOV_FILTERS), )
1167     JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)<br>
1168   endif
1169   JCOV_REPORT_TITLE += Tests: $(TEST)
1170 
1171   jcov-gen-report: jcov-stop-grabber
1172 	$(call LogWarn, Generating JCov report ...)
1173 	$(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
1174 	    `$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
1175 	    $(JCOV_FILTERS) \
1176 	    -mainReportTitle "$(JCOV_REPORT_TITLE)" \
1177 	    -o $(JCOV_REPORT) $(JCOV_RESULT_FILE)
1178 
1179   TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
1180       jcov-gen-report
1181 
1182   ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1183 
1184     JCOV_SOURCE_DIFF := $(JCOV_OUTPUT_DIR)/source_diff
1185     JCOV_DIFF_COVERAGE_REPORT := $(JCOV_OUTPUT_DIR)/diff_coverage_report
1186 
1187     ifneq ($(and $(HG), $(wildcard $(TOPDIR)/.hg)), )
1188       DIFF_COMMAND := $(HG) -R $(TOPDIR) diff -r $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1189     else ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
1190       DIFF_COMMAND := $(GIT) -C $(TOPDIR) diff $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1191     else
1192       $(info Error: Must be either hg or git source tree for diff coverage.)
1193       $(error Neither hg nor git source tree.)
1194     endif
1195 
1196     jcov-gen-diffcoverage: jcov-stop-grabber
1197 	$(call LogWarn, Generating diff coverage with changeset $(TEST_OPTS_JCOV_DIFF_CHANGESET) ... )
1198 	$(DIFF_COMMAND)
1199 	$(JAVA) -Xmx4g -jar $(JCOV_HOME)/lib/jcov.jar \
1200 	  DiffCoverage -replaceDiff "src/.*/classes/:" -all \
1201 	    $(JCOV_RESULT_FILE) $(JCOV_SOURCE_DIFF) > \
1202 	    $(JCOV_DIFF_COVERAGE_REPORT)
1203 
1204     TARGETS += jcov-gen-diffcoverage
1205 
1206   endif
1207 
1208   # Hook this into the framework at appropriate places
1209   pre-run-test: jcov-start-grabber
1210 
1211   post-run-test: jcov-gen-report
1212 
1213   ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1214 
1215     post-run-test: jcov-gen-diffcoverage
1216 
1217   endif
1218 
1219   jcov-stop-grabber: run-all-tests
1220 
1221 endif
1222 
1223 ################################################################################
1224 
1225 all: run-test
1226 
1227 .PHONY: default all $(TARGETS)
--- EOF ---