1 #!/bin/ksh -p
   2 #
   3 # Copyright 2009 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  21 # CA 95054 USA or visit www.sun.com if you need additional information or
  22 # have any 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=/usr/local/java/jdk1.2/solaris
  82       FILESEP="/"
  83       PATHSEP=":"
  84       TMP="/tmp"
  85       ;;
  86 
  87    Linux )
  88       VAR="A different value for Linux"
  89       DEFAULT_JDK=/usr/local/java/jdk1.4/linux-i386
  90       FILESEP="/"
  91       PATHSEP=":"
  92       TMP="/tmp"
  93       ;;
  94 
  95    Windows_95 | Windows_98 | Windows_NT | Windows_ME )
  96       VAR="A different value for Win32"
  97       DEFAULT_JDK=/usr/local/java/jdk1.2/win32
  98       FILESEP="\\"
  99       PATHSEP=";"
 100       TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
 101       ;;
 102 
 103    # catch all other OSs
 104    * )
 105       echo "Unrecognized system!  $OS"
 106       fail "Unrecognized system!  $OS"
 107       ;;
 108 esac
 109 
 110 # Want this test to run standalone as well as in the harness, so do the
 111 #  following to copy the test's directory into the harness's scratch directory
 112 #  and set all appropriate variables:
 113 
 114 if [ -z "${TESTJAVA}" ] ; then
 115    # TESTJAVA is not set, so the test is running stand-alone.
 116    # TESTJAVA holds the path to the root directory of the build of the JDK
 117    # to be tested.  That is, any java files run explicitly in this shell
 118    # should use TESTJAVA in the path to the java interpreter.
 119    # So, we'll set this to the JDK spec'd on the command line.  If none
 120    # is given on the command line, tell the user that and use a cheesy
 121    # default.
 122    # THIS IS THE JDK BEING TESTED.
 123    if [ -n "$1" ] ;
 124       then TESTJAVA=$1
 125       else echo "no JDK specified on command line so using default!"
 126          TESTJAVA=$DEFAULT_JDK
 127    fi
 128    TESTSRC=.
 129    TESTCLASSES=.
 130    STANDALONE=1;
 131 fi
 132 echo "JDK under test is: $TESTJAVA"
 133 
 134 
 135 ###############  YOUR TEST CODE HERE!!!!!!!  #############
 136 
 137 #All files required for the test should be in the same directory with
 138 # this file.  If converting a standalone test to run with the harness,
 139 # as long as all files are in the same directory and it returns 0 for
 140 # pass, you should be able to cut and paste it into here and it will
 141 # run with the test harness.
 142 
 143 # This is an example of running something -- test
 144 # The stuff below catches the exit status of test then passes or fails
 145 # this shell test as appropriate ( 0 status is considered a pass here )
 146 
 147 echo "Create TestApp.jar..."
 148 
 149 if [ -f TestApp.jar ] ; then
 150     rm -f TestApp.jar
 151 fi
 152 
 153 ${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp
 154 
 155 if [ $? -ne "0" ] ; then
 156     fail "Failed to create TestApp.jar"
 157 fi
 158 
 159 echo "Create Test.jar..."
 160 if [ -f Test.jar ] ; then
 161     rm -f Test.jar
 162 fi
 163 
 164 ${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test
 165 
 166 if [ $? -ne 0 ] ; then
 167     fail "Failed to create Test.jar"
 168 fi
 169 
 170 # Prepare temp dir for cahce files
 171 mkdir ./tmp
 172 if [ $? -ne 0 ] ; then
 173     fail "Unable to create temp directory."
 174 fi
 175 
 176 # Verify that all classoladers are destroyed
 177 ${TESTJAVA}/bin/java -cp Test.jar test.Main
 178 if [ $? -ne 0 ] ; then
 179     fail "Test FAILED: some classloaders weren't destroyed."
 180 fi
 181 
 182 
 183 # Verify that ImageIO shutdown hook works correcly
 184 ${TESTJAVA}/bin/java -cp Test.jar -DforgetSomeStreams=true test.Main
 185 if [ $? -ne 0 ] ; then
 186     fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed."
 187 fi
 188 
 189 # sanity check: verify that all cache files were deleted
 190 cache_files=`ls tmp`
 191 
 192 if [ "x${cache_files}" != "x" ] ; then
 193     echo "WARNING: some cache files was not deleted: ${cache_files}"
 194 fi
 195 
 196 echo "Test done."
 197 
 198 status=$?
 199 
 200 if [ $status -eq "0" ] ; then
 201     pass ""
 202 else
 203     fail "Test failed due to test plugin was not found."
 204 fi
 205