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