1 #
   2 # Copyright (c) 1995, 2015, 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 ALT_OUTPUTDIR
  80   ABS_OUTPUTDIR = $(shell $(CD) $(ALT_OUTPUTDIR) && $(PWD))
  81 else
  82   ABS_OUTPUTDIR = $(shell $(CD) $(TEST_ROOT)/.. && $(PWD))
  83 endif
  84 
  85 ABS_PLATFORM_BUILD_ROOT = $(ABS_OUTPUTDIR)
  86 ABS_TEST_OUTPUT_DIR := $(ABS_PLATFORM_BUILD_ROOT)/testoutput/$(UNIQUE_DIR)
  87 
  88 # Expect JPRT to set PRODUCT_HOME (the product or jdk in this case to test)
  89 ifndef PRODUCT_HOME
  90   # Try to use j2sdk-image if it exists
  91   ABS_JDK_IMAGE = $(ABS_PLATFORM_BUILD_ROOT)/images/j2sdk-image
  92   PRODUCT_HOME :=                                       \
  93     $(shell                                             \
  94       if [ -d $(ABS_JDK_IMAGE) ] ; then                 \
  95          $(ECHO) "$(ABS_JDK_IMAGE)";                    \
  96        else                                             \
  97          $(ECHO) "$(ABS_PLATFORM_BUILD_ROOT)";          \
  98        fi)
  99   PRODUCT_HOME := $(PRODUCT_HOME)
 100 endif
 101 
 102 # Expect JPRT to set JPRT_PRODUCT_ARGS (e.g. -server etc.)
 103 #   Should be passed into 'java' only.
 104 #   Could include: -d64 -server -client OR any java option
 105 ifdef JPRT_PRODUCT_ARGS
 106   JAVA_ARGS = $(JPRT_PRODUCT_ARGS)
 107 endif
 108 
 109 # Expect JPRT to set JPRT_PRODUCT_VM_ARGS (e.g. -Xcomp etc.)
 110 #   Should be passed into anything running the vm (java, javac, javadoc, ...).
 111 ifdef JPRT_PRODUCT_VM_ARGS
 112   JAVA_VM_ARGS = $(JPRT_PRODUCT_VM_ARGS)
 113 endif
 114 
 115 # jtreg -nativepath <dir>
 116 #
 117 # Local make tests will be TEST_IMAGE_DIR and JPRT with jprt.use.reg.test.bundle=true
 118 # should be JPRT_TESTNATIVE_PATH
 119 ifdef TEST_IMAGE_DIR
 120   TESTNATIVE_DIR = $(TEST_IMAGE_DIR)
 121 else ifdef JPRT_TESTNATIVE_PATH
 122   TESTNATIVE_DIR = $(JPRT_TESTNATIVE_PATH)
 123 endif
 124 ifdef TESTNATIVE_DIR
 125   JTREG_NATIVE_PATH = -nativepath:$(shell $(GETMIXEDPATH) "$(TESTNATIVE_DIR)/jdk/jtreg/native")
 126 endif
 127 
 128 # Expect JPRT to set JPRT_ARCHIVE_BUNDLE (path to zip bundle for results)
 129 ifdef JPRT_ARCHIVE_BUNDLE
 130   ARCHIVE_BUNDLE = $(JPRT_ARCHIVE_BUNDLE)
 131 else
 132   ARCHIVE_BUNDLE = $(ABS_TEST_OUTPUT_DIR)/ARCHIVE_BUNDLE.zip
 133 endif
 134 
 135 # How to create the test bundle (pass or fail, we want to create this)
 136 #   Follow command with ";$(BUNDLE_UP_AND_EXIT)", so it always gets executed.
 137 ZIP_UP_RESULTS = ( $(MKDIR) -p `$(DIRNAME) $(ARCHIVE_BUNDLE)`     \
 138                    && $(CD) $(ABS_TEST_OUTPUT_DIR)             \
 139                    && $(CHMOD) -R a+r . \
 140                    && $(ZIP) -q -r $(ARCHIVE_BUNDLE) . )
 141 
 142 # important results files
 143 SUMMARY_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport/text/summary.txt")
 144 STATS_TXT_NAME = Stats.txt
 145 STATS_TXT = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/$(STATS_TXT_NAME)")
 146 RUNLIST   = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/runlist.txt")
 147 PASSLIST  = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/passlist.txt")
 148 FAILLIST  = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/faillist.txt")
 149 EXITCODE  = $(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/exitcode.txt")
 150 
 151 TESTEXIT = \
 152   if [ ! -s $(EXITCODE) ] ; then \
 153     $(ECHO) "ERROR: EXITCODE file not filled in."; \
 154     $(ECHO) "1" > $(EXITCODE); \
 155   fi ; \
 156   testExitCode=`$(CAT) $(EXITCODE)`; \
 157   $(ECHO) "EXIT CODE: $${testExitCode}"; \
 158   exit $${testExitCode}
 159 
 160 BUNDLE_UP_AND_EXIT = \
 161 ( \
 162   jtregExitCode=$$? && \
 163   _summary="$(SUMMARY_TXT)"; \
 164   $(RM) -f $(STATS_TXT) $(RUNLIST) $(PASSLIST) $(FAILLIST) $(EXITCODE); \
 165   $(ECHO) "$${jtregExitCode}" > $(EXITCODE); \
 166   if [ -r "$${_summary}" ] ; then \
 167     $(ECHO) "Summary: $(UNIQUE_DIR)" > $(STATS_TXT); \
 168     $(EXPAND) $${_summary} | $(EGREP) -v ' Not run\.' > $(RUNLIST); \
 169     $(EGREP) ' Passed\.' $(RUNLIST) \
 170       | $(EGREP) -v ' Error\.' \
 171       | $(EGREP) -v ' Failed\.' > $(PASSLIST); \
 172     ( $(EGREP) ' Failed\.' $(RUNLIST); \
 173       $(EGREP) ' Error\.' $(RUNLIST); \
 174       $(EGREP) -v ' Passed\.' $(RUNLIST) ) \
 175       | $(SORT) | $(UNIQ) > $(FAILLIST); \
 176     if [ $${jtregExitCode} != 0 -o -s $(FAILLIST) ] ; then \
 177       $(EXPAND) $(FAILLIST) \
 178         | $(CUT) -d' ' -f1 \
 179         | $(SED) -e 's@^@FAILED: @' >> $(STATS_TXT); \
 180       if [ $${jtregExitCode} = 0 ] ; then \
 181         jtregExitCode=1; \
 182       fi; \
 183     fi; \
 184     runc="`$(CAT) $(RUNLIST)      | $(WC) -l | $(AWK) '{print $$1;}'`"; \
 185     passc="`$(CAT) $(PASSLIST)    | $(WC) -l | $(AWK) '{print $$1;}'`"; \
 186     failc="`$(CAT) $(FAILLIST)    | $(WC) -l | $(AWK) '{print $$1;}'`"; \
 187     exclc="FIXME CODETOOLS-7900176"; \
 188     $(ECHO) "TEST STATS: name=$(UNIQUE_DIR)  run=$${runc}  pass=$${passc}  fail=$${failc}" \
 189       >> $(STATS_TXT); \
 190   else \
 191     $(ECHO) "Missing file: $${_summary}" >> $(STATS_TXT); \
 192   fi; \
 193   if [ -f $(STATS_TXT) ] ; then \
 194     $(CAT) $(STATS_TXT); \
 195   fi; \
 196   $(ZIP_UP_RESULTS) ; \
 197   $(TESTEXIT) \
 198 )
 199 
 200 ################################################################
 201 
 202 # Default make rule (runs default jdk tests)
 203 all: jdk_default
 204         @$(ECHO) "Testing completed successfully"
 205 
 206 # Prep for output
 207 # Change execute permissions on shared library files.
 208 # Files in repositories should never have execute permissions, but
 209 # there are some tests that have pre-built shared libraries, and these
 210 # windows dll files must have execute permission. Adding execute
 211 # permission may happen automatically on windows when using certain
 212 # versions of mercurial but it cannot be guaranteed. And blindly
 213 # adding execute permission might be seen as a mercurial 'change', so
 214 # we avoid adding execute permission to repository files. But testing
 215 # from a plain source tree needs the chmod a+rx. Applying the chmod to
 216 # all shared libraries not just dll files. And with CYGWIN and sshd
 217 # service, you may need CYGWIN=ntsec for this to work.
 218 prep:
 219         @$(MKDIR) -p $(ABS_TEST_OUTPUT_DIR)
 220         @$(MKDIR) -p `$(DIRNAME) $(ARCHIVE_BUNDLE)`
 221         @if [ ! -d $(TEST_ROOT)/../.hg ] ; then                          \
 222           $(FIND) $(TEST_ROOT) \( -name \*.dll -o -name \*.DLL -o -name \*.so \)  \
 223                 -exec $(CHMOD) a+rx {} \; ;                             \
 224         fi
 225 
 226 # Cleanup
 227 clean:
 228         @$(RM) -r $(ABS_TEST_OUTPUT_DIR)
 229         @$(RM) $(ARCHIVE_BUNDLE)
 230 
 231 ################################################################
 232 
 233 # jtreg tests
 234 
 235 # Expect JT_HOME to be set for jtreg tests. (home for jtreg)
 236 ifndef JT_HOME
 237   JT_HOME = $(SLASH_JAVA)/re/jtreg/4.1/promoted/latest/binaries/jtreg
 238   ifdef JPRT_JTREG_HOME
 239     JT_HOME = $(JPRT_JTREG_HOME)
 240   endif
 241 endif
 242 
 243 # Problematic tests to be excluded
 244 PROBLEM_LISTS=$(call MixedDirs,$(wildcard ProblemList.txt closed/ProblemList.txt))
 245 
 246 # Create exclude list for this platform and arch
 247 ifdef NO_EXCLUDES
 248   JTREG_EXCLUSIONS =
 249 else
 250   JTREG_EXCLUSIONS = $(PROBLEM_LISTS:%=-exclude:%)
 251 endif
 252 
 253 # convert list of directories to dos paths
 254 define MixedDirs
 255 $(foreach i,$1,$(shell $(GETMIXEDPATH) "${i}"))
 256 endef
 257 
 258 define SummaryInfo
 259 $(ECHO) "########################################################"
 260 $(CAT) $(?:%=$(ABS_TEST_OUTPUT_DIR)/%/$(STATS_TXT_NAME))
 261 $(ECHO) "########################################################"
 262 endef
 263 
 264 # ------------------------------------------------------------------
 265 
 266 jdk_% core_% svc_%:
 267         $(ECHO) "Running tests: $@"
 268         for each in $@; do \
 269                 $(MAKE) -j 1 TEST_SELECTION=":$$each" UNIQUE_DIR=$$each jtreg_tests; \
 270         done
 271 
 272 # ------------------------------------------------------------------
 273 
 274 # When called from JPRT the TESTDIRS variable is set to the jtreg tests to run
 275 ifdef TESTDIRS
 276   TEST_SELECTION = $(TESTDIRS)
 277 endif
 278 
 279 ifdef CONCURRENCY
 280   EXTRA_JTREG_OPTIONS += -concurrency:$(CONCURRENCY)
 281 endif
 282 
 283 # Default JTREG to run
 284 JTREG = $(JT_HOME)/bin/jtreg
 285 # run in agentvm mode
 286 JTREG_BASIC_OPTIONS += -agentvm
 287 # Only run automatic tests
 288 JTREG_BASIC_OPTIONS += -a
 289 # Always turn on assertions
 290 JTREG_ASSERT_OPTION = -ea -esa
 291 JTREG_BASIC_OPTIONS += $(JTREG_ASSERT_OPTION)
 292 # Report details on all failed or error tests, times too
 293 JTREG_BASIC_OPTIONS += -v:fail,error,time
 294 # Retain all files for failing tests
 295 JTREG_BASIC_OPTIONS += -retain:fail,error
 296 # Ignore tests are not run and completely silent about it
 297 JTREG_IGNORE_OPTION = -ignore:quiet
 298 JTREG_BASIC_OPTIONS += $(JTREG_IGNORE_OPTION)
 299 # Multiple by 4 the timeout numbers
 300 JTREG_TIMEOUT_OPTION =  -timeoutFactor:4
 301 JTREG_BASIC_OPTIONS += $(JTREG_TIMEOUT_OPTION)
 302 # Set the max memory for jtreg control vm
 303 JTREG_MEMORY_OPTION = -J-Xmx512m
 304 JTREG_BASIC_OPTIONS += $(JTREG_MEMORY_OPTION)
 305 # Add any extra options
 306 JTREG_BASIC_OPTIONS += $(EXTRA_JTREG_OPTIONS)
 307 # Set other vm and test options
 308 JTREG_TEST_OPTIONS = $(JAVA_ARGS:%=-javaoptions:%) $(JAVA_VM_ARGS:%=-vmoption:%)
 309 # Set the GC options for test vms
 310 #JTREG_GC_OPTION = -vmoption:-XX:+UseSerialGC
 311 #JTREG_TEST_OPTIONS += $(JTREG_GC_OPTION)
 312 # Set the max memory for jtreg target test vms
 313 JTREG_TESTVM_MEMORY_OPTION = -vmoption:-Xmx512m
 314 JTREG_TEST_OPTIONS += $(JTREG_TESTVM_MEMORY_OPTION)
 315 
 316 # Make sure jtreg exists
 317 $(JTREG): $(JT_HOME)
 318 
 319 # Run jtreg
 320 jtreg_tests: prep $(PRODUCT_HOME) $(JTREG)
 321         (                                                                    \
 322           ( JT_HOME=$(shell $(GETMIXEDPATH) "$(JT_HOME)");                   \
 323             export JT_HOME;                                                  \
 324             $(shell $(GETMIXEDPATH) "$(JTREG)")                              \
 325               $(JTREG_BASIC_OPTIONS)                                         \
 326               -r:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTreport")  \
 327               -w:$(shell $(GETMIXEDPATH) "$(ABS_TEST_OUTPUT_DIR)/JTwork")    \
 328               -jdk:$(shell $(GETMIXEDPATH) "$(PRODUCT_HOME)")                \
 329               $(JTREG_NATIVE_PATH)                                           \
 330               $(JTREG_EXCLUSIONS)                                            \
 331               $(JTREG_TEST_OPTIONS)                                          \
 332               $(TEST_SELECTION)                                                    \
 333           ) ;                                                                \
 334           $(BUNDLE_UP_AND_EXIT)                                              \
 335         ) 2>&1 | $(TEE) $(ABS_TEST_OUTPUT_DIR)/output.txt ; $(TESTEXIT)
 336 
 337 PHONY_LIST += jtreg_tests
 338 
 339 ################################################################
 340 
 341 # Phony targets (e.g. these are not filenames)
 342 .PHONY: all clean prep $(PHONY_LIST)
 343 
 344 ################################################################