1 #!/bin/ksh -p
   2 #
   3 # Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
   4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 #
   6 # This code is free software; you can redistribute it and/or modify it
   7 # under the terms of the GNU General Public License version 2 only, as
   8 # published by the Free Software Foundation.
   9 #
  10 # This code is distributed in the hope that it will be useful, but WITHOUT
  11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13 # version 2 for more details (a copy is included in the LICENSE file that
  14 # accompanied this code).
  15 #
  16 # You should have received a copy of the GNU General Public License version
  17 # 2 along with this work; if not, write to the Free Software Foundation,
  18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19 #
  20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21 # or visit www.oracle.com if you need additional information or have any
  22 # questions.
  23 #
  24 
  25 #
  26 #   @test
  27 #   @bug        6788096
  28 #   @summary    Test simulates the case of multiple applets executed in
  29 #               the same VM and verifies that ImageIO shutdown hook
  30 #               StreamCloser does not cause a leak of classloaders.
  31 #
  32 #   @modules java.desktop/sun.awt
  33 #   @build      test.Main
  34 #   @build      testapp.Main
  35 #   @run shell  run_test.sh
  36 
  37 # There are several resources which need to be present before many
  38 #  shell scripts can run.  Following are examples of how to check for
  39 #  many common ones.
  40 #
  41 # Note that the shell used is the Korn Shell, KSH
  42 #
  43 # Also note, it is recommended that make files NOT be used.  Rather,
  44 #  put the individual commands directly into this file.  That way,
  45 #  it is possible to use command line arguments and other shell tech-
  46 #  niques to find the compiler, etc on different systems.  For example,
  47 #  a different path could be used depending on whether this were a
  48 #  Solaris or Win32 machine, which is more difficult (if even possible)
  49 #  in a make file.
  50 
  51 
  52 # Beginning of subroutines:
  53 status=1
  54 
  55 #Call this from anywhere to fail the test with an error message
  56 # usage: fail "reason why the test failed"
  57 fail()
  58  { echo "The test failed :-("
  59    echo "$*" 1>&2
  60    echo "exit status was $status"
  61    exit $status
  62  } #end of fail()
  63 
  64 #Call this from anywhere to pass the test with a message
  65 # usage: pass "reason why the test passed if applicable"
  66 pass()
  67  { echo "The test passed!!!"
  68    echo "$*" 1>&2
  69    exit 0
  70  } #end of pass()
  71 
  72 # end of subroutines
  73 
  74 
  75 # The beginning of the script proper
  76 
  77 # Checking for proper OS
  78 OS=`uname -s`
  79 case "$OS" in
  80    SunOS )
  81       VAR="One value for Sun"
  82       DEFAULT_JDK=/
  83       FILESEP="/"
  84       PATHSEP=":"
  85       TMP="/tmp"
  86       ;;
  87 
  88    Linux )
  89       VAR="A different value for Linux"
  90       DEFAULT_JDK=/
  91       FILESEP="/"
  92       PATHSEP=":"
  93       TMP="/tmp"
  94       ;;
  95 
  96    AIX )
  97       VAR="A different value for AIX"
  98       DEFAULT_JDK=/
  99       FILESEP="/"
 100       PATHSEP=":"
 101       TMP="/tmp"
 102       ;;
 103 
 104    Darwin )
 105       VAR="A different value for MacOSX"
 106       DEFAULT_JDK=/usr
 107       FILESEP="/"
 108       PATHSEP=":"
 109       TMP="/tmp"
 110       ;;
 111 
 112    Windows* )
 113       VAR="A different value for Win32"
 114       DEFAULT_JDK="C:/Program Files/Java/jdk1.8.0"
 115       FILESEP="\\"
 116       PATHSEP=";"
 117       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 118       ;;
 119 
 120     CYGWIN* )
 121       VAR="A different value for Cygwin"
 122       DEFAULT_JDK="/cygdrive/c/Program\ Files/Java/jdk1.8.0"
 123       FILESEP="/"
 124       PATHSEP=";"
 125       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 126       ;;
 127 
 128    # catch all other OSs
 129    * )
 130       echo "Unrecognized system!  $OS"
 131       fail "Unrecognized system!  $OS"
 132       ;;
 133 esac
 134 
 135 # Want this test to run standalone as well as in the harness, so do the
 136 #  following to copy the test's directory into the harness's scratch directory
 137 #  and set all appropriate variables:
 138 
 139 if [ -z "${TESTJAVA}" ] ; then
 140    # TESTJAVA is not set, so the test is running stand-alone.
 141    # TESTJAVA holds the path to the root directory of the build of the JDK
 142    # to be tested.  That is, any java files run explicitly in this shell
 143    # should use TESTJAVA in the path to the java interpreter.
 144    # So, we'll set this to the JDK spec'd on the command line.  If none
 145    # is given on the command line, tell the user that and use a cheesy
 146    # default.
 147    # THIS IS THE JDK BEING TESTED.
 148    if [ -n "$1" ] ;
 149       then TESTJAVA=$1
 150       else echo "no JDK specified on command line so using default!"
 151          TESTJAVA=$DEFAULT_JDK
 152    fi
 153    TESTSRC=.
 154    TESTCLASSES=.
 155    STANDALONE=1;
 156 fi
 157 echo "JDK under test is: $TESTJAVA"
 158 
 159 
 160 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 161 
 162 #All files required for the test should be in the same directory with
 163 # this file.  If converting a standalone test to run with the harness,
 164 # as long as all files are in the same directory and it returns 0 for
 165 # pass, you should be able to cut and paste it into here and it will
 166 # run with the test harness.
 167 
 168 # This is an example of running something -- test
 169 # The stuff below catches the exit status of test then passes or fails
 170 # this shell test as appropriate ( 0 status is considered a pass here )
 171 
 172 echo "Create TestApp.jar..."
 173 
 174 if [ -f TestApp.jar ] ; then
 175     rm -f TestApp.jar
 176 fi
 177 
 178 ${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp
 179 
 180 if [ $? -ne "0" ] ; then
 181     fail "Failed to create TestApp.jar"
 182 fi
 183 
 184 echo "Create Test.jar..."
 185 if [ -f Test.jar ] ; then
 186     rm -f Test.jar
 187 fi
 188 
 189 ${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test
 190 
 191 if [ $? -ne 0 ] ; then
 192     fail "Failed to create Test.jar"
 193 fi
 194 
 195 # Prepare temp dir for cahce files
 196 mkdir ./tmp
 197 if [ $? -ne 0 ] ; then
 198     fail "Unable to create temp directory."
 199 fi
 200 
 201 # Verify that all classoladers are destroyed
 202 ${TESTJAVA}/bin/java ${TESTVMOPTS} -cp Test.jar test.Main
 203 if [ $? -ne 0 ] ; then
 204     fail "Test FAILED: some classloaders weren't destroyed."
 205 fi
 206 
 207 
 208 # Verify that ImageIO shutdown hook works correcly
 209 ${TESTJAVA}/bin/java ${TESTVMOPTS} \
 210     -cp Test.jar -DforgetSomeStreams=true test.Main
 211 if [ $? -ne 0 ] ; then
 212     fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed."
 213 fi
 214 
 215 # sanity check: verify that all cache files were deleted
 216 cache_files=`ls tmp`
 217 
 218 if [ "x${cache_files}" != "x" ] ; then
 219     echo "WARNING: some cache files was not deleted: ${cache_files}"
 220 fi
 221 
 222 echo "Test done."
 223 
 224 status=$?
 225 
 226 if [ $status -eq "0" ] ; then
 227     pass ""
 228 else
 229     fail "Test failed due to test plugin was not found."
 230 fi
 231