Path: blob/master/test/jdk/javax/imageio/stream/StreamCloserLeak/run_test.sh
41153 views
#!/bin/ksh -p1#2# Copyright (c) 2009, 2020, 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 it6# under the terms of the GNU General Public License version 2 only, as7# published by the Free Software Foundation.8#9# This code is distributed in the hope that it will be useful, but WITHOUT10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12# version 2 for more details (a copy is included in the LICENSE file that13# accompanied this code).14#15# You should have received a copy of the GNU General Public License version16# 2 along with this work; if not, write to the Free Software Foundation,17# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18#19# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20# or visit www.oracle.com if you need additional information or have any21# questions.22#2324#25# @test26# @bug 678809627# @key intermittent28# @summary Test simulates the case of multiple applets executed in29# the same VM and verifies that ImageIO shutdown hook30# StreamCloser does not cause a leak of classloaders.31#32# @modules java.desktop/sun.awt33# @build test.Main34# @build testapp.Main35# @run shell run_test.sh3637# There are several resources which need to be present before many38# shell scripts can run. Following are examples of how to check for39# many common ones.40#41# Note that the shell used is the Korn Shell, KSH42#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 a48# Solaris or Win32 machine, which is more difficult (if even possible)49# in a make file.505152# Beginning of subroutines:53status=15455#Call this from anywhere to fail the test with an error message56# usage: fail "reason why the test failed"57fail()58{ echo "The test failed :-("59echo "$*" 1>&260echo "exit status was $status"61exit $status62} #end of fail()6364#Call this from anywhere to pass the test with a message65# usage: pass "reason why the test passed if applicable"66pass()67{ echo "The test passed!!!"68echo "$*" 1>&269exit 070} #end of pass()7172# end of subroutines737475# The beginning of the script proper7677# Checking for proper OS78OS=`uname -s`79case "$OS" in80Linux )81VAR="A different value for Linux"82DEFAULT_JDK=/83FILESEP="/"84PATHSEP=":"85TMP="/tmp"86;;8788AIX )89VAR="A different value for AIX"90DEFAULT_JDK=/91FILESEP="/"92PATHSEP=":"93TMP="/tmp"94;;9596Darwin )97VAR="A different value for MacOSX"98DEFAULT_JDK=/usr99FILESEP="/"100PATHSEP=":"101TMP="/tmp"102;;103104Windows* )105VAR="A different value for Win32"106DEFAULT_JDK="C:/Program Files/Java/jdk1.8.0"107FILESEP="\\"108PATHSEP=";"109TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`110;;111112CYGWIN* )113VAR="A different value for Cygwin"114DEFAULT_JDK="/cygdrive/c/Program\ Files/Java/jdk1.8.0"115FILESEP="/"116PATHSEP=";"117TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`118;;119120# catch all other OSs121* )122echo "Unrecognized system! $OS"123fail "Unrecognized system! $OS"124;;125esac126127# Want this test to run standalone as well as in the harness, so do the128# following to copy the test's directory into the harness's scratch directory129# and set all appropriate variables:130131if [ -z "${TESTJAVA}" ] ; then132# TESTJAVA is not set, so the test is running stand-alone.133# TESTJAVA holds the path to the root directory of the build of the JDK134# to be tested. That is, any java files run explicitly in this shell135# should use TESTJAVA in the path to the java interpreter.136# So, we'll set this to the JDK spec'd on the command line. If none137# is given on the command line, tell the user that and use a cheesy138# default.139# THIS IS THE JDK BEING TESTED.140if [ -n "$1" ] ;141then TESTJAVA=$1142else echo "no JDK specified on command line so using default!"143TESTJAVA=$DEFAULT_JDK144fi145TESTSRC=.146TESTCLASSES=.147STANDALONE=1;148fi149echo "JDK under test is: $TESTJAVA"150151152############### YOUR TEST CODE HERE!!!!!!! #############153154#All files required for the test should be in the same directory with155# this file. If converting a standalone test to run with the harness,156# as long as all files are in the same directory and it returns 0 for157# pass, you should be able to cut and paste it into here and it will158# run with the test harness.159160# This is an example of running something -- test161# The stuff below catches the exit status of test then passes or fails162# this shell test as appropriate ( 0 status is considered a pass here )163164echo "Create TestApp.jar..."165166if [ -f TestApp.jar ] ; then167rm -f TestApp.jar168fi169170${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp171172if [ $? -ne "0" ] ; then173fail "Failed to create TestApp.jar"174fi175176echo "Create Test.jar..."177if [ -f Test.jar ] ; then178rm -f Test.jar179fi180181${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test182183if [ $? -ne 0 ] ; then184fail "Failed to create Test.jar"185fi186187# Prepare temp dir for cahce files188mkdir ./tmp189if [ $? -ne 0 ] ; then190fail "Unable to create temp directory."191fi192193# Verify that all classloaders are destroyed194${TESTJAVA}/bin/java --add-exports java.desktop/sun.awt=ALL-UNNAMED ${TESTVMOPTS} -cp Test.jar test.Main195if [ $? -ne 0 ] ; then196fail "Test FAILED: some classloaders weren't destroyed."197fi198199200# Verify that ImageIO shutdown hook works correcly201${TESTJAVA}/bin/java --add-exports java.desktop/sun.awt=ALL-UNNAMED ${TESTVMOPTS} \202-cp Test.jar -DforgetSomeStreams=true test.Main203if [ $? -ne 0 ] ; then204fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed."205fi206207# sanity check: verify that all cache files were deleted208cache_files=`ls tmp`209210if [ "x${cache_files}" != "x" ] ; then211echo "WARNING: some cache files was not deleted: ${cache_files}"212fi213214echo "Test done."215216status=$?217218if [ $status -eq "0" ] ; then219pass ""220else221fail "Test failed due to test plugin was not found."222fi223224225226