1 #!/bin/ksh -p
   2 #
   3 # Copyright (c) 2009, 2012, 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 #   @build      test.Main
  33 #   @build      testapp.Main
  34 #   @run shell  run_test.sh
  35 
  36 # There are several resources which need to be present before many
  37 #  shell scripts can run.  Following are examples of how to check for
  38 #  many common ones.
  39 #
  40 # Note that the shell used is the Korn Shell, KSH
  41 #
  42 # Also note, it is recommended that make files NOT be used.  Rather,
  43 #  put the individual commands directly into this file.  That way,
  44 #  it is possible to use command line arguments and other shell tech-
  45 #  niques to find the compiler, etc on different systems.  For example,
  46 #  a different path could be used depending on whether this were a
  47 #  Solaris or Win32 machine, which is more difficult (if even possible)
  48 #  in a make file.
  49 
  50 
  51 # Beginning of subroutines:
  52 status=1
  53 
  54 #Call this from anywhere to fail the test with an error message
  55 # usage: fail "reason why the test failed"
  56 fail()
  57  { echo "The test failed :-("
  58    echo "$*" 1>&2
  59    echo "exit status was $status"
  60    exit $status
  61  } #end of fail()
  62 
  63 #Call this from anywhere to pass the test with a message
  64 # usage: pass "reason why the test passed if applicable"
  65 pass()
  66  { echo "The test passed!!!"
  67    echo "$*" 1>&2
  68    exit 0
  69  } #end of pass()
  70 
  71 # end of subroutines
  72 
  73 
  74 # The beginning of the script proper
  75 
  76 # Checking for proper OS
  77 OS=`uname -s`
  78 case "$OS" in
  79    SunOS )
  80       VAR="One value for Sun"
  81       DEFAULT_JDK=/
  82       FILESEP="/"
  83       PATHSEP=":"
  84       TMP="/tmp"
  85       ;;
  86 
  87    Linux )
  88       VAR="A different value for Linux"
  89       DEFAULT_JDK=/
  90       FILESEP="/"
  91       PATHSEP=":"
  92       TMP="/tmp"
  93       ;;
  94 
  95    Darwin )
  96       VAR="A different value for MacOSX"
  97       DEFAULT_JDK=/usr
  98       FILESEP="/"
  99       PATHSEP=":"
 100       TMP="/tmp"
 101       ;;
 102 
 103    Windows* )
 104       VAR="A different value for Win32"
 105       DEFAULT_JDK="C:/Program Files/Java/jdk1.8.0"
 106       FILESEP="\\"
 107       PATHSEP=";"
 108       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 109       ;;
 110 
 111     CYGWIN* )
 112       VAR="A different value for Cygwin"
 113       DEFAULT_JDK="/cygdrive/c/Program\ Files/Java/jdk1.8.0"
 114       FILESEP="/"
 115       PATHSEP=";"
 116       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 117       ;;
 118 
 119    # catch all other OSs
 120    * )
 121       echo "Unrecognized system!  $OS"
 122       fail "Unrecognized system!  $OS"
 123       ;;
 124 esac
 125 
 126 # Want this test to run standalone as well as in the harness, so do the
 127 #  following to copy the test's directory into the harness's scratch directory
 128 #  and set all appropriate variables:
 129 
 130 if [ -z "${TESTJAVA}" ] ; then
 131    # TESTJAVA is not set, so the test is running stand-alone.
 132    # TESTJAVA holds the path to the root directory of the build of the JDK
 133    # to be tested.  That is, any java files run explicitly in this shell
 134    # should use TESTJAVA in the path to the java interpreter.
 135    # So, we'll set this to the JDK spec'd on the command line.  If none
 136    # is given on the command line, tell the user that and use a cheesy
 137    # default.
 138    # THIS IS THE JDK BEING TESTED.
 139    if [ -n "$1" ] ;
 140       then TESTJAVA=$1
 141       else echo "no JDK specified on command line so using default!"
 142          TESTJAVA=$DEFAULT_JDK
 143    fi
 144    TESTSRC=.
 145    TESTCLASSES=.
 146    STANDALONE=1;
 147 fi
 148 echo "JDK under test is: $TESTJAVA"
 149 
 150 
 151 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 152 
 153 #All files required for the test should be in the same directory with
 154 # this file.  If converting a standalone test to run with the harness,
 155 # as long as all files are in the same directory and it returns 0 for
 156 # pass, you should be able to cut and paste it into here and it will
 157 # run with the test harness.
 158 
 159 # This is an example of running something -- test
 160 # The stuff below catches the exit status of test then passes or fails
 161 # this shell test as appropriate ( 0 status is considered a pass here )
 162 
 163 echo "Create TestApp.jar..."
 164 
 165 if [ -f TestApp.jar ] ; then
 166     rm -f TestApp.jar
 167 fi
 168 
 169 ${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp
 170 
 171 if [ $? -ne "0" ] ; then
 172     fail "Failed to create TestApp.jar"
 173 fi
 174 
 175 echo "Create Test.jar..."
 176 if [ -f Test.jar ] ; then
 177     rm -f Test.jar
 178 fi
 179 
 180 ${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test
 181 
 182 if [ $? -ne 0 ] ; then
 183     fail "Failed to create Test.jar"
 184 fi
 185 
 186 # Prepare temp dir for cahce files
 187 mkdir ./tmp
 188 if [ $? -ne 0 ] ; then
 189     fail "Unable to create temp directory."
 190 fi
 191 
 192 # Verify that all classoladers are destroyed
 193 ${TESTJAVA}/bin/java -cp Test.jar test.Main
 194 if [ $? -ne 0 ] ; then
 195     fail "Test FAILED: some classloaders weren't destroyed."
 196 fi
 197 
 198 
 199 # Verify that ImageIO shutdown hook works correcly
 200 ${TESTJAVA}/bin/java -cp Test.jar -DforgetSomeStreams=true test.Main
 201 if [ $? -ne 0 ] ; then
 202     fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed."
 203 fi
 204 
 205 # sanity check: verify that all cache files were deleted
 206 cache_files=`ls tmp`
 207 
 208 if [ "x${cache_files}" != "x" ] ; then
 209     echo "WARNING: some cache files was not deleted: ${cache_files}"
 210 fi
 211 
 212 echo "Test done."
 213 
 214 status=$?
 215 
 216 if [ $status -eq "0" ] ; then
 217     pass ""
 218 else
 219     fail "Test failed due to test plugin was not found."
 220 fi
 221