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