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