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