run_test.sh revision 6073:cea72c2bf071
1185922Simp#!/bin/ksh -p
2185922Simp#
3185922Simp# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
4185922Simp# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5185922Simp#
6185922Simp# This code is free software; you can redistribute it and/or modify it
7185922Simp# under the terms of the GNU General Public License version 2 only, as
8185922Simp# published by the Free Software Foundation.
9185922Simp#
10185922Simp# This code is distributed in the hope that it will be useful, but WITHOUT
11185922Simp# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12185922Simp# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13185922Simp# version 2 for more details (a copy is included in the LICENSE file that
14185922Simp# accompanied this code).
15185922Simp#
16185922Simp# You should have received a copy of the GNU General Public License version
17185922Simp# 2 along with this work; if not, write to the Free Software Foundation,
18185922Simp# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19185922Simp#
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:
52status=1
53
54#Call this from anywhere to fail the test with an error message
55# usage: fail "reason why the test failed"
56fail()
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"
65pass()
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
77OS=`uname -s`
78case "$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 | Darwin )
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 | CYGWIN* )
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      ;;
108esac
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
114if [ -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;
131fi
132echo "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
147echo "Create TestApp.jar..."
148
149if [ -f TestApp.jar ] ; then
150    rm -f TestApp.jar
151fi
152
153${TESTJAVA}/bin/jar -cvf TestApp.jar -C ${TESTCLASSES} testapp
154
155if [ $? -ne "0" ] ; then
156    fail "Failed to create TestApp.jar"
157fi
158
159echo "Create Test.jar..."
160if [ -f Test.jar ] ; then
161    rm -f Test.jar
162fi
163
164${TESTJAVA}/bin/jar -cvf Test.jar -C ${TESTCLASSES} test
165
166if [ $? -ne 0 ] ; then
167    fail "Failed to create Test.jar"
168fi
169
170# Prepare temp dir for cahce files
171mkdir ./tmp
172if [ $? -ne 0 ] ; then
173    fail "Unable to create temp directory."
174fi
175
176# Verify that all classoladers are destroyed
177${TESTJAVA}/bin/java -cp Test.jar test.Main
178if [ $? -ne 0 ] ; then
179    fail "Test FAILED: some classloaders weren't destroyed."
180fi
181
182
183# Verify that ImageIO shutdown hook works correcly
184${TESTJAVA}/bin/java -cp Test.jar -DforgetSomeStreams=true test.Main
185if [ $? -ne 0 ] ; then
186    fail "Test FAILED: some classloaders weren't destroyed of shutdown hook failed."
187fi
188
189# sanity check: verify that all cache files were deleted
190cache_files=`ls tmp`
191
192if [ "x${cache_files}" != "x" ] ; then
193    echo "WARNING: some cache files was not deleted: ${cache_files}"
194fi
195
196echo "Test done."
197
198status=$?
199
200if [ $status -eq "0" ] ; then
201    pass ""
202else
203    fail "Test failed due to test plugin was not found."
204fi
205
206