# # Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License version 2 only, as # published by the Free Software Foundation. Oracle designates this # particular file as subject to the "Classpath" exception as provided # by Oracle in the LICENSE file that accompanied this code. # # This code is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # version 2 for more details (a copy is included in the LICENSE file that # accompanied this code). # # You should have received a copy of the GNU General Public License version # 2 along with this work; if not, write to the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. # # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA # or visit www.oracle.com if you need additional information or have any # questions. #
default: all
include $(SPEC) include MakeBase.gmk include FindTests.gmk
# We will always run multiple tests serially
.NOTPARALLEL:
################################################################################ # Parse global control variables ################################################################################
# Helper function to propagate TEST_OPTS values. # # Note: No spaces are allowed around the arguments. # Arg $1 The variable in TEST_OPTS to propagate # Arg $2 The control variable to propagate it to define SetTestOpt ifneq ($$(TEST_OPTS_$1), )
$2_$1 := $$(TEST_OPTS_$1) endif endef
################################################################################ # Hook to include the corresponding custom file, if present.
$(eval $(call IncludeCustomExtension, RunTests.gmk)) ################################################################################
# This is the JDK that we will test
JDK_UNDER_TEST := $(JDK_IMAGE_DIR)
################################################################################ # Setup global test running parameters ################################################################################
# Each factor variable comes in 3 variants. The first one is reserved for users # to use on command line. The other two are for predefined configurations in JDL # and for machine specific configurations respectively.
TEST_JOBS_FACTOR ?= 1
TEST_JOBS_FACTOR_JDL ?= 1
TEST_JOBS_FACTOR_MACHINE ?= 1
ifeq ($(TEST_JOBS), 0)
CORES_DIVIDER := 2 # For some big multi-core machines with low ulimit -u setting we hit the max # threads/process limit. In such a setup the memory/cores-only-guided # TEST_JOBS config is insufficient. From experience a concurrency setting of # 14 works reasonably well for low ulimit values (<= 4096). Thus, use # divider 4096/14. For high ulimit -u values this shouldn't make a difference.
ULIMIT_DIVIDER := (4096/14)
PROC_ULIMIT := -1 ifneq ($(OPENJDK_TARGET_OS), windows)
PROC_ULIMIT := $(shell $(ULIMIT) -u) ifeq ($(PROC_ULIMIT), unlimited)
PROC_ULIMIT := -1 endif endif
MEMORY_DIVIDER := 2048
TEST_JOBS := $(shell $(AWK) \ 'BEGIN { \
c = $(NUM_CORES) / $(CORES_DIVIDER); \
m = $(MEMORY_SIZE) / $(MEMORY_DIVIDER); \
u = $(PROC_ULIMIT); \ if (u > -1) { \
u = u / $(ULIMIT_DIVIDER); \ if (u < c) c = u; \
} \ if (c > m) c = m; \
c = c * $(TEST_JOBS_FACTOR); \
c = c * $(TEST_JOBS_FACTOR_JDL); \
c = c * $(TEST_JOBS_FACTOR_MACHINE); \ if (c < 1) c = 1; \
printf "%.0f", c; \
}') endif
################################################################################ # Parse control variables ################################################################################
ifneq ($(TEST_OPTS), ) # Inform the user
$(info Running tests using TEST_OPTS control variable '$(TEST_OPTS)') endif
################################################################################ # Parse test selection # # The user has given a test selection in the TEST variable. We must parse it # and determine what that means in terms of actual calls to the test framework. # # The parse functions take as argument a test specification as given by the # user, and returns a fully qualified test descriptor if it was a match, or # nothing if not. A single test specification can result in multiple test # descriptors being returned. A valid test descriptor must always be accepted # and returned identically. ################################################################################
# Helper function to determine if a test specification is a Gtest test # # It is a Gtest test if it is either "gtest", or "gtest:" followed by an optional # test filter string, and an optional "/<variant>" to select a specific JVM # variant. If no variant is specified, all found variants are tested. define ParseGtestTestSelection
$(if $(filter gtest%, $1), \
$(if $(filter gtest, $1), \
$(addprefix gtest:all/, $(GTEST_VARIANTS)) \
, \
$(if $(strip $(or $(filter gtest/%, $1) $(filter gtest:/%, $1))), \
$(patsubst gtest:/%, gtest:all/%, $(patsubst gtest/%, gtest:/%, $1)) \
, \
$(if $(filter gtest:%, $1), \
$(if $(findstring /, $1), \
$1 \
, \
$(addprefix $1/, $(GTEST_VARIANTS)) \
) \
) \
) \
) \
) endef
# Helper function to determine if a test specification is a microbenchmark test # # It is a microbenchmark test if it is either "micro", or "micro:" followed by # an optional test filter string. define ParseMicroTestSelection
$(if $(filter micro%, $1), \
$(if $(filter micro, $1), \
micro:all \
, \
$(if $(filter micro:, $1), \
micro:all \
, \
$1 \
) \
) \
) endef
# Helper function that removes the TOPDIR part
CleanupJtregPath = \
$(strip $(patsubst %/, %, $(subst $(JTREG_TOPDIR)/,, $1)))
# Take a partial Jtreg root path and return a full, absolute path to that Jtreg # root. Also support having "hotspot" as an alias for "hotspot/jtreg".
ExpandJtregRoot = \
$(call CleanupJtregPath, $(wildcard \
$(if $(filter /%, $1), \
$(if $(wildcard $(strip $1)/TEST.ROOT), \
$1 \
) \
, \
$(filter $(addprefix %, $1), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
$(filter $(addprefix %, $(strip $1)/jtreg), $(JTREG_TESTROOTS) $(addsuffix /, $(JTREG_TESTROOTS))) \
) \
))
# Take a partial Jtreg test path and return a full, absolute path to that Jtreg # test. Also support having "hotspot" as an alias for "hotspot/jtreg".
ExpandJtregPath = \
$(if $(call ExpandJtregRoot, $1), \
$(call ExpandJtregRoot, $1) \
, \
$(call CleanupJtregPath, $(wildcard \
$(if $(filter /%, $1), \
$1 \
, \
$(addsuffix /$(strip $1), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
$(addsuffix $(strip $(patsubst hotspot/%, /hotspot/jtreg/%, $1)), $(JTREG_TESTROOTS) $(TEST_BASEDIRS)) \
) \
)) \
)
# The test id starting with a hash (#testid) will be stripped by all # evals in ParseJtregTestSelectionInner and will be reinserted by calling # TestID (if it is present).
ParseJtregTestSelection = \
$(call IfAppend, $(call ParseJtregTestSelectionInner, $1), $(call TestID, $1))
# Helper function to determine if a test specification is a Jtreg test # # It is a Jtreg test if it optionally begins with jtreg:, and then is either # an unspecified group name (possibly prefixed by :), or a group in a # specified test root, or a path to a test or test directory, # either absolute or relative to any of the TEST_BASEDIRS or test roots. define ParseJtregTestSelectionInner
$(eval TEST_NAME := $(strip $(patsubst jtreg:%, %, $1))) \
$(if $(or $(findstring :, $(TEST_NAME)), $(findstring /, $(TEST_NAME))), , \
$(eval TEST_NAME := :$(TEST_NAME)) \
) \
$(if $(findstring :, $(TEST_NAME)), \
$(if $(filter :%, $(TEST_NAME)), \
$(eval TEST_GROUP := $(patsubst :%, %, $(TEST_NAME))) \
$(eval TEST_ROOTS := $(foreach test_root, $(JTREG_TESTROOTS), \
$(call CleanupJtregPath, $(test_root)))) \
, \
$(eval TEST_PATH := $(word 1, $(subst :, $(SPACE), $(TEST_NAME)))) \
$(eval TEST_GROUP := $(word 2, $(subst :, $(SPACE), $(TEST_NAME)))) \
$(eval TEST_ROOTS := $(call ExpandJtregRoot, $(TEST_PATH))) \
) \
$(foreach test_root, $(TEST_ROOTS), \
$(if $(filter /%, $(test_root)), \
jtreg:$(test_root):$(TEST_GROUP) \
, \
$(if $(filter $(TEST_GROUP), $($(JTREG_TOPDIR)/$(test_root)_JTREG_TEST_GROUPS)), \
jtreg:$(test_root):$(TEST_GROUP) \
) \
) \
) \
, \
$(eval TEST_PATHS := $(call ExpandJtregPath, $(TEST_NAME))) \
$(foreach test_path, $(TEST_PATHS), \
jtreg:$(test_path) \
) \
) endef
# Helper function to determine if a test specification is a special test # # It is a special test if it is "special:" followed by a test name, # if it is "make:" or "make-" followed by a make test, or any of the special # test names as a single word. define ParseSpecialTestSelection
$(if $(filter special:%, $1), \
$1 \
) \
$(if $(filter make%, $1), \
$(if $(filter make:%, $1), \
special:$(strip $1) \
) \
$(if $(filter make-%, $1), \
special:$(patsubst make-%,make:%, $1) \
) \
$(if $(filter make, $1), \
special:make:all \
)
) \
$(if $(filter failure-handler, $1), \
special:$(strip $1) \
) endef
ifeq ($(TEST), )
$(info No test selection given in TEST!)
$(info Please use e.g. 'make test TEST=tier1' or 'make test-tier1')
$(info See doc/testing.[md|html] for help)
$(error Cannot continue) endif
# Now intelligently convert the test selection given by the user in TEST # into a list of fully qualified test descriptors of the tests to run.
TESTS_TO_RUN := $(strip $(foreach test, $(TEST), $(call ParseTestSelection, $(test))))
UNKNOWN_TEST := $(strip $(foreach test, $(TEST), $(if $(call ParseTestSelection, $(test)), , $(test))))
ifneq ($(UNKNOWN_TEST), )
$(info Unknown test selection: '$(UNKNOWN_TEST)')
$(info See doc/testing.[md|html] for help)
$(error Cannot continue) endif
# Present the result of our parsing to the user
$(info Test selection '$(TEST)', will run:)
$(foreach test, $(TESTS_TO_RUN), $(info * $(test)))
################################################################################ # Functions for setting up rules for running the selected tests # # The SetupRun*Test functions all have the same interface: # # Parameter 1 is the name of the rule. This is the test id, based on the test # descriptor, and this is also used as variable prefix, and the targets # generated are listed in a variable by that name. # # Remaining parameters are named arguments. Currently this is only: # TEST -- The properly formatted fully qualified test descriptor # # After the rule named by the test id has been executed, the following # variables will be available: # testid_TOTAL - the total number of tests run # testid_PASSED - the number of successful tests # testid_FAILED - the number of failed tests # testid_ERROR - the number of tests was neither successful or failed # ################################################################################
# Helper function for SetupRunMicroTest. Set a MICRO_* variable from, in order: # 1) Specified by user on command line # 2) Generic default # # Note: No spaces are allowed around the arguments. # Arg $1 The test ID (i.e. $1 in SetupRunMicroTest) # Arg $2 Base variable, e.g. MICRO_TEST_JDK # Arg $3 The default value (optional) define SetMicroValue ifneq ($$($2), )
$1_$2 := $$($2) else ifneq ($3, )
$1_$2 := $3 endif endif endef
# Helper function for SetupRunJtregTest. Set a JTREG_* variable from, in order: # 1) Specified by user on command line # 2) Component-specific default # 3) Generic default # # Note: No spaces are allowed around the arguments. # Arg $1 The test ID (i.e. $1 in SetupRunJtregTest) # Arg $2 Base variable, e.g. JTREG_JOBS # Arg $3 The default value (optional) define SetJtregValue ifneq ($$($2), )
$1_$2 := $$($2) else ifneq ($$($$($1_COMPONENT)_$2), )
$1_$2 := $$($$($1_COMPONENT)_$2) else ifneq ($3, )
$1_$2 := $3 endif endif endif endef
$1_TEST_ROOT := \
$$(strip $$(foreach root, $$(JTREG_TESTROOTS), \
$$(if $$(filter $$(root)%, $$(JTREG_TOPDIR)/$$($1_TEST_NAME)), $$(root)) \
))
$1_COMPONENT := $$(lastword $$(subst /, $$(SPACE), $$($1_TEST_ROOT))) # This will work only as long as just hotspot has the additional "jtreg" directory ifeq ($$($1_COMPONENT), jtreg)
$1_COMPONENT := hotspot endif
ifeq ($$(JT_HOME), )
$$(info Error: jtreg framework is not found.)
$$(info Please run configure using --with-jtreg.)
$$(error Cannot continue) endif
# Unfortunately, we need different defaults for some JTREG values, # depending on what component we're running.
# Convert JTREG_foo into $1_JTREG_foo with a suitable value.
$$(eval $$(call SetJtregValue,$1,JTREG_TEST_MODE,agentvm))
$$(eval $$(call SetJtregValue,$1,JTREG_ASSERT,true))
$$(eval $$(call SetJtregValue,$1,JTREG_MAX_MEM,768m))
$$(eval $$(call SetJtregValue,$1,JTREG_NATIVEPATH))
$$(eval $$(call SetJtregValue,$1,JTREG_BASIC_OPTIONS))
$$(eval $$(call SetJtregValue,$1,JTREG_PROBLEM_LIST))
# Only the problem list for the current test root should be used.
$1_JTREG_PROBLEM_LIST := $$(filter $$($1_TEST_ROOT)%, $$($1_JTREG_PROBLEM_LIST))
# Make sure MaxRAMPercentage is high enough to not cause OOM or swapping since # we may end up with a lot of JVM's
$1_JTREG_MAX_RAM_PERCENTAGE := $$(shell $(AWK) 'BEGIN { print 25 / $$($1_JTREG_JOBS); }')
ifneq ($$(JTREG_RETRY_COUNT), 0) ifneq ($$(JTREG_REPEAT_COUNT), 0)
$$(info Error: Cannot use both JTREG_RETRY_COUNT and JTREG_REPEAT_COUNT together.)
$$(info Please choose one or the other.)
$$(error Cannot continue) endif endif
# Make sure the tmp dir is normalized as some tests will react badly otherwise
$1_TEST_TMP_DIR := $$(abspath $$($1_TEST_SUPPORT_DIR)/tmp)
# test.boot.jdk is used by some test cases that want to execute a previous # version of the JDK.
$1_JTREG_BASIC_OPTIONS += -$$($1_JTREG_TEST_MODE) \
-verbose:$$(JTREG_VERBOSE) -retain:$$(JTREG_RETAIN) \
-concurrency:$$($1_JTREG_JOBS) -timeoutFactor:$$(JTREG_TIMEOUT_FACTOR) \
-vmoption:-XX:MaxRAMPercentage=$$($1_JTREG_MAX_RAM_PERCENTAGE) \
-vmoption:-Dtest.boot.jdk="$$(BOOT_JDK)" \
-vmoption:-Djava.io.tmpdir="$$($1_TEST_TMP_DIR)"
# Make it possible to specify the JIB_DATA_DIR for tests using the # JIB Artifact resolver
$1_JTREG_BASIC_OPTIONS += -e:JIB_DATA_DIR # If running on Windows, propagate the _NT_SYMBOL_PATH to enable # symbol lookup in hserr files ifeq ($$(call isTargetOs, windows), true)
$1_JTREG_BASIC_OPTIONS += -e:_NT_SYMBOL_PATH elseifeq ($$(call isTargetOs, linux), true)
$1_JTREG_BASIC_OPTIONS += -e:_JVM_DWARF_PATH=$$(SYMBOLS_IMAGE_DIR) endif
ifneq ($$(JTREG_EXTRA_PROBLEM_LISTS), ) # Accept both absolute paths as well as relative to the current test root.
$1_JTREG_BASIC_OPTIONS += $$(addprefix $$(JTREG_PROBLEM_LIST_PREFIX), $$(wildcard \
$$(JTREG_EXTRA_PROBLEM_LISTS) \
$$(addprefix $$($1_TEST_ROOT)/, $$(JTREG_EXTRA_PROBLEM_LISTS)) \
)) endif
ifneq ($$(JTREG_KEYWORDS), ) # The keywords string may contain problematic characters and may be quoted # already when it arrives here. Remove any existing quotes and replace them # with one set of single quotes.
$1_JTREG_KEYWORDS := \
$$(strip $$(subst $$(SQUOTE),,$$(subst $$(DQUOTE),,$$(JTREG_KEYWORDS)))) ifneq ($$($1_JTREG_KEYWORDS), )
$1_JTREG_BASIC_OPTIONS += -k:'$$($1_JTREG_KEYWORDS)' endif endif
ifneq ($$(JTREG_RETRY_COUNT), 0)
$1_COMMAND_LINE := \ for i in {0..$$(JTREG_RETRY_COUNT)}; do \ if [ "$$$$i" != 0 ]; then \
$$(PRINTF) "\nRetrying Jtreg run. Attempt: $$$$i\n"; \ fi; \
$$($1_COMMAND_LINE); \ if [ "`$$(CAT) $$($1_EXITCODE)`" = "0" ]; then \
break; \ fi; \ export JTREG_STATUS="-status:error,fail"; \ done endif
ifneq ($$(JTREG_REPEAT_COUNT), 0)
$1_COMMAND_LINE := \ for i in {1..$$(JTREG_REPEAT_COUNT)}; do \
$$(PRINTF) "\nRepeating Jtreg run: $$$$i out of $$(JTREG_REPEAT_COUNT)\n"; \
$$($1_COMMAND_LINE); \ if [ "`$$(CAT) $$($1_EXITCODE)`" != "0" ]; then \
$$(PRINTF) "\nFailures detected, no more repeats.\n"; \
break; \ fi; \ done endif
# We can not parse the various "special" tests.
parse-test-$1: run-test-$1
$$(call LogWarn, Finished running test '$$($1_TEST)')
$$(call LogWarn, Test report is stored in $$(strip \
$$(subst $$(TOPDIR)/, , $$($1_TEST_RESULTS_DIR))))
$$(call LogWarn, Warning: Special test results are not properly parsed!)
$$(eval $1_PASSED := $$(shell \ if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 1; else $(ECHO) 0; fi \
))
$$(eval $1_FAILED := $$(shell \ if [ `$(CAT) $$($1_EXITCODE)` = "0" ]; then $(ECHO) 0; else $(ECHO) 1; fi \
))
$$(eval $1_ERROR := 0)
$$(eval $1_TOTAL := 1)
################################################################################ # Setup and execute make rules for all selected tests ################################################################################
# Helper function to determine which handler to use for the given test
UseGtestTestHandler = \
$(if $(filter gtest:%, $1), true)
# Now process each test to run and setup a proper make rule
$(foreach test, $(TESTS_TO_RUN), \
$(eval TEST_ID := $(shell $(ECHO) $(strip $(test)) | \
$(TR) -cs '[a-z][A-Z][0-9]\n''[_*1000]')) \
$(eval ALL_TEST_IDS += $(TEST_ID)) \
$(if $(call UseCustomTestHandler, $(test)), \
$(eval $(call SetupRunCustomTest, $(TEST_ID), \
TEST := $(test), \
)) \
) \
$(if $(call UseGtestTestHandler, $(test)), \
$(eval $(call SetupRunGtestTest, $(TEST_ID), \
TEST := $(test), \
)) \
) \
$(if $(call UseMicroTestHandler, $(test)), \
$(eval $(call SetupRunMicroTest, $(TEST_ID), \
TEST := $(test), \
)) \
) \
$(if $(call UseJtregTestHandler, $(test)), \
$(eval $(call SetupRunJtregTest, $(TEST_ID), \
TEST := $(test), \
)) \
) \
$(if $(call UseSpecialTestHandler, $(test)), \
$(eval $(call SetupRunSpecialTest, $(TEST_ID), \
TEST := $(test), \
)) \
) \
)
# Sort also removes duplicates, so if there is any we'll get fewer words. ifneq ($(words $(ALL_TEST_IDS)), $(words $(sort $(ALL_TEST_IDS))))
$(error Duplicate test specification) endif
################################################################################ # The main target for RunTests.gmk ################################################################################
# # Provide hooks for adding functionality before and after all tests are run. #
$(call LogInfo, RunTest setup starting)
# This target depends on all actual test having been run (TEST_TARGETS has beeen # populated by the SetupRun*Test functions). If you need to provide a teardown # hook, you must let it depend on this target.
run-all-tests: $(TEST_TARGETS)
$(call LogInfo, RunTest teardown starting)
# This is an abstract target that will be run before any actual tests. Add your # target as a dependency to thisif you need "setup" type functionality executed # before all tests.
pre-run-test:
$(call LogInfo, RunTest setup done)
# This is an abstract target that will be run after all actual tests, but before # the test summary. If you need "teardown" type functionality, add your target # as a dependency on this, and let the teardown target depend on run-all-tests.
post-run-test: run-all-tests
$(call LogInfo, RunTest teardown done)
# # Create and print a table of the result of all tests run #
TEST_FAILURE := false
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.