1 #
2 # Copyright (c) 2016, 2026, 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 include MakeFileStart.gmk
27
28 ################################################################################
29
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 AOT_JDK, \
49 STRING_KEYWORDS := VM_OPTIONS JAVA_OPTIONS, \
50 ))
51
52 # Helper function to propagate TEST_OPTS values.
53 #
54 # Note: No spaces are allowed around the arguments.
55 # Arg $1 The variable in TEST_OPTS to propagate
56 # Arg $2 The control variable to propagate it to
57 define SetTestOpt
58 ifneq ($$(TEST_OPTS_$1), )
59 $2_$1 := $$(TEST_OPTS_$1)
60 endif
61 endef
62
63 # Setup _NT_SYMBOL_PATH on Windows, which points to our pdb files.
64 ifeq ($(call isTargetOs, windows), true)
65 ifndef _NT_SYMBOL_PATH
66 SYMBOL_PATH := $(call PathList, $(sort $(patsubst %/, %, $(dir $(wildcard \
67 $(addprefix $(SYMBOLS_IMAGE_DIR)/bin/, *.pdb */*.pdb))))))
68 export _NT_SYMBOL_PATH := $(subst \\,\, $(call FixPath, \
69 $(subst $(DQUOTE),, $(SYMBOL_PATH))))
70 $(call LogDebug, Setting _NT_SYMBOL_PATH to $(_NT_SYMBOL_PATH))
71 endif
72 endif
73
74 ################################################################################
75
76 # This is the JDK that we will test
77 JDK_UNDER_TEST := $(JDK_IMAGE_DIR)
78
79 TEST_RESULTS_DIR := $(OUTPUTDIR)/test-results
80 TEST_SUPPORT_DIR := $(OUTPUTDIR)/test-support
81 TEST_SUMMARY := $(TEST_RESULTS_DIR)/test-summary.txt
82 TEST_LAST_IDS := $(TEST_SUPPORT_DIR)/test-last-ids.txt
83
84 ifeq ($(CUSTOM_ROOT), )
85 JTREG_TOPDIR := $(TOPDIR)
86 else
87 JTREG_TOPDIR := $(CUSTOM_ROOT)
88 endif
89
90 JTREG_FAILURE_HANDLER_DIR := $(TEST_IMAGE_DIR)/failure_handler
91 JTREG_FAILURE_HANDLER := $(JTREG_FAILURE_HANDLER_DIR)/jtregFailureHandler.jar
92
93 JTREG_TEST_THREAD_FACTORY_DIR := $(TEST_IMAGE_DIR)/jtreg_test_thread_factory
94 JTREG_TEST_THREAD_FACTORY_JAR := $(JTREG_TEST_THREAD_FACTORY_DIR)/jtregTestThreadFactory.jar
95
96 JTREG_VALUE_CLASS_PLUGIN_DIR := $(TEST_IMAGE_DIR)/jtreg_value_class_plugin
97 JTREG_VALUE_CLASS_PLUGIN_JAR := $(JTREG_VALUE_CLASS_PLUGIN_DIR)/valueClassPlugin.jar
98
99 JTREG_FAILURE_HANDLER_TIMEOUT ?= 0
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:$(JTREG_FAILURE_HANDLER_TIMEOUT) \
108 #
109 endif
110
111 GTEST_LAUNCHER_DIRS := $(patsubst %/gtestLauncher$(EXECUTABLE_SUFFIX), %, \
112 $(wildcard $(TEST_IMAGE_DIR)/hotspot/gtest/*/gtestLauncher$(EXECUTABLE_SUFFIX)))
113 GTEST_VARIANTS := $(strip $(patsubst $(TEST_IMAGE_DIR)/hotspot/gtest/%, %, \
114 $(GTEST_LAUNCHER_DIRS)))
115
116 COV_ENVIRONMENT :=
117 JTREG_COV_OPTIONS :=
118
119 ifeq ($(TEST_OPTS_JCOV), true)
120 JCOV_OUTPUT_DIR := $(TEST_RESULTS_DIR)/jcov-output
121 JCOV_SUPPORT_DIR := $(TEST_SUPPORT_DIR)/jcov-support
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 # Setup global test running parameters
144 ################################################################################
145
146 # Each factor variable comes in 3 variants. The first one is reserved for users
147 # to use on command line. The other two are for predefined configurations in JDL
148 # and for machine specific configurations respectively.
149 TEST_JOBS_FACTOR ?= 1
150 TEST_JOBS_FACTOR_JDL ?= 1
151 TEST_JOBS_FACTOR_MACHINE ?= 1
152
153 ifeq ($(TEST_JOBS), 0)
154 CORES_DIVIDER := 2
155 # For some big multi-core machines with low ulimit -u setting we hit the max
156 # threads/process limit. In such a setup the memory/cores-only-guided
157 # TEST_JOBS config is insufficient. From experience a concurrency setting of
158 # 14 works reasonably well for low ulimit values (<= 4096). Thus, use
159 # divider 4096/14. For high ulimit -u values this shouldn't make a difference.
160 ULIMIT_DIVIDER := (4096/14)
161 PROC_ULIMIT := -1
162 ifneq ($(OPENJDK_TARGET_OS), windows)
163 PROC_ULIMIT := $(shell $(ULIMIT) -u)
164 ifeq ($(PROC_ULIMIT), unlimited)
165 PROC_ULIMIT := -1
166 endif
167 endif
168 MEMORY_DIVIDER := 2048
169 TEST_JOBS := $(shell $(AWK) \
170 'BEGIN { \
171 c = $(NUM_CORES) / $(CORES_DIVIDER); \
172 m = $(MEMORY_SIZE) / $(MEMORY_DIVIDER); \
173 u = $(PROC_ULIMIT); \
174 if (u > -1) { \
175 u = u / $(ULIMIT_DIVIDER); \
176 if (u < c) c = u; \
177 } \
178 if (c > m) c = m; \
179 c = c * $(TEST_JOBS_FACTOR); \
180 c = c * $(TEST_JOBS_FACTOR_JDL); \
181 c = c * $(TEST_JOBS_FACTOR_MACHINE); \
182 if (c < 1) c = 1; \
183 c = c + 0.5; \
184 printf "%d", c; \
185 }')
186 endif
187
188 ################################################################################
189 # Parse control variables
190 ################################################################################
191
192 ifneq ($(TEST_OPTS), )
193 # Inform the user
194 $(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)')
195 endif
196
197 ### Jtreg
198
199 $(eval $(call SetTestOpt,VM_OPTIONS,JTREG))
200 $(eval $(call SetTestOpt,JAVA_OPTIONS,JTREG))
201
202 $(eval $(call SetTestOpt,JOBS,JTREG))
203 $(eval $(call SetTestOpt,TIMEOUT_FACTOR,JTREG))
204 $(eval $(call SetTestOpt,FAILURE_HANDLER_TIMEOUT,JTREG))
205 $(eval $(call SetTestOpt,REPORT,JTREG))
206 $(eval $(call SetTestOpt,AOT_JDK,JTREG))
207
208 $(eval $(call ParseKeywordVariable, JTREG, \
209 SINGLE_KEYWORDS := JOBS TIMEOUT_FACTOR FAILURE_HANDLER_TIMEOUT \
210 TEST_MODE ASSERT VERBOSE RETAIN TEST_THREAD_FACTORY JVMTI_STRESS_AGENT \
211 MAX_MEM RUN_PROBLEM_LISTS RETRY_COUNT REPEAT_COUNT MAX_OUTPUT REPORT \
212 AOT_JDK MANUAL VALUE_CLASS_PLUGIN $(CUSTOM_JTREG_SINGLE_KEYWORDS), \
213 STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS KEYWORDS \
214 EXTRA_PROBLEM_LISTS LAUNCHER_OPTIONS \
215 $(CUSTOM_JTREG_STRING_KEYWORDS), \
216 ))
217
218 ifneq ($(JTREG), )
219 # Inform the user
220 $(info Running tests using JTREG control variable '$(JTREG)')
221 endif
222
223 ### Gtest
224
225 $(eval $(call SetTestOpt,VM_OPTIONS,GTEST))
226 $(eval $(call SetTestOpt,JAVA_OPTIONS,GTEST))
227
228 $(eval $(call ParseKeywordVariable, GTEST, \
229 SINGLE_KEYWORDS := REPEAT, \
230 STRING_KEYWORDS := OPTIONS VM_OPTIONS JAVA_OPTIONS, \
231 ))
232
233 ifneq ($(GTEST), )
234 # Inform the user
235 $(info Running tests using GTEST control variable '$(GTEST)')
236 endif
237
238 ### Microbenchmarks
239
240 $(eval $(call SetTestOpt,VM_OPTIONS,MICRO))
241 $(eval $(call SetTestOpt,JAVA_OPTIONS,MICRO))
242
243 $(eval $(call ParseKeywordVariable, MICRO, \
244 SINGLE_KEYWORDS := ITER FORK TIME WARMUP_ITER WARMUP_TIME, \
245 STRING_KEYWORDS := OPTIONS JAVA_OPTIONS VM_OPTIONS RESULTS_FORMAT TEST_JDK \
246 BENCHMARKS_JAR, \
247 ))
248
249 ifneq ($(MICRO), )
250 # Inform the user
251 $(info Running tests using MICRO control variable '$(MICRO)')
252 endif
253
254
255 ################################################################################
256 # Component-specific Jtreg settings
257 ################################################################################
258
259 hotspot_JTREG_MAX_MEM := 0
260 hotspot_JTREG_ASSERT := false
261 hotspot_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/hotspot/jtreg/native
262 jdk_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/jdk/jtreg/native
263 lib-test_JTREG_NATIVEPATH := $(TEST_IMAGE_DIR)/lib-test/jtreg/native
264
265 jdk_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jdk/ProblemList.txt
266 jaxp_JTREG_PROBLEM_LIST += $(TOPDIR)/test/jaxp/ProblemList.txt
267 langtools_JTREG_PROBLEM_LIST += $(TOPDIR)/test/langtools/ProblemList.txt
268 hotspot_JTREG_PROBLEM_LIST += $(TOPDIR)/test/hotspot/jtreg/ProblemList.txt
269 lib-test_JTREG_PROBLEM_LIST += $(TOPDIR)/test/lib-test/ProblemList.txt
270 docs_JTREG_PROBLEM_LIST += $(TOPDIR)/test/docs/ProblemList.txt
271
272 ################################################################################
273 # Parse test selection
274 #
275 # The user has given a test selection in the TEST variable. We must parse it
276 # and determine what that means in terms of actual calls to the test framework.
277 #
278 # The parse functions take as argument a test specification as given by the
279 # user, and returns a fully qualified test descriptor if it was a match, or
280 # nothing if not. A single test specification can result in multiple test
281 # descriptors being returned. A valid test descriptor must always be accepted
282 # and returned identically.
283 ################################################################################
284
285 # Helper function to determine if a test specification is a Gtest test
286 #
287 # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional
288 # test filter string, and an optional "/<variant>" to select a specific JVM
289 # variant. If no variant is specified, all found variants are tested.
290 define ParseGtestTestSelection
291 $(if $(filter gtest%, $1), \
292 $(if $(filter gtest, $1), \
293 $(addprefix gtest:all/, $(GTEST_VARIANTS)) \
294 , \
295 $(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
296 $(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
297 , \
298 $(if $(filter gtest:%, $1), \
299 $(if $(findstring /, $1), \
300 $1 \
301 , \
302 $(addprefix $1/, $(GTEST_VARIANTS)) \
303 ) \
304 ) \
305 ) \
306 ) \
307 )
308 endef
309
310 # Helper function to determine if a test specification is a microbenchmark test
311 #
312 # It is a microbenchmark test if it is either "micro", or "micro:" followed by
313 # an optional test filter string.
314 define ParseMicroTestSelection
315 $(if $(filter micro%, $1), \
316 $(if $(filter micro, $1), \
317 micro:all \
318 , \
319 $(if $(filter micro:, $1), \
320 micro:all \
321 , \
322 $1 \
323 ) \
324 ) \
325 )
326 endef
327
328 # Helper function that removes the TOPDIR part
329 CleanupJtregPath = \
330 $(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
331
332 # Take a partial Jtreg root path and return a full, absolute path to that Jtreg
333 # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
334 ExpandJtregRoot = \
335 $(call CleanupJtregPath, $(wildcard \
336 $(if $(filter /%, $1), \
337 $(if $(wildcard $(strip $1)/TEST.ROOT), \
338 $1 \
339 ) \
340 , \
341 $(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
342 $(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
343 ) \
344 ))
345
346 # Take a partial Jtreg test path and return a full, absolute path to that Jtreg
347 # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
348 ExpandJtregPath = \
349 $(if $(call ExpandJtregRoot, $1), \
350 $(call ExpandJtregRoot, $1) \
351 , \
352 $(call CleanupJtregPath, $(wildcard \
353 $(if $(filter /%, $1), \
354 $1 \
355 , \
356 $(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
357 $(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
358 ) \
359 )) \
360 )
361
362 # with test id: dir/Test.java#selection -> Test.java#selection -> .java#selection -> #selection
363 # without: dir/Test.java -> Test.java -> .java -> <<empty string>>
364 TestID = \
365 $(subst .jasm,,$(subst .sh,,$(subst .html,,$(subst .java,,$(suffix $(notdir $1))))))
366
367 # The test id starting with a hash (#testid) will be stripped by all
368 # evals in ParseJtregTestSelectionInner and will be reinserted by calling
369 # TestID (if it is present).
370 ParseJtregTestSelection = \
371 $(call IfAppend, $(call ParseJtregTestSelectionInner, $1), $(call TestID, $1))
372
373 # Helper function to determine if a test specification is a Jtreg test
374 #
375 # It is a Jtreg test if it optionally begins with jtreg:, and then is either
376 # an unspecified group name (possibly prefixed by :), or a group in a
377 # specified test root, or a path to a test or test directory,
378 # either absolute or relative to any of the TEST_BASEDIRS or test roots.
379 define ParseJtregTestSelectionInner
380 $(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
381 $(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
382 $(eval TEST_NAME := :$(TEST_NAME)) \
383 ) \
384 $(if $(findstring :, $(TEST_NAME)), \
385 $(if $(filter :%, $(TEST_NAME)), \
386 $(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
387 $(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
388 $(call CleanupJtregPath, $(test_root)))) \
389 , \
390 $(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
391 $(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
392 $(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
393 ) \
394 $(foreach test_root, $(TEST_ROOTS), \
395 $(if $(filter /%, $(test_root)), \
396 jtreg:$(test_root):$(TEST_GROUP) \
397 , \
398 $(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
399 jtreg:$(test_root):$(TEST_GROUP) \
400 ) \
401 ) \
402 ) \
403 , \
404 $(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
405 $(foreach test_path, $(TEST_PATHS), \
406 jtreg:$(test_path) \
407 ) \
408 )
409 endef
410
411 # Helper function to determine if a test specification is a special test
412 #
413 # It is a special test if it is "special:" followed by a test name,
414 # if it is "make:" or "make-" followed by a make test, or any of the special
415 # test names as a single word.
416 define ParseSpecialTestSelection
417 $(if $(filter special:%, $1), \
418 $1 \
419 ) \
420 $(if $(filter make%, $1), \
421 $(if $(filter make:%, $1), \
422 special:$(strip $1) \
423 ) \
424 $(if $(filter make-%, $1), \
425 special:$(patsubst make-%,make:%, $1) \
426 ) \
427 $(if $(filter make, $1), \
428 special:make:all \
429 )
430 ) \
431 $(if $(filter failure-handler, $1), \
432 special:$(strip $1) \
433 )
434 endef
435
436 ifeq ($(TEST), )
437 $(info No test selection given in TEST!)
438 $(info Please use e.g. 'make test TEST=tier1' or 'make test-tier1')
439 $(info See doc/testing.[md|html] for help)
440 $(error Cannot continue)
441 endif
442
443 ParseTestSelection = \
444 $(strip $(or \
445 $(call ParseCustomTestSelection, $1) \
446 $(call ParseGtestTestSelection, $1) \
447 $(call ParseMicroTestSelection, $1) \
448 $(call ParseJtregTestSelection, $1) \
449 $(call ParseSpecialTestSelection, $1) \
450 ))
451
452 # Now intelligently convert the test selection given by the user in TEST
453 # into a list of fully qualified test descriptors of the tests to run.
454 TESTS_TO_RUN := $(strip $(foreach test, $(TEST), $(call ParseTestSelection, $(test))))
455 UNKNOWN_TEST := $(strip $(foreach test, $(TEST), $(if $(call ParseTestSelection, $(test)), , $(test))))
456
457 ifneq ($(UNKNOWN_TEST), )
458 $(info Unknown test selection: '$(UNKNOWN_TEST)')
459 $(info See doc/testing.[md|html] for help)
460 $(error Cannot continue)
461 endif
462
463 # Present the result of our parsing to the user
464 $(info Test selection '$(TEST)', will run:)
465 $(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
466
467
468 ################################################################################
469 # Functions for setting up rules for running the selected tests
470 #
471 # The SetupRun*Test functions all have the same interface:
472 #
473 # Parameter 1 is the name of the rule. This is the test id, based on the test
474 # descriptor, and this is also used as variable prefix, and the targets
475 # generated are listed in a variable by that name.
476 #
477 # Remaining parameters are named arguments. Currently this is only:
478 # TEST -- The properly formatted fully qualified test descriptor
479 #
480 # After the rule named by the test id has been executed, the following
481 # variables will be available:
482 # testid_TOTAL - the total number of tests run
483 # testid_PASSED - the number of successful tests
484 # testid_FAILED - the number of failed tests
485 # testid_ERROR - the number of tests was neither successful or failed
486 #
487 ################################################################################
488
489 ### Rules for Gtest
490
491 SetupRunGtestTest = $(NamedParamsMacroTemplate)
492 define SetupRunGtestTestBody
493 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
494 $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
495 $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
496
497 $1_VARIANT := $$(lastword $$(subst /, , $$($1_TEST)))
498 ifeq ($$(filter $$($1_VARIANT), $$(GTEST_VARIANTS)), )
499 $$(error Invalid gtest variant '$$($1_VARIANT)'. Valid variants: $$(GTEST_VARIANTS))
500 endif
501 $1_TEST_NAME := $$(strip $$(patsubst %/$$($1_VARIANT), %, \
502 $$(patsubst gtest:%, %, $$($1_TEST))))
503 ifneq ($$($1_TEST_NAME), all)
504 $1_GTEST_FILTER := --gtest_filter=$$($1_TEST_NAME)*
505 endif
506
507 ifneq ($$(GTEST_REPEAT), )
508 $1_GTEST_REPEAT := --gtest_repeat=$$(GTEST_REPEAT)
509 endif
510
511 run-test-$1: pre-run-test
512 $$(call LogWarn)
513 $$(call LogWarn, Running test '$$($1_TEST)')
514 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
515 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/gtest, \
516 $$(CD) $$($1_TEST_SUPPORT_DIR) && \
517 $$(FIXPATH) $$(TEST_IMAGE_DIR)/hotspot/gtest/$$($1_VARIANT)/gtestLauncher \
518 -jdk $(JDK_UNDER_TEST) $$($1_GTEST_FILTER) \
519 --gtest_output=xml:$$($1_TEST_RESULTS_DIR)/gtest.xml \
520 --gtest_catch_exceptions=0 \
521 $$($1_GTEST_REPEAT) $$(GTEST_OPTIONS) $$(GTEST_VM_OPTIONS) \
522 $$(GTEST_JAVA_OPTIONS) \
523 > >($(TEE) $$($1_TEST_RESULTS_DIR)/gtest.txt) \
524 && $$(ECHO) $$$$? > $$($1_EXITCODE) \
525 || $$(ECHO) $$$$? > $$($1_EXITCODE) \
526 )
527
528 $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/gtest.txt
529
530 parse-test-$1: run-test-$1
531 $$(call LogWarn, Finished running test '$$($1_TEST)')
532 $$(call LogWarn, Test report is stored in $$(strip \
533 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
534 $$(if $$(wildcard $$($1_RESULT_FILE)), \
535 $$(eval $1_RUN := $$(shell $$(AWK) \
536 '/==========.* tests? from .* test (cases?|suites?) ran/ { print $$$$2 }' \
537 $$($1_RESULT_FILE))) \
538 $$(if $$($1_RUN), , $$(eval $1_RUN := 0)) \
539 $$(eval $1_PASSED := $$(shell $$(AWK) '/\[ PASSED \] .* tests?./ \
540 { print $$$$4 }' $$($1_RESULT_FILE))) \
541 $$(if $$($1_PASSED), , $$(eval $1_PASSED := 0)) \
542 $$(eval $1_GTEST_DISABLED := $$(shell $$(AWK) '/YOU HAVE .* DISABLED TEST/ \
543 { print $$$$3 }' $$($1_RESULT_FILE))) \
544 $$(if $$($1_GTEST_DISABLED), , $$(eval $1_GTEST_DISABLED := 0)) \
545 $$(eval $1_GTEST_SKIPPED := $$(shell $$(AWK) '/\[ SKIPPED \] .* tests?.*/ \
546 { print $$$$4 }' $$($1_RESULT_FILE))) \
547 $$(if $$($1_GTEST_SKIPPED), , $$(eval $1_GTEST_SKIPPED := 0)) \
548 $$(eval $1_SKIPPED := $$(shell \
549 $$(EXPR) $$($1_GTEST_DISABLED) + $$($1_GTEST_SKIPPED))) \
550 $$(eval $1_FAILED := $$(shell $$(AWK) '/\[ FAILED \] .* tests?, \
551 listed below/ { print $$$$4 }' $$($1_RESULT_FILE))) \
552 $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
553 $$(eval $1_ERROR := $$(shell \
554 $$(EXPR) $$($1_RUN) - $$($1_PASSED) - $$($1_FAILED) - $$($1_GTEST_SKIPPED))) \
555 $$(eval $1_TOTAL := $$(shell \
556 $$(EXPR) $$($1_RUN) + $$($1_GTEST_DISABLED))) \
557 , \
558 $$(eval $1_PASSED := 0) \
559 $$(eval $1_FAILED := 0) \
560 $$(eval $1_ERROR := 1) \
561 $$(eval $1_SKIPPED := 0) \
562 $$(eval $1_TOTAL := 1) \
563 )
564
565 $1: run-test-$1 parse-test-$1
566
567 TARGETS += $1 run-test-$1 parse-test-$1
568 TEST_TARGETS += parse-test-$1
569
570 endef
571
572 ################################################################################
573
574 ### Rules for Microbenchmarks
575
576 # Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order:
577 # 1) Specified by user on command line
578 # 2) Generic default
579 #
580 # Note: No spaces are allowed around the arguments.
581 # Arg $1 The test ID (i.e. $1 in SetupRunMicroTest)
582 # Arg $2 Base variable, e.g. MICRO_TEST_JDK
583 # Arg $3 The default value (optional)
584 define SetMicroValue
585 ifneq ($$($2), )
586 $1_$2 := $$($2)
587 else
588 ifneq ($3, )
589 $1_$2 := $3
590 else
591 $1_$2 :=
592 endif
593 endif
594 endef
595
596 SetupRunMicroTest = $(NamedParamsMacroTemplate)
597 define SetupRunMicroTestBody
598 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
599 $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
600 $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
601
602 $1_TEST_NAME := $$(strip $$(patsubst micro:%, %, $$($1_TEST)))
603
604 $$(eval $$(call SetMicroValue,$1,MICRO_BENCHMARKS_JAR,$$(TEST_IMAGE_DIR)/micro/benchmarks.jar))
605 $$(eval $$(call SetMicroValue,$1,MICRO_TEST_JDK,$$(JDK_UNDER_TEST)))
606 $$(eval $$(call SetMicroValue,$1,MICRO_JAVA_OPTIONS))
607
608 # Current tests needs to open java.io
609 $1_MICRO_JAVA_OPTIONS += --add-opens=java.base/java.io=ALL-UNNAMED
610
611 # Save output as JSON or CSV file
612 ifneq ($$(MICRO_RESULTS_FORMAT), )
613 $1_MICRO_BASIC_OPTIONS += -rf $$(MICRO_RESULTS_FORMAT)
614 $1_MICRO_BASIC_OPTIONS += -rff $$($1_TEST_RESULTS_DIR)/jmh-result.$(MICRO_RESULTS_FORMAT)
615 endif
616
617 # Set library path for native dependencies
618 $1_JMH_JVM_ARGS := -Djava.library.path=$$(TEST_IMAGE_DIR)/micro/native
619
620 ifneq ($$(MICRO_VM_OPTIONS)$$(MICRO_JAVA_OPTIONS), )
621 $1_JMH_JVM_ARGS += $$(MICRO_VM_OPTIONS) $$(MICRO_JAVA_OPTIONS)
622 endif
623
624 $1_MICRO_VM_OPTIONS := -jvmArgsPrepend $(call ShellQuote,$$($1_JMH_JVM_ARGS))
625
626 ifneq ($$(MICRO_ITER), )
627 $1_MICRO_ITER := -i $$(MICRO_ITER)
628 endif
629 ifneq ($$(MICRO_FORK), )
630 $1_MICRO_FORK := -f $$(MICRO_FORK)
631 endif
632 ifneq ($$(MICRO_TIME), )
633 $1_MICRO_TIME := -r $$(MICRO_TIME)
634 endif
635 ifneq ($$(MICRO_WARMUP_ITER), )
636 $1_MICRO_WARMUP_ITER := -wi $$(MICRO_WARMUP_ITER)
637 endif
638 ifneq ($$(MICRO_WARMUP_TIME), )
639 $1_MICRO_WARMUP_TIME := -w $$(MICRO_WARMUP_TIME)
640 endif
641
642 # Microbenchmarks are executed from the root of the test image directory.
643 # This enables JMH tests to add dependencies using relative paths such as
644 # -Djava.library.path=micro/native
645
646 run-test-$1: pre-run-test
647 $$(call LogWarn)
648 $$(call LogWarn, Running test '$$($1_TEST)')
649 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
650 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/micro, \
651 $$(CD) $$(TEST_IMAGE_DIR) && \
652 $$(FIXPATH) $$($1_MICRO_TEST_JDK)/bin/java $$($1_MICRO_JAVA_OPTIONS) \
653 -jar $$($1_MICRO_BENCHMARKS_JAR) \
654 $$($1_MICRO_ITER) $$($1_MICRO_FORK) $$($1_MICRO_TIME) \
655 $$($1_MICRO_WARMUP_ITER) $$($1_MICRO_WARMUP_TIME) \
656 $$($1_MICRO_VM_OPTIONS) $$($1_MICRO_BASIC_OPTIONS) $$(MICRO_OPTIONS) \
657 $$($1_TEST_NAME) \
658 > >($(TEE) $$($1_TEST_RESULTS_DIR)/micro.txt) \
659 && $$(ECHO) $$$$? > $$($1_EXITCODE) \
660 || $$(ECHO) $$$$? > $$($1_EXITCODE) \
661 )
662
663 $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/micro.txt
664
665 parse-test-$1: run-test-$1
666 $$(call LogWarn, Finished running test '$$($1_TEST)')
667 $$(call LogWarn, Test report is stored in $$(strip \
668 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
669 $$(if $$(wildcard $$($1_EXITCODE)), \
670 $$(eval $1_EXIT_CODE := $$(shell $$(CAT) $$($1_EXITCODE))) \
671 $$(if $$(filter 0, $$($1_EXIT_CODE)), \
672 $$(eval $1_PASSED := 1) \
673 $$(eval $1_ERROR := 0) \
674 , \
675 $$(eval $1_PASSED := 0) \
676 $$(eval $1_ERROR := 1) \
677 ) \
678 $$(eval $1_FAILED := 0) \
679 $$(eval $1_TOTAL := $$(shell \
680 $$(EXPR) $$($1_PASSED) + $$($1_ERROR))) \
681 , \
682 $$(eval $1_PASSED := 0) \
683 $$(eval $1_FAILED := 0) \
684 $$(eval $1_ERROR := 1) \
685 $$(eval $1_TOTAL := 1) \
686 )
687 $$(eval $1_SKIPPED := 0)
688
689 $1: run-test-$1 parse-test-$1
690
691 TARGETS += $1 run-test-$1 parse-test-$1
692 TEST_TARGETS += parse-test-$1
693
694 endef
695
696 ################################################################################
697
698 ### Rules for Jtreg
699
700 # Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order:
701 # 1) Specified by user on command line
702 # 2) Component-specific default
703 # 3) Generic default
704 #
705 # Note: No spaces are allowed around the arguments.
706 # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest)
707 # Arg $2 Base variable, e.g. JTREG_JOBS
708 # Arg $3 The default value (optional)
709 define SetJtregValue
710 ifneq ($$($2), )
711 $1_$2 := $$($2)
712 else
713 ifneq ($$($$($1_COMPONENT)_$2), )
714 $1_$2 := $$($$($1_COMPONENT)_$2)
715 else
716 ifneq ($3, )
717 $1_$2 := $3
718 else
719 $1_$2 :=
720 endif
721 endif
722 endif
723 endef
724
725 ################################################################################
726 # Helper function for creating a customized AOT cache for running tests
727 ################################################################################
728
729 # Parameter 1 is the name of the rule.
730 #
731 # Remaining parameters are named arguments.
732 # TRAINING The AOT training mode: onestep or twostep
733 # VM_OPTIONS List of JVM arguments to use when creating AOT cache
734 #
735 # After calling this, the following variables are defined
736 # $1_AOT_TARGETS List of all targets that the test rule will need to depend on
737 # $1_AOT_JDK_CACHE The AOT cache file to be used to run the test with
738 #
739 SetupAOT = $(NamedParamsMacroTemplate)
740 define SetupAOTBody
741 $1_AOT_JDK_OUTPUT_DIR := $$($1_TEST_SUPPORT_DIR)/aot
742 $1_AOT_JDK_CONF := $$($1_AOT_JDK_OUTPUT_DIR)/jdk.aotconf
743 $1_AOT_JDK_CACHE := $$($1_AOT_JDK_OUTPUT_DIR)/jdk.aotcache
744 $1_AOT_JDK_LOG := $$($1_AOT_JDK_OUTPUT_DIR)/TestSetupAOT.log
745
746 # We execute the training run with the TestSetupAOT class from $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.jar
747 # to touch a fair number of classes inside the JDK. Note that we can't specify a classpath,
748 # or else the AOT cache cannot be used with jtreg test cases that use a different value
749 # for their classpaths. Instead, we cd in the $$($1_AOT_JDK_OUTPUT_DIR) directory,
750 # extract the TestSetupAOT.jar there, and run in that directory without specifying a classpath.
751 # The "java" launcher will have an implicit classpath of ".", so it can pick up the TestSetupAOT
752 # class from the JVM's current directory.
753 #
754 # The TestSetupAOT class (or any other classes that are loaded from ".") will be excluded
755 # from the the AOT cache as "." is an unsupported location. As a result, the AOT cache will contain
756 # only classes from the JDK.
757
758 $$($1_AOT_JDK_CACHE): $$(JDK_IMAGE_DIR)/release
759 $$(call MakeDir, $$($1_AOT_JDK_OUTPUT_DIR))
760
761 ifeq ($$($1_TRAINING), onestep)
762
763 $$(call LogWarn, AOT: Create AOT cache $$($1_AOT_JDK_CACHE) in one step with flags: $$($1_VM_OPTIONS)) \
764 $$(call ExecuteWithLog, $$($1_AOT_JDK_OUTPUT_DIR), \
765 cd $$($1_AOT_JDK_OUTPUT_DIR); \
766 $(JAR) --extract --file $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.jar; \
767 $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java $$($1_VM_OPTIONS) \
768 -Xlog:class+load$$(COMMA)aot$$(COMMA)aot+class=debug:file=$$($1_AOT_JDK_CACHE).log -Xlog:cds*=error -Xlog:aot*=error \
769 -XX:AOTMode=record -XX:AOTCacheOutput=$$($1_AOT_JDK_CACHE) \
770 TestSetupAOT $$($1_AOT_JDK_OUTPUT_DIR) > $$($1_AOT_JDK_LOG) \
771 )
772
773 else
774
775 $$(call LogWarn, AOT: Create cache configuration) \
776 $$(call ExecuteWithLog, $$($1_AOT_JDK_OUTPUT_DIR), \
777 cd $$($1_AOT_JDK_OUTPUT_DIR); \
778 $(JAR) --extract --file $(TEST_IMAGE_DIR)/setup_aot/TestSetupAOT.jar; \
779 $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java $$($1_VM_OPTIONS) \
780 -Xlog:class+load$$(COMMA)aot$$(COMMA)aot+class=debug:file=$$($1_AOT_JDK_CONF).log -Xlog:cds*=error -Xlog:aot*=error \
781 -XX:AOTMode=record -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) \
782 TestSetupAOT $$($1_AOT_JDK_OUTPUT_DIR) > $$($1_AOT_JDK_LOG) \
783 )
784
785 $$(call LogWarn, AOT: Generate AOT cache $$($1_AOT_JDK_CACHE) with flags: $$($1_VM_OPTIONS))
786 $$(call ExecuteWithLog, $$($1_AOT_JDK_OUTPUT_DIR), \
787 $$(FIXPATH) $(JDK_UNDER_TEST)/bin/java \
788 $$($1_VM_OPTIONS) -Xlog:aot$$(COMMA)aot+class=debug:file=$$($1_AOT_JDK_CACHE).log -Xlog:cds*=error -Xlog:aot*=error \
789 -XX:ExtraSharedClassListFile=$(JDK_UNDER_TEST)/lib/classlist \
790 -XX:AOTMode=create -XX:AOTConfiguration=$$($1_AOT_JDK_CONF) -XX:AOTCache=$$($1_AOT_JDK_CACHE) \
791 )
792
793 endif
794
795 $1_AOT_TARGETS += $$($1_AOT_JDK_CACHE)
796
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,768m))
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 # Pass along the path to the tidy html checker
838 ifneq ($$(TIDY), )
839 $1_JTREG_BASIC_OPTIONS += -Dtidy=$$(TIDY)
840 endif
841
842 ifneq ($(TEST_JOBS), 0)
843 $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(TEST_JOBS)))
844 else
845 $$(eval $$(call SetJtregValue,$1,JTREG_JOBS,$$(JOBS)))
846 endif
847
848 # Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since
849 # we may end up with a lot of JVM's
850 $1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $(AWK) 'BEGIN { print 25 / $$($1_JTREG_JOBS); }')
851
852 JTREG_VERBOSE ?= fail,error,summary
853 JTREG_RETAIN ?= fail,error
854 JTREG_TEST_THREAD_FACTORY ?=
855 JTREG_RUN_PROBLEM_LISTS ?= false
856 JTREG_RETRY_COUNT ?= 0
857 JTREG_REPEAT_COUNT ?= 0
858 JTREG_REPORT ?= files
859 JTREG_AOT_JDK ?= none
860
861 ifneq ($$(JTREG_RETRY_COUNT), 0)
862 ifneq ($$(JTREG_REPEAT_COUNT), 0)
863 $$(info Error: Cannot use both JTREG_RETRY_COUNT and JTREG_REPEAT_COUNT together.)
864 $$(info Please choose one or the other.)
865 $$(error Cannot continue)
866 endif
867 endif
868
869 ifeq ($$(JTREG_RUN_PROBLEM_LISTS), true)
870 JTREG_PROBLEM_LIST_PREFIX := -match:
871 else
872 JTREG_PROBLEM_LIST_PREFIX := -exclude:
873 endif
874
875 ifneq ($$(JTREG_TEST_THREAD_FACTORY), )
876 $1_JTREG_BASIC_OPTIONS += -testThreadFactoryPath:$$(JTREG_TEST_THREAD_FACTORY_JAR)
877 $1_JTREG_BASIC_OPTIONS += -testThreadFactory:$$(JTREG_TEST_THREAD_FACTORY)
878 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
879 $$(addprefix $$($1_TEST_ROOT)/, ProblemList-$$(JTREG_TEST_THREAD_FACTORY).txt) \
880 ))
881 endif
882
883 ifneq ($$(JTREG_VALUE_CLASS_PLUGIN), )
884 ifneq ($$(wildcard $$(JTREG_VALUE_CLASS_PLUGIN_JAR)), )
885 $1_JTREG_BASIC_OPTIONS += -cpa:$$(JTREG_VALUE_CLASS_PLUGIN_JAR)
886 endif
887 $1_JTREG_BASIC_OPTIONS += -vmoption:--enable-preview
888 $1_JTREG_BASIC_OPTIONS += -javacoption:-XDaccessInternalAPI
889 $1_JTREG_BASIC_OPTIONS += -javacoption:--source -javacoption:$(VERSION_FEATURE)
890 $1_JTREG_BASIC_OPTIONS += -javacoption:--enable-preview
891 $1_JTREG_BASIC_OPTIONS += -javacoption:-Xplugin:ValueClassPlugin
892 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
893 $$(addprefix $$($1_TEST_ROOT)/, ProblemList-ValueClass.txt) \
894 ))
895 endif
896
897 ifneq ($$(JTREG_JVMTI_STRESS_AGENT), )
898 AGENT := $$(LIBRARY_PREFIX)JvmtiStressAgent$$(SHARED_LIBRARY_SUFFIX)=$$(JTREG_JVMTI_STRESS_AGENT)
899 $1_JTREG_BASIC_OPTIONS += -javaoption:'-agentpath:$(TEST_IMAGE_DIR)/hotspot/jtreg/native/$$(AGENT)'
900 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
901 $$(addprefix $$($1_TEST_ROOT)/, ProblemList-jvmti-stress-agent.txt) \
902 ))
903 endif
904
905
906 ifneq ($$(JTREG_LAUNCHER_OPTIONS), )
907 $1_JTREG_LAUNCHER_OPTIONS += $$(JTREG_LAUNCHER_OPTIONS)
908 endif
909
910 ifneq ($$(JTREG_MAX_OUTPUT), )
911 $1_JTREG_LAUNCHER_OPTIONS += -Djavatest.maxOutputSize=$$(JTREG_MAX_OUTPUT)
912 endif
913
914 ifneq ($$($1_JTREG_MAX_MEM), 0)
915 $1_JTREG_BASIC_OPTIONS += -vmoption:-Xmx$$($1_JTREG_MAX_MEM)
916 $1_JTREG_LAUNCHER_OPTIONS += -Xmx$$($1_JTREG_MAX_MEM)
917 endif
918
919 # Make sure the tmp dir is normalized as some tests will react badly otherwise
920 $1_TEST_TMP_DIR := $$(abspath $$($1_TEST_SUPPORT_DIR)/tmp)
921
922 # test.boot.jdk is used by some test cases that want to execute a previous
923 # version of the JDK.
924 $1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
925 -verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
926 -concurrency:$$($1_JTREG_JOBS) \
927 -vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE) \
928 -vmoption:-Dtest.boot.jdk="$$(BOOT_JDK)" \
929 -vmoption:-Djava.io.tmpdir="$$($1_TEST_TMP_DIR)"
930
931 $1_JTREG_BASIC_OPTIONS += -ignore:quiet
932
933 ifeq ($$(JTREG_MANUAL), true)
934 $1_JTREG_BASIC_OPTIONS += -manual
935 else
936 $1_JTREG_BASIC_OPTIONS += -automatic
937 endif
938
939 # Make it possible to specify the JIB_DATA_DIR for tests using the
940 # JIB Artifact resolver
941 $1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR
942 # If running on Windows, propagate the _NT_SYMBOL_PATH to enable
943 # symbol lookup in hserr files
944 # The minidumps are disabled by default on client Windows, so enable them
945 ifeq ($$(call isTargetOs, windows), true)
946 $1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH
947 $1_JTREG_BASIC_OPTIONS += -vmoption:-XX:+CreateCoredumpOnCrash
948 else ifeq ($$(call isTargetOs, linux), true)
949 $1_JTREG_BASIC_OPTIONS += -e:_JVM_DWARF_PATH=$$(SYMBOLS_IMAGE_DIR)
950 endif
951
952 $1_JTREG_BASIC_OPTIONS += \
953 $$(addprefix -javaoption:, $$(JTREG_JAVA_OPTIONS)) \
954 $$(addprefix -vmoption:, $$(JTREG_VM_OPTIONS)) \
955 #
956
957 ifeq ($$($1_JTREG_ASSERT), true)
958 $1_JTREG_BASIC_OPTIONS += -ea -esa
959 endif
960
961 ifneq ($$($1_JTREG_NATIVEPATH), )
962 $1_JTREG_BASIC_OPTIONS += -nativepath:$$($1_JTREG_NATIVEPATH)
963 endif
964
965 ifneq ($$($1_JTREG_PROBLEM_LIST), )
966 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$($1_JTREG_PROBLEM_LIST))
967 endif
968
969 JTREG_ALL_OPTIONS := $$(JTREG_JAVA_OPTIONS) $$(JTREG_VM_OPTIONS)
970
971 JTREG_AUTO_PROBLEM_LISTS :=
972 # Please reach consensus before changing this.
973 JTREG_AUTO_TIMEOUT_FACTOR := 4
974
975 ifneq ($$(findstring -Xcomp, $$(JTREG_ALL_OPTIONS)), )
976 JTREG_AUTO_PROBLEM_LISTS += ProblemList-Xcomp.txt
977 JTREG_AUTO_TIMEOUT_FACTOR := 10
978 endif
979
980 ifneq ($$(findstring -XX:+UseZGC, $$(JTREG_ALL_OPTIONS)), )
981 JTREG_AUTO_PROBLEM_LISTS += ProblemList-zgc.txt
982 endif
983
984 ifneq ($$(findstring -XX:+UseShenandoahGC, $$(JTREG_ALL_OPTIONS)), )
985 JTREG_AUTO_PROBLEM_LISTS += ProblemList-shenandoah.txt
986 endif
987
988 ifneq ($$(findstring --enable-preview, $$(JTREG_ALL_OPTIONS)), )
989 JTREG_AUTO_PROBLEM_LISTS += ProblemList-enable-preview.txt
990 endif
991
992 ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), )
993 # Accept both absolute paths as well as relative to the current test root.
994 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
995 $$(JTREG_EXTRA_PROBLEM_LISTS) \
996 $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
997 ))
998 endif
999
1000 ifneq ($$(JIB_HOME), )
1001 $1_JTREG_BASIC_OPTIONS += -e:JIB_HOME=$$(JIB_HOME)
1002 endif
1003
1004 ifneq ($$(JDK_FOR_COMPILE), )
1005 # Allow overriding the JDK used for compilation from the command line
1006 $1_JTREG_BASIC_OPTIONS += -compilejdk:$$(JDK_FOR_COMPILE)
1007 endif
1008
1009 $1_JTREG_BASIC_OPTIONS += -e:TEST_IMAGE_DIR=$(TEST_IMAGE_DIR)
1010
1011 $1_JTREG_BASIC_OPTIONS += -e:DOCS_JDK_IMAGE_DIR=$$(DOCS_JDK_IMAGE_DIR)
1012
1013 ifneq ($$(JTREG_FAILURE_HANDLER_OPTIONS), )
1014 $1_JTREG_LAUNCHER_OPTIONS += -Djava.library.path="$(JTREG_FAILURE_HANDLER_DIR)"
1015 endif
1016
1017 ifneq ($$(JTREG_KEYWORDS), )
1018 # The keywords string may contain problematic characters and may be quoted
1019 # already when it arrives here. Remove any existing quotes and replace them
1020 # with one set of single quotes.
1021 $1_JTREG_KEYWORDS := \
1022 $$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS))))
1023 ifneq ($$($1_JTREG_KEYWORDS), )
1024 $1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)'
1025 endif
1026 endif
1027
1028 ifneq ($$(filter $$(JTREG_AOT_JDK), onestep twostep), )
1029 $$(call LogWarn, Add AOT target for $1)
1030 $$(eval $$(call SetupAOT, $1, \
1031 TRAINING := $$(JTREG_AOT_JDK), \
1032 VM_OPTIONS := $$(JTREG_ALL_OPTIONS) ))
1033 $$(call LogWarn, AOT_JDK_CACHE=$$($1_AOT_JDK_CACHE))
1034 $1_JTREG_BASIC_OPTIONS += -vmoption:-XX:AOTCache="$$($1_AOT_JDK_CACHE)"
1035 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
1036 $$(addprefix $$($1_TEST_ROOT)/, ProblemList-AotJdk.txt) \
1037 ))
1038 endif
1039
1040
1041 $$(eval $$(call SetupRunJtregTestCustom, $1))
1042
1043 # SetupRunJtregTestCustom might also adjust JTREG_AUTO_ variables
1044 # so set the final results after setting values from custom setup
1045 ifneq ($$(JTREG_AUTO_PROBLEM_LISTS), )
1046 # Accept both absolute paths as well as relative to the current test root.
1047 $1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
1048 $$(JTREG_AUTO_PROBLEM_LISTS) \
1049 $$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_AUTO_PROBLEM_LISTS)) \
1050 ))
1051 endif
1052
1053 JTREG_TIMEOUT_FACTOR ?= $$(JTREG_AUTO_TIMEOUT_FACTOR)
1054 $1_JTREG_BASIC_OPTIONS += -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR)
1055
1056 clean-outputdirs-$1:
1057 $$(call LogWarn, Clean up dirs for $1)
1058 $$(RM) -r $$($1_TEST_SUPPORT_DIR)
1059 $$(RM) -r $$($1_TEST_RESULTS_DIR)
1060
1061 $1_COMMAND_LINE := \
1062 $$(JTREG_JAVA) $$($1_JTREG_LAUNCHER_OPTIONS) \
1063 -Dprogram=jtreg -jar $$(JT_HOME)/lib/jtreg.jar \
1064 $$($1_JTREG_BASIC_OPTIONS) \
1065 -testjdk:$$(JDK_UNDER_TEST) \
1066 -dir:$$(JTREG_TOPDIR) \
1067 -reportDir:$$($1_TEST_RESULTS_DIR) \
1068 -workDir:$$($1_TEST_SUPPORT_DIR) \
1069 -report:$${JTREG_REPORT} \
1070 $$$${JTREG_STATUS} \
1071 $$(JTREG_OPTIONS) \
1072 $$(JTREG_FAILURE_HANDLER_OPTIONS) \
1073 $$(JTREG_COV_OPTIONS) \
1074 $$($1_TEST_NAME) \
1075 && $$(ECHO) $$$$? > $$($1_EXITCODE) \
1076 || $$(ECHO) $$$$? > $$($1_EXITCODE)
1077
1078
1079 ifneq ($$(JTREG_RETRY_COUNT), 0)
1080 $1_COMMAND_LINE := \
1081 for i in {0..$$(JTREG_RETRY_COUNT)}; do \
1082 if [ "$$$$i" != 0 ]; then \
1083 $$(ECHO) ""; \
1084 $$(ECHO) "Retrying Jtreg run. Attempt: $$$$i"; \
1085 fi; \
1086 $$($1_COMMAND_LINE); \
1087 if [ "`$$(CAT) $$($1_EXITCODE)`" = "0" ]; then \
1088 break; \
1089 fi; \
1090 export JTREG_STATUS="-status:error,fail"; \
1091 done
1092 endif
1093
1094 ifneq ($$(JTREG_REPEAT_COUNT), 0)
1095 $1_COMMAND_LINE := \
1096 for i in {1..$$(JTREG_REPEAT_COUNT)}; do \
1097 $$(ECHO) ""; \
1098 $$(ECHO) "Repeating Jtreg run: $$$$i out of $$(JTREG_REPEAT_COUNT)"; \
1099 $$($1_COMMAND_LINE); \
1100 if [ "`$$(CAT) $$($1_EXITCODE)`" != "0" ]; then \
1101 $$(ECHO) ""; \
1102 $$(ECHO) "Failures detected, no more repeats."; \
1103 break; \
1104 fi; \
1105 done
1106 endif
1107
1108 run-test-$1: clean-outputdirs-$1 pre-run-test $$($1_AOT_TARGETS)
1109 $$(call LogWarn)
1110 $$(call LogWarn, Running test '$$($1_TEST)')
1111 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR) \
1112 $$($1_TEST_TMP_DIR))
1113 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/jtreg, \
1114 $$(COV_ENVIRONMENT) $$($1_COMMAND_LINE) \
1115 )
1116
1117 $1_RESULT_FILE := $$($1_TEST_RESULTS_DIR)/text/stats.txt
1118
1119 parse-test-$1: run-test-$1
1120 $$(call LogWarn, Finished running test '$$($1_TEST)')
1121 $$(call LogWarn, Test report is stored in $$(strip \
1122 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
1123
1124 # Read jtreg documentation to learn on the test stats categories:
1125 # https://github.com/openjdk/jtreg/blob/master/src/share/doc/javatest/regtest/faq.md#what-do-all-those-numbers-in-the-test-results-line-mean
1126 # In jtreg, "skipped:" category accounts for tests that threw jtreg.SkippedException at runtime.
1127 # At the same time these tests contribute to "passed:" tests.
1128 # In here we don't want that and so we substract number of "skipped:" from "passed:".
1129
1130 $$(if $$(wildcard $$($1_RESULT_FILE)), \
1131 $$(eval $1_PASSED_AND_RUNTIME_SKIPPED := $$(shell $$(AWK) '{ gsub(/[,;]/, ""); \
1132 for (i=1; i<=NF; i++) { if ($$$$i == "passed:") \
1133 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
1134 $$(if $$($1_PASSED_AND_RUNTIME_SKIPPED), , $$(eval $1_PASSED_AND_RUNTIME_SKIPPED := 0)) \
1135 $$(eval $1_FAILED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
1136 for (i=1; i<=NF; i++) { if ($$$$i == "failed:") \
1137 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
1138 $$(if $$($1_FAILED), , $$(eval $1_FAILED := 0)) \
1139 $$(eval $1_RUNTIME_SKIPPED := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
1140 for (i=1; i<=NF; i++) { if ($$$$i == "skipped:") \
1141 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
1142 $$(if $$($1_RUNTIME_SKIPPED), , $$(eval $1_RUNTIME_SKIPPED := 0)) \
1143 $$(eval $1_SKIPPED := $$(shell \
1144 $$(AWK) \
1145 'BEGIN { \
1146 overall_skipped = 0; \
1147 patterns[1] = "skipped"; \
1148 patterns[2] = "excluded"; \
1149 patterns[3] = "not in match-list"; \
1150 patterns[4] = "did not match keywords"; \
1151 patterns[5] = "did not meet module requirements"; \
1152 patterns[6] = "did not meet platform requirements"; \
1153 patterns[7] = "did not match prior status"; \
1154 patterns[8] = "did not meet time-limit requirements"; \
1155 } { \
1156 split($$$$0, arr, ";"); \
1157 for (item in arr) { \
1158 for (p in patterns) { \
1159 if (match(arr[item], patterns[p] ": [0-9]+")) { \
1160 overall_skipped += substr(arr[item], RSTART + length(patterns[p]) + 2, RLENGTH); \
1161 } \
1162 } \
1163 } \
1164 print overall_skipped; \
1165 }' \
1166 $$($1_RESULT_FILE) \
1167 )) \
1168 $$(eval $1_ERROR := $$(shell $$(AWK) '{gsub(/[,;]/, ""); \
1169 for (i=1; i<=NF; i++) { if ($$$$i == "error:") \
1170 print $$$$(i+1) } }' $$($1_RESULT_FILE))) \
1171 $$(if $$($1_ERROR), , $$(eval $1_ERROR := 0)) \
1172 \
1173 $$(eval $1_PASSED := $$(shell \
1174 $$(EXPR) $$($1_PASSED_AND_RUNTIME_SKIPPED) - $$($1_RUNTIME_SKIPPED))) \
1175 $$(eval $1_TOTAL := $$(shell \
1176 $$(EXPR) $$($1_PASSED) + $$($1_FAILED) + $$($1_ERROR) + $$($1_SKIPPED))) \
1177 , \
1178 $$(eval $1_PASSED_AND_RUNTIME_SKIPPED := 0) \
1179 $$(eval $1_PASSED := 0) \
1180 $$(eval $1_RUNTIME_SKIPPED := 0) \
1181 $$(eval $1_SKIPPED := 0) \
1182 $$(eval $1_FAILED := 0) \
1183 $$(eval $1_ERROR := 1) \
1184 $$(eval $1_TOTAL := 1) \
1185 )
1186
1187 $1: run-test-$1 parse-test-$1 clean-outputdirs-$1
1188
1189 TARGETS += $1 run-test-$1 parse-test-$1 clean-outputdirs-$1
1190 TEST_TARGETS += parse-test-$1
1191
1192 endef
1193
1194 ################################################################################
1195
1196 ### Rules for special tests
1197
1198 SetupRunSpecialTest = $(NamedParamsMacroTemplate)
1199 define SetupRunSpecialTestBody
1200 $1_TEST_RESULTS_DIR := $$(TEST_RESULTS_DIR)/$1
1201 $1_TEST_SUPPORT_DIR := $$(TEST_SUPPORT_DIR)/$1
1202 $1_EXITCODE := $$($1_TEST_RESULTS_DIR)/exitcode.txt
1203
1204 $1_FULL_TEST_NAME := $$(strip $$(patsubst special:%, %, $$($1_TEST)))
1205 ifneq ($$(findstring :, $$($1_FULL_TEST_NAME)), )
1206 $1_TEST_NAME := $$(firstword $$(subst :, ,$$($1_FULL_TEST_NAME)))
1207 $1_TEST_ARGS := $$(strip $$(patsubst special:$$($1_TEST_NAME):%, %, $$($1_TEST)))
1208 else
1209 $1_TEST_NAME := $$($1_FULL_TEST_NAME)
1210 $1_TEST_ARGS :=
1211 endif
1212
1213 ifeq ($$($1_TEST_NAME), failure-handler)
1214 ifeq ($(BUILD_FAILURE_HANDLER), true)
1215 $1_TEST_COMMAND_LINE := \
1216 ($(CD) $(TOPDIR)/make/test && $(MAKE) $(MAKE_ARGS) -f \
1217 BuildFailureHandler.gmk test)
1218 else
1219 $$(error Cannot test failure handler if it is not built)
1220 endif
1221 else ifeq ($$($1_TEST_NAME), make)
1222 $1_TEST_COMMAND_LINE := \
1223 ($(CD) $(TOPDIR)/test/make && $(MAKE) $(MAKE_ARGS) -f \
1224 TestMake.gmk $$($1_TEST_ARGS) TEST_SUPPORT_DIR="$$($1_TEST_SUPPORT_DIR)")
1225 else
1226 $$(error Invalid special test specification: $$($1_TEST_NAME))
1227 endif
1228
1229 run-test-$1: pre-run-test
1230 $$(call LogWarn)
1231 $$(call LogWarn, Running test '$$($1_TEST)')
1232 $$(call MakeDir, $$($1_TEST_RESULTS_DIR) $$($1_TEST_SUPPORT_DIR))
1233 $$(call ExecuteWithLog, $$($1_TEST_SUPPORT_DIR)/test-execution, \
1234 $$($1_TEST_COMMAND_LINE) \
1235 > >($(TEE) $$($1_TEST_RESULTS_DIR)/test-output.txt) \
1236 && $$(ECHO) $$$$? > $$($1_EXITCODE) \
1237 || $$(ECHO) $$$$? > $$($1_EXITCODE) \
1238 )
1239
1240 # We can not parse the various "special" tests.
1241 parse-test-$1: run-test-$1
1242 $$(call LogWarn, Finished running test '$$($1_TEST)')
1243 $$(call LogWarn, Test report is stored in $$(strip \
1244 $$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
1245 $$(call LogWarn, Warning: Special test results are not properly parsed!)
1246 $$(eval $1_PASSED := $$(shell \
1247 if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 1; else $(ECHO) 0; fi \
1248 ))
1249 $$(eval $1_SKIPPED := 0)
1250 $$(eval $1_FAILED := $$(shell \
1251 if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 0; else $(ECHO) 1; fi \
1252 ))
1253 $$(eval $1_ERROR := 0)
1254 $$(eval $1_TOTAL := 1)
1255
1256 $1: run-test-$1 parse-test-$1
1257
1258 TARGETS += $1 run-test-$1 parse-test-$1
1259 TEST_TARGETS += parse-test-$1
1260
1261 endef
1262
1263 ################################################################################
1264 # Setup and execute make rules for all selected tests
1265 ################################################################################
1266
1267 # Helper function to determine which handler to use for the given test
1268 UseGtestTestHandler = \
1269 $(if $(filter gtest:%, $1), true)
1270
1271 UseMicroTestHandler = \
1272 $(if $(filter micro:%, $1), true)
1273
1274 UseJtregTestHandler = \
1275 $(if $(filter jtreg:%, $1), true)
1276
1277 UseSpecialTestHandler = \
1278 $(if $(filter special:%, $1), true)
1279
1280 # Now process each test to run and setup a proper make rule
1281 $(foreach test, $(TESTS_TO_RUN), \
1282 $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1283 $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
1284 $(eval ALL_TEST_IDS += $(TEST_ID)) \
1285 $(if $(call UseCustomTestHandler, $(test)), \
1286 $(eval $(call SetupRunCustomTest, $(TEST_ID), \
1287 TEST := $(test), \
1288 )) \
1289 ) \
1290 $(if $(call UseGtestTestHandler, $(test)), \
1291 $(eval $(call SetupRunGtestTest, $(TEST_ID), \
1292 TEST := $(test), \
1293 )) \
1294 ) \
1295 $(if $(call UseMicroTestHandler, $(test)), \
1296 $(eval $(call SetupRunMicroTest, $(TEST_ID), \
1297 TEST := $(test), \
1298 )) \
1299 ) \
1300 $(if $(call UseJtregTestHandler, $(test)), \
1301 $(eval $(call SetupRunJtregTest, $(TEST_ID), \
1302 TEST := $(test), \
1303 )) \
1304 ) \
1305 $(if $(call UseSpecialTestHandler, $(test)), \
1306 $(eval $(call SetupRunSpecialTest, $(TEST_ID), \
1307 TEST := $(test), \
1308 )) \
1309 ) \
1310 )
1311
1312 # Sort also removes duplicates, so if there is any we'll get fewer words.
1313 ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
1314 $(error Duplicate test specification)
1315 endif
1316
1317
1318 ################################################################################
1319 # The main target for RunTests.gmk
1320 ################################################################################
1321
1322 #
1323 # Provide hooks for adding functionality before and after all tests are run.
1324 #
1325
1326 $(call LogInfo, RunTest setup starting)
1327
1328 # This target depends on all actual test having been run (TEST_TARGETS has beeen
1329 # populated by the SetupRun*Test functions). If you need to provide a teardown
1330 # hook, you must let it depend on this target.
1331 run-all-tests: $(TEST_TARGETS)
1332 $(call LogInfo, RunTest teardown starting)
1333
1334 # This is an abstract target that will be run before any actual tests. Add your
1335 # target as a dependency to thisif you need "setup" type functionality executed
1336 # before all tests.
1337 pre-run-test:
1338 $(call LogInfo, RunTest setup done)
1339
1340 # This is an abstract target that will be run after all actual tests, but before
1341 # the test summary. If you need "teardown" type functionality, add your target
1342 # as a dependency on this, and let the teardown target depend on run-all-tests.
1343 post-run-test: run-all-tests
1344 $(call LogInfo, RunTest teardown done)
1345
1346 #
1347 # Create and print a table of the result of all tests run
1348 #
1349 TEST_FAILURE := false
1350
1351 run-test-report: post-run-test
1352 $(RM) $(TEST_SUMMARY).old 2> /dev/null
1353 $(MV) $(TEST_SUMMARY) $(TEST_SUMMARY).old 2> /dev/null || true
1354 $(RM) $(TEST_LAST_IDS).old 2> /dev/null
1355 $(MV) $(TEST_LAST_IDS) $(TEST_LAST_IDS).old 2> /dev/null || true
1356 $(ECHO) >> $(TEST_SUMMARY) ==============================
1357 $(ECHO) >> $(TEST_SUMMARY) Test summary
1358 $(ECHO) >> $(TEST_SUMMARY) ==============================
1359 $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5s %5s %5s %5s %5s %2s\n" " " \
1360 TEST TOTAL PASS FAIL ERROR SKIP " "
1361 $(foreach test, $(TESTS_TO_RUN), \
1362 $(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
1363 $(TR) -cs '[a-z][A-Z][0-9]\n' '_')) \
1364 $(ECHO) >> $(TEST_LAST_IDS) $(TEST_ID) $(NEWLINE) \
1365 $(eval NAME_PATTERN := $(shell $(ECHO) $(test) | $(TR) -c '\n' '_')) \
1366 $(if $(filter __________________________________________________%, $(NAME_PATTERN)), \
1367 $(eval TEST_NAME := ) \
1368 $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s\n" " " "$(test)" $(NEWLINE) \
1369 , \
1370 $(eval TEST_NAME := $(test)) \
1371 ) \
1372 $(if $(filter-out 0, $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR)), \
1373 $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %5d %2s\n" \
1374 ">>" "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1375 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) $($(TEST_ID)_SKIPPED) "<<" $(NEWLINE) \
1376 $(eval TEST_FAILURE := true) \
1377 , \
1378 $(PRINTF) >> $(TEST_SUMMARY) "%2s %-49s %5d %5d %5d %5d %5d %2s\n" \
1379 " " "$(TEST_NAME)" $($(TEST_ID)_TOTAL) $($(TEST_ID)_PASSED) \
1380 $($(TEST_ID)_FAILED) $($(TEST_ID)_ERROR) $($(TEST_ID)_SKIPPED) " " $(NEWLINE) \
1381 ) \
1382 )
1383 $(ECHO) >> $(TEST_SUMMARY) ==============================
1384 $(if $(filter true, $(TEST_FAILURE)), \
1385 $(ECHO) >> $(TEST_SUMMARY) TEST FAILURE $(NEWLINE) \
1386 $(MKDIR) -p $(MAKESUPPORT_OUTPUTDIR) $(NEWLINE) \
1387 $(TOUCH) $(MAKESUPPORT_OUTPUTDIR)/exit-with-error \
1388 , \
1389 $(ECHO) >> $(TEST_SUMMARY) TEST SUCCESS \
1390 )
1391 $(ECHO)
1392 $(CAT) $(TEST_SUMMARY)
1393 $(ECHO)
1394
1395 # The main run-test target
1396 run-test: run-test-report
1397
1398 TARGETS += run-all-tests pre-run-test post-run-test run-test-report run-test
1399
1400 ################################################################################
1401 # Setup JCov
1402 ################################################################################
1403
1404 ifeq ($(TEST_OPTS_JCOV), true)
1405
1406 JCOV_VM_OPTS := -Xmx4g -Djdk.xml.totalEntitySizeLimit=0 -Djdk.xml.maxGeneralEntitySizeLimit=0
1407
1408 jcov-do-start-grabber:
1409 $(call MakeDir, $(JCOV_OUTPUT_DIR))
1410 if $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -status 1>/dev/null 2>&1 ; then \
1411 $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600 ; \
1412 fi
1413 $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar Grabber -v -t \
1414 $(JCOV_IMAGE_DIR)/template.xml -o $(JCOV_RESULT_FILE) \
1415 1>$(JCOV_GRABBER_LOG) 2>&1 &
1416
1417 jcov-start-grabber: jcov-do-start-grabber
1418 $(call LogWarn, Starting JCov Grabber...)
1419 $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -t 600 -wait
1420
1421 jcov-stop-grabber:
1422 $(call LogWarn, Stopping JCov Grabber...)
1423 $(JAVA) -jar $(JCOV_HOME)/lib/jcov.jar GrabberManager -stop -stoptimeout 3600
1424
1425 JCOV_REPORT_TITLE := JDK code coverage report<br/>
1426 ifneq ($(JCOV_MODULES), )
1427 JCOV_MODULES_FILTER := $(foreach m, $(JCOV_MODULES), -include_module $m)
1428 JCOV_REPORT_TITLE += Included modules: $(JCOV_MODULES)<br>
1429 endif
1430 ifneq ($(JCOV_FILTERS), )
1431 JCOV_REPORT_TITLE += Code filters: $(JCOV_FILTERS)<br>
1432 endif
1433 JCOV_REPORT_TITLE += Tests: $(TEST)
1434
1435 jcov-gen-report: jcov-stop-grabber
1436 $(call LogWarn, Generating JCov report ...)
1437 $(call ExecuteWithLog, $(JCOV_SUPPORT_DIR)/run-jcov-repgen, \
1438 $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar RepGen -sourcepath \
1439 `$(ECHO) $(TOPDIR)/src/*/share/classes/ | $(TR) ' ' ':'` -fmt html \
1440 $(JCOV_MODULES_FILTER) $(JCOV_FILTERS) \
1441 -mainReportTitle "$(JCOV_REPORT_TITLE)" \
1442 -o $(JCOV_REPORT) $(JCOV_RESULT_FILE))
1443
1444 TARGETS += jcov-do-start-grabber jcov-start-grabber jcov-stop-grabber \
1445 jcov-gen-report
1446
1447 ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1448
1449 JCOV_SOURCE_DIFF := $(JCOV_OUTPUT_DIR)/source_diff
1450 JCOV_DIFF_COVERAGE_REPORT := $(JCOV_OUTPUT_DIR)/diff_coverage_report
1451
1452 ifneq ($(and $(GIT), $(wildcard $(TOPDIR)/.git)), )
1453 DIFF_COMMAND := $(GIT) -C $(TOPDIR) diff $(TEST_OPTS_JCOV_DIFF_CHANGESET) > $(JCOV_SOURCE_DIFF)
1454 else
1455 $(info Error: Must be a git source tree for diff coverage.)
1456 $(error No git source tree.)
1457 endif
1458
1459 jcov-gen-diffcoverage: jcov-stop-grabber
1460 $(call LogWarn, Generating diff coverage with changeset $(TEST_OPTS_JCOV_DIFF_CHANGESET) ... )
1461 $(DIFF_COMMAND)
1462 $(JAVA) $(JCOV_VM_OPTS) -jar $(JCOV_HOME)/lib/jcov.jar \
1463 DiffCoverage -replaceDiff "src/.*/classes/:" -all \
1464 $(JCOV_RESULT_FILE) $(JCOV_SOURCE_DIFF) > \
1465 $(JCOV_DIFF_COVERAGE_REPORT)
1466
1467 TARGETS += jcov-gen-diffcoverage
1468
1469 endif
1470
1471 # Hook this into the framework at appropriate places
1472 pre-run-test: jcov-start-grabber
1473
1474 post-run-test: jcov-gen-report
1475
1476 ifneq ($(TEST_OPTS_JCOV_DIFF_CHANGESET), )
1477
1478 post-run-test: jcov-gen-diffcoverage
1479
1480 endif
1481
1482 jcov-stop-grabber: run-all-tests
1483
1484 endif
1485
1486 ################################################################################
1487
1488 all: run-test
1489
1490 .PHONY: $(TARGETS)
1491
1492 ################################################################################
1493
1494 include MakeFileEnd.gmk