1 #
   2 # Copyright (c) 2016, 2017, 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, \
  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
  64 ifeq ($(OPENJDK_TARGET_OS), windows)
  65   ifndef _NT_SYMBOL_PATH
  66     # Can't use PathList here as it adds quotes around the value.
  67     _NT_SYMBOL_PATH := \
  68         $(subst $(SPACE),;,$(strip \
  69             $(foreach p, $(sort $(dir $(wildcard \
  70                 $(addprefix $(SYMBOLS_IMAGE_DIR)/bin/, *.pdb */*.pdb)))), \
  71               $(call FixPath, $p) \
  72             ) \
  73         ))
  74     export _NT_SYMBOL_PATH
  75     $(info _NT_SYMBOL_PATH=$(_NT_SYMBOL_PATH))
  76   endif
  77 endif
  78 
  79 ################################################################################
  80 # Hook to include the corresponding custom file, if present.
  81 $(eval $(call IncludeCustomExtension, RunTests.gmk))
  82 ################################################################################
  83 
  84 TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
  85 TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
  86 TEST_SUMMARY := $(TEST_RESULTS_DIR)/test-summary.txt
  87 TEST_LAST_IDS := $(TEST_SUPPORT_DIR)/test-last-ids.txt
  88 
  89 ifeq ($(CUSTOM_ROOT), )
  90   JTREG_TOPDIR := $(TOPDIR)
  91 else
  92   JTREG_TOPDIR := $(CUSTOM_ROOT)
  93 endif
  94 
  95 JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler
  96 JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar
  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:0
 105 endif
 106 
 107 GTEST_LAUNCHER_DIRS := $(patsubst %/gtestLauncher, %, $(wildcard $(TEST_IMAGE_DIR)/hotspot/gtest/*/gtestLauncher))
 108 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, $(GTEST_LAUNCHER_DIRS)))
 109 
 110 ################################################################################
 111 # Setup global test running parameters
 112 ################################################################################
 113 
 114 # Each factor variable comes in 3 variants. The first one is reserved for users
 115 # to use on command line. The other two are for predifined configurations in JDL
 116 # and for machine specific configurations respectively.
 117 TEST_JOBS_FACTOR ?= 1
 118 TEST_JOBS_FACTOR_JDL ?= 1
 119 TEST_JOBS_FACTOR_MACHINE ?= 1
 120 
 121 ifeq ($(TEST_JOBS), 0)
 122   # Concurrency based on min(cores / 2, 12) * TEST_JOBS_FACTOR
 123   TEST_JOBS := $(shell $(AWK) \
 124     'BEGIN { \
 125       c = $(NUM_CORES) / 2; \
 126       if (c > 12) c = 12; \
 127       c = c * $(TEST_JOBS_FACTOR); \
 128       c = c * $(TEST_JOBS_FACTOR_JDL); \
 129       c = c * $(TEST_JOBS_FACTOR_MACHINE); \
 130       if (c < 1) c = 1; \
 131       printf "%.0f", c; \
 132     }')
 133 endif
 134 
 135 ################################################################################
 136 # Parse control variables
 137 ################################################################################
 138 
 139 ifneq ($(TEST_OPTS), )
 140   # Inform the user
 141   $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
 142 endif
 143 
 144 $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
 145 $(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
 146 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
 147 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
 148 
 149 $(eval $(call SetTestOpt,JOBS,JTREG))
 150 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
 151 
 152 $(eval $(call ParseKeywordVariable, JTREG, \
 153     SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR TEST_MODE ASSERT VERBOSE RETAIN MAX_MEM \
 154         EXTRA_PROBLEM_LISTS KEYWORDS, \
 155     STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS, \
 156 ))
 157 
 158 ifneq ($(JTREG), )
 159   # Inform the user
 160   $(info Running tests using JTREG control variable '$(JTREG)')
 161 endif
 162 
 163 $(eval $(call ParseKeywordVariable, GTEST, \
 164     SINGLE_KEYWORDS := REPEAT, \
 165     STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
 166 ))
 167 
 168 ifneq ($(GTEST), )
 169   # Inform the user
 170   $(info Running tests using GTEST control variable '$(GTEST)')
 171 endif
 172 
 173 
 174 ################################################################################
 175 # Component-specific Jtreg settings
 176 ################################################################################
 177 
 178 hotspot_JTREG_MAX_MEM := 0
 179 hotspot_JTREG_ASSERT := false
 180 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
 181 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
 182 
 183 jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
 184 jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
 185 langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
 186 nashorn_JTREG_PROBLEM_LIST += $(TOPDIR)/test/nashorn/ProblemList.txt
 187 hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
 188 
 189 langtools_JTREG_MAX_MEM := 768m
 190 
 191 ################################################################################
 192 # Parse test selection
 193 #
 194 # The user has given a test selection in the TEST variable. We must parse it
 195 # and determine what that means in terms of actual calls to the test framework.
 196 #
 197 # The parse functions take as argument a test specification as given by the
 198 # user, and returns a fully qualified test descriptor if it was a match, or
 199 # nothing if not. A single test specification can result in multiple test
 200 # descriptors being returned. A valid test descriptor must always be accepted
 201 # and returned identically.
 202 ################################################################################
 203 
 204 # Helper function to determine if a test specification is a Gtest test
 205 #
 206 # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
 207 # test filter string, and an optional "/<variant>" to select a specific JVM
 208 # variant. If no variant is specified, all found variants are tested.
 209 define ParseGtestTestSelection
 210   $(if $(filter gtest%, $1), \
 211     $(if $(filter gtest, $1), \
 212       $(addprefix gtest:all/, $(GTEST_VARIANTS)) \
 213     , \
 214       $(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
 215         $(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
 216       , \
 217         $(if $(filter gtest:%, $1), \
 218           $(if $(findstring /, $1), \
 219             $1 \
 220           , \
 221             $(addprefix $1/, $(GTEST_VARIANTS)) \
 222           ) \
 223         ) \
 224       ) \
 225     ) \
 226   )
 227 endef
 228 
 229 # Helper function that removes the TOPDIR part
 230 CleanupJtregPath = \
 231   $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
 232 
 233 # Take a partial Jtreg root path and return a full, absolute path to that Jtreg
 234 # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
 235 ExpandJtregRoot = \
 236   $(call CleanupJtregPath, $(wildcard \
 237     $(if $(filter /%, $1), \
 238       $(if $(wildcard $(strip $1)/TEST.ROOT), \
 239         $1 \
 240       ) \
 241     , \
 242       $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 243       $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
 244     ) \
 245   ))
 246 
 247 # Take a partial Jtreg test path and return a full, absolute path to that Jtreg
 248 # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
 249 ExpandJtregPath = \
 250   $(if $(call ExpandJtregRoot, $1), \
 251     $(call ExpandJtregRoot, $1) \
 252   , \
 253     $(call CleanupJtregPath, $(wildcard \
 254       $(if $(filter /%, $1), \
 255         $1 \
 256       , \
 257         $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 258         $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
 259       ) \
 260     )) \
 261   )
 262 
 263 # Helper function to determine if a test specification is a Jtreg test
 264 #
 265 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
 266 # an unspecified group name (possibly prefixed by :), or a group in a
 267 # specified test root, or a path to a test or test directory,
 268 # either absolute or relative to any of the TEST_BASEDIRS or test roots.
 269 define ParseJtregTestSelection
 270   $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
 271   $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
 272     $(eval TEST_NAME := :$(TEST_NAME)) \
 273   ) \
 274   $(if $(findstring :, $(TEST_NAME)), \
 275     $(if $(filter :%, $(TEST_NAME)), \
 276       $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
 277       $(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
 278           $(call CleanupJtregPath, $(test_root)))) \
 279     , \
 280       $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
 281       $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
 282       $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
 283     ) \
 284     $(foreach test_root, $(TEST_ROOTS), \
 285       $(if $(filter /%, $(test_root)), \
 286         jtreg:$(test_root):$(TEST_GROUP) \
 287       , \
 288         $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
 289           jtreg:$(test_root):$(TEST_GROUP) \
 290         ) \
 291       ) \
 292     ) \
 293   , \
 294     $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
 295     $(foreach test_path, $(TEST_PATHS), \
 296       jtreg:$(test_path) \
 297     ) \
 298   )
 299 endef
 300 
 301 # Helper function to determine if a test specification is a special test
 302 #
 303 # It is a special test if it is "special:" followed by a test name.
 304 define ParseSpecialTestSelection
 305   $(if $(filter special:%, $1), \
 306     $1 \
 307   )
 308 endef
 309 
 310 ifeq ($(TEST), )
 311   $(info No test selection given in TEST!)
 312   $(info Please use e.g. 'run-test TEST=tier1' or 'run-test-tier1')
 313   $(info See doc/testing.[md|html] for help)
 314   $(error Cannot continue)
 315 endif
 316 
 317 # Now intelligently convert the test selection given by the user in TEST
 318 # into a list of fully qualified test descriptors of the tests to run.
 319 TESTS_TO_RUN :=
 320 $(foreach test, $(TEST), \
 321   $(eval PARSED_TESTS := $(call ParseCustomTestSelection, $(test))) \
 322   $(if $(strip $(PARSED_TESTS)), , \
 323     $(eval PARSED_TESTS += $(call ParseGtestTestSelection, $(test))) \
 324   ) \
 325   $(if $(strip $(PARSED_TESTS)), , \
 326     $(eval PARSED_TESTS += $(call ParseJtregTestSelection, $(test))) \
 327   ) \
 328   $(if $(strip $(PARSED_TESTS)), , \
 329     $(eval PARSED_TESTS += $(call ParseSpecialTestSelection, $(test))) \
 330   ) \
 331   $(if $(strip $(PARSED_TESTS)), , \
 332     $(eval UNKNOWN_TEST := $(test)) \
 333   ) \
 334   $(eval TESTS_TO_RUN += $(PARSED_TESTS)) \
 335 )
 336 
 337 ifneq ($(UNKNOWN_TEST), )
 338   $(info Unknown test selection: '$(UNKNOWN_TEST)')
 339   $(info See doc/testing.[md|html] for help)
 340   $(error Cannot continue)
 341 endif
 342 
 343 TESTS_TO_RUN := $(strip $(TESTS_TO_RUN))
 344 
 345 
 346 # Present the result of our parsing to the user
 347 $(info Test selection '$(TEST)', will run:)
 348 $(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
 349 
 350 
 351 ################################################################################
 352 # Functions for setting up rules for running the selected tests
 353 #
 354 # The SetupRun*Test functions all have the same interface:
 355 #
 356 # Parameter 1 is the name of the rule. This is the test id, based on the test
 357 # descriptor, and this is also used as variable prefix, and the targets
 358 # generated are listed in a variable by that name.
 359 #
 360 # Remaining parameters are named arguments. Currently this is only:
 361 #   TEST -- The properly formatted fully qualified test descriptor
 362 #
 363 # After the rule named by the test id has been executed, the following
 364 # variables will be available:
 365 # testid_TOTAL - the total number of tests run
 366 # testid_PASSED - the number of successful tests
 367 # testid_FAILED - the number of failed tests
 368 # testid_ERROR - the number of tests was neither successful or failed
 369 #
 370 ################################################################################
 371 
 372 ### Rules for Gtest
 373 
 374 SetupRunGtestTest = $(NamedParamsMacroTemplate)
 375 define SetupRunGtestTestBody
 376   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 377   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 378   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 379 
 380   $1_VARIANT :=  $$(lastword $$(subst /, , $$($1_TEST)))
 381   ifeq ($$(filter $$($1_VARIANT), $$(GTEST_VARIANTS)), )
 382     $$(error Invalid gtest variant '$$($1_VARIANT)'. Valid variants: $$(GTEST_VARIANTS))
 383   endif
 384   $1_TEST_NAME := $$(strip $$(patsubst %/$$($1_VARIANT), %, \
 385       $$(patsubst gtest:%, %, $$($1_TEST))))
 386   ifneq ($$($1_TEST_NAME), all)
 387     $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
 388   endif
 389 
 390   ifneq ($$(GTEST_REPEAT), )
 391     $1_GTEST_REPEAT :=--gtest_repeat=$$(GTEST_REPEAT)
 392   endif
 393 
 394   run-test-$1: $(TEST_PREREQS)
 395         $$(call LogWarn)
 396         $$(call LogWarn, Running test '$$($1_TEST)')
 397         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 398         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, \
 399             $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \
 400                 -jdk $(JDK_IMAGE_DIR) $$($1_GTEST_FILTER) \
 401                 --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
 402                 $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
 403                 $$($1_GTEST_JAVA_OPTIONS) \
 404                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
 405             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 406             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 407         )
 408 
 409   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 410 
 411   parse-test-$1: run-test-$1
 412         $$(call LogWarn, Finished running test '$$($1_TEST)')
 413         $$(call LogWarn, Test report is stored in $$(strip \
 414             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 415         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 416           $$(eval $1_TOTAL := $$(shell $$(AWK) '/==========.* tests? from .* \
 417               test cases? ran/ { print $$$$2 }' $$($1_RESULT_FILE))) \
 418           $$(if $$($1_TOTAL), , $$(eval $1_TOTAL := 0)) \
 419           $$(eval $1_PASSED := $$(shell $$(AWK) '/\[  PASSED  \] .* tests?./ \
 420               { print $$$$4 }' $$($1_RESULT_FILE))) \
 421           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 422           $$(eval $1_FAILED := $$(shell $$(AWK) '/\[  FAILED  \] .* tests?, \
 423               listed below/ { print $$$$4 }' $$($1_RESULT_FILE))) \
 424           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 425           $$(eval $1_ERROR := $$(shell \
 426               $$(EXPR) $$($1_TOTAL) - $$($1_PASSED) - $$($1_FAILED))) \
 427         , \
 428           $$(eval $1_PASSED := 0) \
 429           $$(eval $1_FAILED := 0) \
 430           $$(eval $1_ERROR := 1) \
 431           $$(eval $1_TOTAL := 1) \
 432         )
 433 
 434   $1: run-test-$1 parse-test-$1
 435 
 436   TARGETS += $1
 437 endef
 438 
 439 ################################################################################
 440 
 441 ### Rules for Jtreg
 442 
 443 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
 444 # 1) Specified by user on command line
 445 # 2) Component-specific default
 446 # 3) Generic default
 447 #
 448 # Note: No spaces are allowed around the arguments.
 449 # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
 450 # Arg $2 Base variable, e.g. JTREG_JOBS
 451 # Arg $3 The default value (optional)
 452 define SetJtregValue
 453   ifneq ($$($2), )
 454     $1_$2 := $$($2)
 455   else
 456     ifneq ($$($$($1_COMPONENT)_$2), )
 457       $1_$2 := $$($$($1_COMPONENT)_$2)
 458     else
 459       ifneq ($3, )
 460         $1_$2 := $3
 461       endif
 462     endif
 463   endif
 464 endef
 465 
 466 SetupRunJtregTest = $(NamedParamsMacroTemplate)
 467 define SetupRunJtregTestBody
 468   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 469   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 470   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 471 
 472   $1_TEST_NAME := $$(strip $$(patsubst jtreg:%, %, $$($1_TEST)))
 473 
 474   $1_TEST_ROOT := \
 475       $$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
 476         $$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), $$(root)) \
 477       ))
 478   $1_COMPONENT := $$(lastword $$(subst /, $$(SPACE), $$($1_TEST_ROOT)))
 479   # This will work only as long as just hotspot has the additional "jtreg" directory
 480   ifeq ($$($1_COMPONENT), jtreg)
 481     $1_COMPONENT := hotspot
 482   endif
 483 
 484   ifeq ($$(JT_HOME), )
 485     $$(info Error: jtreg framework is not found.)
 486     $$(info Please run configure using --with-jtreg.)
 487     $$(error Cannot continue)
 488   endif
 489 
 490   # Unfortunately, we need different defaults for some JTREG values,
 491   # depending on what component we're running.
 492 
 493   # Convert JTREG_foo into $1_JTREG_foo with a suitable value.
 494   $$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
 495   $$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
 496   $$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,512m))
 497   $$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
 498   $$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
 499   $$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
 500 
 501   # Only the problem list for the current test root should be used.
 502   $1_JTREG_PROBLEM_LIST := $$(filter $$($1_TEST_ROOT)%, $$($1_JTREG_PROBLEM_LIST))
 503 
 504   ifneq ($(TEST_JOBS), 0)
 505     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
 506   else
 507     $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
 508   endif
 509 
 510   # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
 511   # we may end up with a lot of JVM's
 512   $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $$(EXPR) 25 / $$($1_JTREG_JOBS))
 513 
 514   JTREG_TIMEOUT_FACTOR ?= 4
 515   JTREG_VERBOSE ?= fail,error,summary
 516   JTREG_RETAIN ?= fail,error
 517 
 518   ifneq ($$($1_JTREG_MAX_MEM), 0)
 519     $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
 520     $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
 521   endif
 522 
 523   $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
 524       -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
 525       -concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR) \
 526       -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE)
 527 
 528   $1_JTREG_BASIC_OPTIONS += -automatic -ignore:quiet
 529 
 530   # Make it possible to specify the JIB_DATA_DIR for tests using the
 531   # JIB Artifact resolver
 532   $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
 533   # Some tests needs to find a boot JDK using the JDK8_HOME variable.
 534   $1_JTREG_BASIC_OPTIONS += -e:JDK8_HOME=$$(BOOT_JDK)
 535   # If running on Windows, propagate the _NT_SYMBOL_PATH to enable
 536   # symbol lookup in hserr files
 537   ifeq ($$(OPENJDK_TARGET_OS), windows)
 538     $1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH
 539   endif
 540 
 541   $1_JTREG_BASIC_OPTIONS += \
 542       $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
 543       $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
 544       #
 545 
 546   ifeq ($$($1_JTREG_ASSERT), true)
 547     $1_JTREG_BASIC_OPTIONS += -ea -esa
 548   endif
 549 
 550   ifneq ($$($1_JTREG_NATIVEPATH), )
 551     $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
 552   endif
 553 
 554   ifneq ($$($1_JTREG_PROBLEM_LIST), )
 555     $1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$($1_JTREG_PROBLEM_LIST))
 556   endif
 557 
 558   ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), )
 559     # Accept both absolute paths as well as relative to the current test root.
 560     $1_JTREG_BASIC_OPTIONS += $$(addprefix -exclude:, $$(wildcard \
 561         $$(JTREG_EXTRA_PROBLEM_LISTS) \
 562         $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
 563     ))
 564   endif
 565 
 566   ifneq ($$(JIB_HOME), )
 567     $1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
 568   endif
 569 
 570   $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_GRAAL_DIR=${TEST_IMAGE_DIR}/hotspot/jtreg/graal
 571 
 572   ifneq ($$(JTREG_FAILURE_HANDLER_OPTIONS), )
 573     $1_JTREG_LAUNCHER_OPTIONS += -Djava.library.path="$(JTREG_FAILURE_HANDLER_DIR)"
 574   endif
 575 
 576   ifneq ($$(JTREG_KEYWORDS), )
 577     # The keywords string may contain problematic characters and may be quoted
 578     # already when it arrives here. Remove any existing quotes and replace them
 579     # with one set of single quotes.
 580     $1_JTREG_KEYWORDS := \
 581         $$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS))))
 582     ifneq ($$($1_JTREG_KEYWORDS), )
 583       $1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)'
 584     endif
 585   endif
 586 
 587   clean-workdir-$1:
 588         $$(RM) -r $$($1_TEST_SUPPORT_DIR)
 589 
 590   run-test-$1: clean-workdir-$1 $(TEST_PREREQS)
 591         $$(call LogWarn)
 592         $$(call LogWarn, Running test '$$($1_TEST)')
 593         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 594         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
 595             $$(JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
 596                 -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
 597                 $$($1_JTREG_BASIC_OPTIONS) \
 598                 -testjdk:$$(JDK_IMAGE_DIR) \
 599                 -dir:$$(JTREG_TOPDIR) \
 600                 -reportDir:$$($1_TEST_RESULTS_DIR) \
 601                 -workDir:$$($1_TEST_SUPPORT_DIR) \
 602                 $$(JTREG_OPTIONS) \
 603                 $$(JTREG_FAILURE_HANDLER_OPTIONS) \
 604                 $$($1_TEST_NAME) \
 605             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 606             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 607         )
 608 
 609   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
 610 
 611   parse-test-$1: run-test-$1
 612         $$(call LogWarn, Finished running test '$$($1_TEST)')
 613         $$(call LogWarn, Test report is stored in $$(strip \
 614             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 615         $$(if $$(wildcard $$($1_RESULT_FILE)), \
 616           $$(eval $1_PASSED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
 617               for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
 618               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 619           $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
 620           $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 621               for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
 622               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 623           $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
 624           $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
 625               for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
 626               print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
 627           $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
 628           $$(eval $1_TOTAL := $$(shell \
 629               $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR))) \
 630         , \
 631           $$(eval $1_PASSED := 0) \
 632           $$(eval $1_FAILED := 0) \
 633           $$(eval $1_ERROR := 1) \
 634           $$(eval $1_TOTAL := 1) \
 635         )
 636 
 637   $1: run-test-$1 parse-test-$1
 638 
 639   TARGETS += $1
 640 endef
 641 
 642 ################################################################################
 643 
 644 ### Rules for special tests
 645 
 646 SetupRunSpecialTest = $(NamedParamsMacroTemplate)
 647 define SetupRunSpecialTestBody
 648   $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
 649   $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
 650   $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
 651 
 652   $1_FULL_TEST_NAME := $$(strip $$(patsubst special:%, %, $$($1_TEST)))
 653   ifneq ($$(findstring :, $$($1_FULL_TEST_NAME)), )
 654     $1_TEST_NAME := $$(firstword $$(subst :, ,$$($1_FULL_TEST_NAME)))
 655     $1_TEST_ARGS := $$(strip $$(patsubst special:$$($1_TEST_NAME):%, %, $$($1_TEST)))
 656   else
 657     $1_TEST_NAME := $$($1_FULL_TEST_NAME)
 658     $1_TEST_ARGS :=
 659   endif
 660 
 661   ifeq ($$($1_TEST_NAME), hotspot-internal)
 662     $1_TEST_COMMAND_LINE := \
 663         $$(JDK_IMAGE_DIR)/bin/java -XX:+ExecuteInternalVMTests \
 664         -XX:+ShowMessageBoxOnError -version
 665   else ifeq ($$($1_TEST_NAME), failure-handler)
 666     $1_TEST_COMMAND_LINE := \
 667         ($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f \
 668         BuildFailureHandler.gmk test)
 669   else ifeq ($$($1_TEST_NAME), make)
 670     $1_TEST_COMMAND_LINE := \
 671         ($(CD) $(TOPDIR)/test/make && $(MAKE) $(MAKE_ARGS) -f \
 672         TestMake.gmk $$($1_TEST_ARGS))
 673   else
 674     $$(error Invalid special test specification: $$($1_TEST_NAME))
 675   endif
 676 
 677   run-test-$1: $(TEST_PREREQS)
 678         $$(call LogWarn)
 679         $$(call LogWarn, Running test '$$($1_TEST)')
 680         $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
 681         $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/test-execution, \
 682             $$($1_TEST_COMMAND_LINE) \
 683                 > >($(TEE) $$($1_TEST_RESULTS_DIR)/test-output.txt) \
 684             && $$(ECHO) $$$$? > $$($1_EXITCODE) \
 685             || $$(ECHO) $$$$? > $$($1_EXITCODE) \
 686         )
 687 
 688   $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
 689 
 690   # We can not parse the various "special" tests.
 691   parse-test-$1: run-test-$1
 692         $$(call LogWarn, Finished running test '$$($1_TEST)')
 693         $$(call LogWarn, Test report is stored in $$(strip \
 694             $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
 695         $$(call LogWarn, Warning: Special test results are not properly parsed!)
 696         $$(eval $1_PASSED := 0)
 697         $$(eval $1_FAILED := 0)
 698         $$(eval $1_ERROR := 0)
 699         $$(eval $1_TOTAL := 0)
 700 
 701   $1: run-test-$1 parse-test-$1
 702 
 703   TARGETS += $1
 704 endef
 705 
 706 ################################################################################
 707 # Setup and execute make rules for all selected tests
 708 ################################################################################
 709 
 710 # Helper function to determine which handler to use for the given test
 711 UseGtestTestHandler = \
 712   $(if $(filter gtest:%, $1), true)
 713 
 714 UseJtregTestHandler = \
 715   $(if $(filter jtreg:%, $1), true)
 716 
 717 UseSpecialTestHandler = \
 718   $(if $(filter special:%, $1), true)
 719 
 720 # Now process each test to run and setup a proper make rule
 721 $(foreach test, $(TESTS_TO_RUN), \
 722   $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
 723       $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
 724   $(eval ALL_TEST_IDS += $(TEST_ID)) \
 725   $(if $(call UseCustomTestHandler, $(test)), \
 726     $(eval $(call SetupRunCustomTest, $(TEST_ID), \
 727         TEST := $(test), \
 728     )) \
 729   ) \
 730   $(if $(call UseGtestTestHandler, $(test)), \
 731     $(eval $(call SetupRunGtestTest, $(TEST_ID), \
 732         TEST := $(test), \
 733     )) \
 734   ) \
 735   $(if $(call UseJtregTestHandler, $(test)), \
 736     $(eval $(call SetupRunJtregTest, $(TEST_ID), \
 737         TEST := $(test), \
 738     )) \
 739   ) \
 740   $(if $(call UseSpecialTestHandler, $(test)), \
 741     $(eval $(call SetupRunSpecialTest, $(TEST_ID), \
 742         TEST := $(test), \
 743     )) \
 744   ) \
 745 )
 746 
 747 # Sort also removes duplicates, so if there is any we'll get fewer words.
 748 ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
 749   $(error Duplicate test specification)
 750 endif
 751 
 752 
 753 ################################################################################
 754 # The main target for RunTests.gmk
 755 ################################################################################
 756 
 757 # The SetupRun*Test functions have populated TARGETS.
 758 
 759 TEST_FAILURE := false
 760 
 761 run-test: $(TARGETS)
 762         # Create and print a table of the result of all tests run
 763         $(RM) $(TEST_SUMMARY).old 2> /dev/null
 764         $(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
 765         $(RM) $(TEST_LAST_IDS).old 2> /dev/null
 766         $(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
 767         $(ECHO) >> $(TEST_SUMMARY) ==============================
 768         $(ECHO) >> $(TEST_SUMMARY) Test summary
 769         $(ECHO) >> $(TEST_SUMMARY) ==============================
 770         $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5s %5s %5s %5s %2s\n" "  " \
 771             TEST TOTAL PASS FAIL ERROR " "
 772         $(foreach test, $(TESTS_TO_RUN), \
 773           $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
 774               $(TR) -cs '[a-z][A-Z][0-9]\n' '[_*1000]')) \
 775             $(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
 776           $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '[_*1000]')) \
 777           $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
 778             $(eval TEST_NAME := ) \
 779             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" "  " "$(test)"  $(NEWLINE) \
 780           , \
 781             $(eval TEST_NAME := $(test)) \
 782           ) \
 783           $(if $(filter $($(TEST_ID)_PASSED), $($(TEST_ID)_TOTAL)), \
 784             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
 785                 "  " "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
 786                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "  " $(NEWLINE) \
 787           , \
 788             $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %2s\n" \
 789                  ">>" "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
 790                 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) "<<" $(NEWLINE) \
 791             $(eval TEST_FAILURE := true) \
 792           ) \
 793         )
 794         $(ECHO) >> $(TEST_SUMMARY) ==============================
 795         $(if $(filter true, $(TEST_FAILURE)), \
 796           $(ECHO) >> $(TEST_SUMMARY) TEST FAILURE $(NEWLINE) \
 797           $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR) $(NEWLINE) \
 798           $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
 799         , \
 800           $(ECHO) >> $(TEST_SUMMARY) TEST SUCCESS \
 801         )
 802         $(ECHO)
 803         $(CAT) $(TEST_SUMMARY)
 804         $(ECHO)
 805 
 806 ################################################################################
 807 
 808 all: run-test
 809 
 810 .PHONY: default all run-test $(TARGETS)