TestCommon.gmk revision 2768:90010ba88e64
1# 2# Copyright (c) 1995, 2017, 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# 27# Common logic to run various tests for a component, to be included by the 28# component specific test makefiles. 29# 30 31# Default values for some properties that can be overridden by components. 32USE_JTREG_VERSION ?= 4.2 33JTREG_VM_TYPE ?= -agentvm 34USE_JTREG_ASSERT ?= true 35LIMIT_JTREG_VM_MEMORY ?= true 36 37.DEFAULT : all 38 39# Empty these to get rid of some default rules 40.SUFFIXES: 41.SUFFIXES: .java 42CO= 43GET= 44 45# Utilities used 46AWK = awk 47CAT = cat 48CD = cd 49CHMOD = chmod 50CP = cp 51CUT = cut 52DIRNAME = dirname 53ECHO = echo 54EGREP = egrep 55EXPAND = expand 56FIND = find 57MKDIR = mkdir 58PWD = pwd 59RM = rm -f 60SED = sed 61SORT = sort 62TEE = tee 63UNAME = uname 64UNIQ = uniq 65WC = wc 66ZIPEXE = zip 67 68# Get OS name from uname (Cygwin inexplicably adds _NT-5.1) 69UNAME_S := $(shell $(UNAME) -s | $(CUT) -f1 -d_) 70 71# Commands to run on paths to make mixed paths for java on windows 72ifeq ($(findstring CYGWIN,$(UNAME_S)), CYGWIN) 73 # Location of developer shared files 74 SLASH_JAVA = J: 75 GETMIXEDPATH = cygpath -m 76 PLATFORM = windows 77else 78 # Location of developer shared files 79 SLASH_JAVA = /java 80 GETMIXEDPATH = $(ECHO) 81 PLATFORM = unix # we only care about windows or bsd. 82 ifeq ($(UNAME_S), Darwin) 83 PLATFORM = bsd 84 endif 85 ifeq ($(findstring BSD,$(UNAME_S)), BSD) 86 PLATFORM = bsd 87 endif 88endif 89 90ifdef ALT_SLASH_JAVA 91 SLASH_JAVA = $(ALT_SLASH_JAVA) 92endif 93 94# Root of this test area (important to use full paths in some places) 95TEST_ROOT := $(shell $(PWD)) 96 97# Root of all test results 98ifdef TEST_OUTPUT_DIR 99 $(shell $(MKDIR) -p $(TEST_OUTPUT_DIR)/jtreg) 100 ABS_TEST_OUTPUT_DIR := \ 101 $(shell $(CD) $(TEST_OUTPUT_DIR)/jtreg && $(PWD)) 102else 103 ifdef ALT_OUTPUTDIR 104 ABS_OUTPUTDIR = $(shell $(CD) $(ALT_OUTPUTDIR) && $(PWD)) 105 else 106 ABS_OUTPUTDIR = $(shell $(CD) $(TEST_ROOT)/.. && $(PWD)) 107 endif 108 109 ABS_PLATFORM_BUILD_ROOT = $(ABS_OUTPUTDIR) 110 ABS_TEST_OUTPUT_DIR := $(ABS_PLATFORM_BUILD_ROOT)/testoutput/$(UNIQUE_DIR) 111endif 112 113# Expect JPRT to set PRODUCT_HOME (the product or jdk in this case to test) 114ifndef PRODUCT_HOME 115 # Try to use images/jdk if it exists 116 ABS_JDK_IMAGE = $(ABS_PLATFORM_BUILD_ROOT)/images/jdk 117 PRODUCT_HOME := \ 118 $(shell \ 119 if [ -d $(ABS_JDK_IMAGE) ] ; then \ 120 $(ECHO) "$(ABS_JDK_IMAGE)"; \ 121 else \ 122 $(ECHO) "$(ABS_PLATFORM_BUILD_ROOT)"; \ 123 fi) 124 PRODUCT_HOME := $(PRODUCT_HOME) 125endif 126 127# Expect JPRT to set JPRT_PRODUCT_ARGS (e.g. -server etc.) 128# Should be passed into 'java' only. 129# Could include: -d64 -server -client OR any java option 130ifdef JPRT_PRODUCT_ARGS 131 JAVA_ARGS = $(JPRT_PRODUCT_ARGS) 132endif 133 134# Expect JPRT to set JPRT_PRODUCT_VM_ARGS (e.g. -Xcomp etc.) 135# Should be passed into anything running the vm (java, javac, javadoc, ...). 136ifdef JPRT_PRODUCT_VM_ARGS 137 JAVA_VM_ARGS = $(JPRT_PRODUCT_VM_ARGS) 138endif 139 140ifneq ($(NATIVE_TEST_PATH), ) 141 # jtreg -nativepath <dir> 142 # 143 # Local make tests will be TEST_IMAGE_DIR and JPRT with jprt.use.reg.test.bundle=true 144 # should be JPRT_TESTNATIVE_PATH 145 ifdef TEST_IMAGE_DIR 146 TESTNATIVE_DIR = $(TEST_IMAGE_DIR) 147 else ifdef JPRT_TESTNATIVE_PATH 148 TESTNATIVE_DIR = $(JPRT_TESTNATIVE_PATH) 149 endif 150 ifdef TESTNATIVE_DIR 151 JTREG_NATIVE_PATH = -nativepath:$(shell $(GETMIXEDPATH) "$(TESTNATIVE_DIR)/$(NATIVE_TEST_PATH)") 152 endif 153endif 154 155ifeq ($(USE_FAILURE_HANDLER), true) 156 # jtreg failure handler config 157 ifeq ($(FAILURE_HANDLER_DIR), ) 158 ifneq ($(TESTNATIVE_DIR), ) 159 FAILURE_HANDLER_DIR := $(TESTNATIVE_DIR)/failure_handler 160 endif 161 endif 162 ifneq ($(FAILURE_HANDLER_DIR), ) 163 FAILURE_HANDLER_DIR_MIXED := $(shell $(GETMIXEDPATH) "$(FAILURE_HANDLER_DIR)") 164 JTREG_FAILURE_HANDLER_OPTIONS := \ 165 -timeoutHandlerDir:$(FAILURE_HANDLER_DIR_MIXED)/jtregFailureHandler.jar \ 166 -observerDir:$(FAILURE_HANDLER_DIR_MIXED)/jtregFailureHandler.jar \ 167 -timeoutHandler:jdk.test.failurehandler.jtreg.GatherProcessInfoTimeoutHandler \ 168 -observer:jdk.test.failurehandler.jtreg.GatherDiagnosticInfoObserver \ 169 -timeoutHandlerTimeout:0 170 ifeq ($(PLATFORM), windows) 171 JTREG_FAILURE_HANDLER_OPTIONS += -J-Djava.library.path="$(FAILURE_HANDLER_DIR_MIXED)" 172 endif 173 endif 174endif 175 176# Expect JPRT to set JPRT_ARCHIVE_BUNDLE (path to zip bundle for results) 177ifdef JPRT_ARCHIVE_BUNDLE 178 ARCHIVE_BUNDLE = $(JPRT_ARCHIVE_BUNDLE) 179else 180 ARCHIVE_BUNDLE = $(ABS_TEST_OUTPUT_DIR)/ARCHIVE_BUNDLE.zip 181endif 182 183# How to create the test bundle (pass or fail, we want to create this) 184# Follow command with ";$(BUNDLE_UP_AND_EXIT)", so it always gets executed. 185ZIP_UP_RESULTS = ( $(MKDIR) -p `$(DIRNAME) $(ARCHIVE_BUNDLE)` \ 186 && $(CD) $(ABS_TEST_OUTPUT_DIR) \ 187 && $(CHMOD) -R a+r . \ 188 && $(ZIPEXE) -q -r $(ARCHIVE_BUNDLE) . ) 189 190# important results files 191SUMMARY_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport/text/summary.txt") 192STATS_TXT_NAME = Stats.txt 193STATS_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/$(STATS_TXT_NAME)") 194RUNLIST = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/runlist.txt") 195PASSLIST = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/passlist.txt") 196FAILLIST = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/faillist.txt") 197EXITCODE = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/exitcode.txt") 198 199TESTEXIT = \ 200 if [ ! -s $(EXITCODE) ] ; then \ 201 $(ECHO) "ERROR: EXITCODE file not filled in."; \ 202 $(ECHO) "1" > $(EXITCODE); \ 203 fi ; \ 204 testExitCode=`$(CAT) $(EXITCODE)`; \ 205 $(ECHO) "EXIT CODE: $${testExitCode}"; \ 206 exit $${testExitCode} 207 208ifeq ($(TREAT_EXIT_CODE_1_AS_0), true) 209 ADJUST_EXIT_CODE := \ 210 if [ $${jtregExitCode} = 1 ] ; then \ 211 jtregExitCode=0; \ 212 fi 213else 214 # colon is the shell no-op 215 ADJUST_EXIT_CODE := : 216endif 217 218BUNDLE_UP_AND_EXIT = \ 219( \ 220 jtregExitCode=$$? && \ 221 _summary="$(SUMMARY_TXT)"; \ 222 $(ADJUST_EXIT_CODE) ; \ 223 $(RM) -f $(STATS_TXT) $(RUNLIST) $(PASSLIST) $(FAILLIST) $(EXITCODE); \ 224 $(ECHO) "$${jtregExitCode}" > $(EXITCODE); \ 225 if [ -r "$${_summary}" ] ; then \ 226 $(ECHO) "Summary: $(UNIQUE_DIR)" > $(STATS_TXT); \ 227 $(EXPAND) $${_summary} | $(EGREP) -v ' Not run\.' > $(RUNLIST); \ 228 $(EGREP) ' Passed\.' $(RUNLIST) \ 229 | $(EGREP) -v ' Error\.' \ 230 | $(EGREP) -v ' Failed\.' > $(PASSLIST); \ 231 ( $(EGREP) ' Failed\.' $(RUNLIST); \ 232 $(EGREP) ' Error\.' $(RUNLIST); \ 233 $(EGREP) -v ' Passed\.' $(RUNLIST) ) \ 234 | $(SORT) | $(UNIQ) > $(FAILLIST); \ 235 if [ $${jtregExitCode} != 0 -o -s $(FAILLIST) ] ; then \ 236 $(EXPAND) $(FAILLIST) \ 237 | $(CUT) -d' ' -f1 \ 238 | $(SED) -e 's@^@FAILED: @' >> $(STATS_TXT); \ 239 if [ $${jtregExitCode} = 0 ] ; then \ 240 jtregExitCode=1; \ 241 fi; \ 242 fi; \ 243 runc="`$(CAT) $(RUNLIST) | $(WC) -l | $(AWK) '{print $$1;}'`"; \ 244 passc="`$(CAT) $(PASSLIST) | $(WC) -l | $(AWK) '{print $$1;}'`"; \ 245 failc="`$(CAT) $(FAILLIST) | $(WC) -l | $(AWK) '{print $$1;}'`"; \ 246 exclc="FIXME CODETOOLS-7900176"; \ 247 $(ECHO) "TEST STATS: name=$(UNIQUE_DIR) run=$${runc} pass=$${passc} fail=$${failc}" \ 248 >> $(STATS_TXT); \ 249 else \ 250 $(ECHO) "Missing file: $${_summary}" >> $(STATS_TXT); \ 251 fi; \ 252 if [ -f $(STATS_TXT) ] ; then \ 253 $(CAT) $(STATS_TXT); \ 254 fi; \ 255 $(ZIP_UP_RESULTS) ; \ 256 $(TESTEXIT) \ 257) 258 259################################################################ 260 261# Prep for output 262# Change execute permissions on shared library files. 263# Files in repositories should never have execute permissions, but 264# there are some tests that have pre-built shared libraries, and these 265# windows dll files must have execute permission. Adding execute 266# permission may happen automatically on windows when using certain 267# versions of mercurial but it cannot be guaranteed. And blindly 268# adding execute permission might be seen as a mercurial 'change', so 269# we avoid adding execute permission to repository files. But testing 270# from a plain source tree needs the chmod a+rx. Applying the chmod to 271# all shared libraries not just dll files. And with CYGWIN and sshd 272# service, you may need CYGWIN=ntsec for this to work. 273prep: 274 @$(MKDIR) -p $(ABS_TEST_OUTPUT_DIR) 275 @$(MKDIR) -p `$(DIRNAME) $(ARCHIVE_BUNDLE)` 276 @if [ ! -d $(TEST_ROOT)/../.hg ] ; then \ 277 $(FIND) $(TEST_ROOT) \( -name \*.dll -o -name \*.DLL -o -name \*.so \) \ 278 -exec $(CHMOD) a+rx {} \; ; \ 279 fi 280 281ifeq ($(CLEAN_BEFORE_PREP), true) 282prep: clean 283 284endif 285 286# Cleanup 287clean: 288 @$(RM) -r $(ABS_TEST_OUTPUT_DIR) 289 @$(RM) $(ARCHIVE_BUNDLE) 290 291################################################################ 292 293# jtreg tests 294 295# Expect JT_HOME to be set for jtreg tests. (home for jtreg) 296ifndef JT_HOME 297 JT_HOME = $(SLASH_JAVA)/re/jtreg/$(USE_JTREG_VERSION)/promoted/latest/binaries/jtreg 298 ifdef JPRT_JTREG_HOME 299 JT_HOME = $(JPRT_JTREG_HOME) 300 endif 301endif 302 303# Problematic tests to be excluded 304PROBLEM_LISTS=$(call MixedDirs,$(wildcard ProblemList.txt closed/ProblemList.txt)) 305 306# Create exclude list for this platform and arch 307ifdef NO_EXCLUDES 308 JTREG_EXCLUSIONS = 309else 310 JTREG_EXCLUSIONS = $(PROBLEM_LISTS:%=-exclude:%) 311endif 312 313# convert list of directories to dos paths 314define MixedDirs 315$(foreach i,$1,$(shell $(GETMIXEDPATH) "${i}")) 316endef 317 318# ------------------------------------------------------------------ 319 320# When called from JPRT the TESTDIRS variable is set to the jtreg tests to run 321ifdef TESTDIRS 322 TEST_SELECTION = $(TESTDIRS) 323endif 324 325ifdef CONCURRENCY 326 JTREG_BASIC_OPTIONS += -concurrency:$(CONCURRENCY) 327endif 328ifdef EXTRA_JTREG_OPTIONS 329 JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS) 330endif 331 332# Default JTREG to run 333JTREG = $(JT_HOME)/bin/jtreg 334# run in agentvm/othervm mode 335JTREG_BASIC_OPTIONS += $(JTREG_VM_TYPE) 336# Only run automatic tests 337JTREG_BASIC_OPTIONS += -a 338# Always turn on assertions 339ifeq ($(USE_JTREG_ASSERT), true) 340 JTREG_ASSERT_OPTION = -ea -esa 341endif 342JTREG_BASIC_OPTIONS += $(JTREG_ASSERT_OPTION) 343# jtreg verbosity setting 344# Default is to report details on all failed or error tests, times too 345JTREG_VERBOSE ?= fail,error,time 346JTREG_BASIC_OPTIONS += $(if $(JTREG_VERBOSE),-v:$(JTREG_VERBOSE)) 347# Retain all files for failing tests 348JTREG_BASIC_OPTIONS += -retain:fail,error 349# Ignore tests are not run and completely silent about it 350JTREG_IGNORE_OPTION = -ignore:quiet 351JTREG_BASIC_OPTIONS += $(JTREG_IGNORE_OPTION) 352# Multiply by 4 the timeout factor 353JTREG_TIMEOUT_OPTION = -timeoutFactor:4 354JTREG_BASIC_OPTIONS += $(JTREG_TIMEOUT_OPTION) 355ifeq ($(LIMIT_JTREG_VM_MEMORY), true) 356 # Set the max memory for jtreg control vm 357 JTREG_MEMORY_OPTION = -J-Xmx512m 358 JTREG_BASIC_OPTIONS += $(JTREG_MEMORY_OPTION) 359 # Set the max memory for jtreg target test vms 360 JTREG_TESTVM_MEMORY_OPTION = -vmoption:-Xmx512m 361 JTREG_TEST_OPTIONS += $(JTREG_TESTVM_MEMORY_OPTION) 362endif 363# Give tests access to JT_JAVA, see JDK-8141609 364JTREG_BASIC_OPTIONS += -e:JDK8_HOME=${JT_JAVA} 365# Give aot tests access to Visual Studio installation 366ifneq ($(VS120COMNTOOLS), ) 367 JTREG_BASIC_OPTIONS += -e:VS120COMNTOOLS=$(shell $(GETMIXEDPATH) "$(VS120COMNTOOLS)") 368endif 369# Set other vm and test options 370JTREG_TEST_OPTIONS += $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_VM_ARGS:%=-vmoption:%) 371ifneq ($(JIB_JAR), ) 372 JTREG_BASIC_OPTIONS += -cpa:$(shell $(GETMIXEDPATH) "$(JIB_JAR)") 373endif 374ifeq ($(IGNORE_MARKED_TESTS), true) 375 # Option to tell jtreg to not run tests marked with "ignore" 376 ifeq ($(PLATFORM), windows) 377 JTREG_KEY_OPTION = -k:!ignore 378 else 379 JTREG_KEY_OPTION = -k:\!ignore 380 endif 381 JTREG_BASIC_OPTIONS += $(JTREG_KEY_OPTION) 382endif 383 384# Make sure jtreg exists 385ifeq ($(USE_WINDOWS_EXISTENCE_CHECK), true) 386 jtreg_exists: 387 test -d $(shell $(GETMIXEDPATH) "$(JT_HOME)") 388 test -f $(shell $(GETMIXEDPATH) "$(JTREG)") 389 390else 391 jtreg_exists: $(JT_HOME) 392endif 393PHONY_LIST += jtreg_exists 394 395# Run jtreg 396jtreg_tests: prep jtreg_exists $(PRODUCT_HOME) 397 ( \ 398 ( JT_HOME=$(shell $(GETMIXEDPATH) "$(JT_HOME)"); \ 399 export JT_HOME; \ 400 $(shell $(GETMIXEDPATH) "$(JTREG)") \ 401 $(JTREG_BASIC_OPTIONS) \ 402 -r:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport") \ 403 -w:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTwork") \ 404 -jdk:$(shell $(GETMIXEDPATH) "$(PRODUCT_HOME)") \ 405 $(JTREG_NATIVE_PATH) \ 406 $(JTREG_FAILURE_HANDLER_OPTIONS) \ 407 $(JTREG_EXCLUSIONS) \ 408 $(JTREG_TEST_OPTIONS) \ 409 $(TEST_SELECTION) \ 410 ) ; \ 411 $(BUNDLE_UP_AND_EXIT) \ 412 ) 2>&1 | $(TEE) $(ABS_TEST_OUTPUT_DIR)/output.txt ; $(TESTEXIT) 413 414PHONY_LIST += jtreg_tests 415 416################################################################ 417 418# Phony targets (e.g. these are not filenames) 419.PHONY: all clean prep $(PHONY_LIST) 420 421################################################################ 422