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