Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/spi/AppletContextTest/BadPluginConfigurationTest.sh
38853 views
1
#!/bin/ksh -p
2
# Copyright (c) 2005, 2017, 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 it
6
# under the terms of the GNU General Public License version 2 only, as
7
# published by the Free Software Foundation.
8
#
9
# This code is distributed in the hope that it will be useful, but WITHOUT
10
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
# version 2 for more details (a copy is included in the LICENSE file that
13
# accompanied this code).
14
#
15
# You should have received a copy of the GNU General Public License version
16
# 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 USA
20
# or visit www.oracle.com if you need additional information or have any
21
# questions.
22
#
23
# @test
24
#
25
# @bug 6342404 7078379 8167503 8183351
26
#
27
# @summary Test verifies that incorrectly configured ImageIO plugin spi
28
# does not affect registration of other ImageIO plugin in the
29
# applet context.
30
#
31
#
32
# @compile IIOPluginTest.java
33
# @compile DummyReaderPluginSpi.java
34
# @run shell BadPluginConfigurationTest.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
clean
61
exit $status
62
} #end of fail()
63
64
#Call this from anywhere to pass the test with a message
65
# usage: pass "reason why the test passed if applicable"
66
pass()
67
{ echo "The test passed!!!"
68
echo "$*" 1>&2
69
clean
70
exit 0
71
} #end of pass()
72
73
#Clean up the test_ext directory (PLUGINDST_DIR) before leaving
74
clean()
75
{
76
echo "Removing PLUGINDST_DIR ${PLUGINDST_DIR}"
77
if [ -n "${PLUGINDST_DIR}" -a -d "${PLUGINDST_DIR}" ] ; then
78
rm -rf "${PLUGINDST_DIR}"
79
fi
80
}
81
82
# end of subroutines
83
84
85
# The beginning of the script proper
86
87
# Checking for proper OS
88
OS=`uname -s`
89
case "$OS" in
90
SunOS | Linux | Darwin )
91
FILESEP="/"
92
PATHSEP=":"
93
TMP=`cd /tmp; pwd -P`
94
;;
95
96
Windows* )
97
FILESEP="\\"
98
PATHSEP=";"
99
TMP=`cd "${SystemRoot}/Temp"; echo ${PWD}`
100
;;
101
102
CYGWIN* )
103
FILESEP="/"
104
PATHSEP=";"
105
TMP="/tmp"
106
;;
107
108
# catch all other OSs
109
* )
110
echo "Unrecognized system! $OS"
111
fail "Unrecognized system! $OS"
112
;;
113
esac
114
115
# Want this test to run standalone as well as in the harness, so do the
116
# following to copy the test's directory into the harness's scratch directory
117
# and set all appropriate variables:
118
119
if [ -z "${TESTJAVA}" ] ; then
120
# TESTJAVA is not set, so the test is running stand-alone.
121
# TESTJAVA holds the path to the root directory of the build of the JDK
122
# to be tested. That is, any java files run explicitly in this shell
123
# should use TESTJAVA in the path to the java interpreter.
124
# So, we'll set this to the JDK spec'd on the command line. If none
125
# is given on the command line, tell the user that and use a cheesy
126
# default.
127
# THIS IS THE JDK BEING TESTED.
128
if [ -n "$1" ] ;
129
then TESTJAVA=$1
130
else fail "no JDK specified on command line!"
131
fi
132
TESTSRC=.
133
TESTCLASSES=.
134
STANDALONE=1;
135
fi
136
echo "JDK under test is: $TESTJAVA"
137
138
#Deal with .class files:
139
if [ -n "${STANDALONE}" ] ;
140
then
141
#if standalone, remind user to cd to dir. containing test before running it
142
echo "Just a reminder: cd to the dir containing this test when running it"
143
# then compile all .java files (if there are any) into .class files
144
if [ -a *.java ] ;
145
then echo "Reminder, this test should be in its own directory with all"
146
echo "supporting files it needs in the directory with it."
147
${COMPILEJAVA}/bin/javac ./*.java ;
148
fi
149
# else in harness so copy all the class files from where jtreg put them
150
# over to the scratch directory this test is running in.
151
else cp ${TESTCLASSES}/*.class . ;
152
fi
153
154
#if in test harness, then copy the entire directory that the test is in over
155
# to the scratch directory. This catches any support files needed by the test.
156
if [ -z "${STANDALONE}" ] ;
157
then cp ${TESTSRC}/*.java .
158
fi
159
160
#Just before executing anything, make sure it has executable permission!
161
chmod 777 ./*
162
163
############### YOUR TEST CODE HERE!!!!!!! #############
164
165
#All files required for the test should be in the same directory with
166
# this file. If converting a standalone test to run with the harness,
167
# as long as all files are in the same directory and it returns 0 for
168
# pass, you should be able to cut and paste it into here and it will
169
# run with the test harness.
170
171
# This is an example of running something -- test
172
# The stuff below catches the exit status of test then passes or fails
173
# this shell test as appropriate ( 0 status is considered a pass here )
174
175
echo
176
echo ------ PREPARE TEST PLUGIN ---------
177
178
# note that we can not use some subdirectory of the
179
# scratch dir as the plugin dst dir because the test
180
# app have file read permission for all subdirs of the
181
# scratch dir
182
183
PLUGINDST_DIR=$(mktemp -d ${TMP}/iio_test.XXXXXXXX)
184
echo "Created PLUGINDST_DIR as ${PLUGINDST_DIR}"
185
186
TEST_PLUGIN=dummy.jar
187
188
# remove old service declaration
189
if [ -d META-INF ] ; then
190
rm -rf META-INF
191
fi
192
193
# generate the service declaration
194
if [ ! -d META_INF ] ; then
195
mkdir META-INF
196
mkdir META-INF/services
197
fi
198
199
# add wrong record to the service configuration
200
echo "BadReaderPluginSpi" > META-INF/services/javax.imageio.spi.ImageReaderSpi
201
202
echo "DummyReaderPluginSpi" >> META-INF/services/javax.imageio.spi.ImageReaderSpi
203
204
205
${TESTJAVA}/bin/jar -cvf ${TEST_PLUGIN} DummyReaderPluginSpi*.class META-INF/services/javax.imageio.spi.ImageReaderSpi
206
207
echo ----- TEST PLUGIN IS READY --------
208
echo
209
echo ----- INSTALL PLUGIN --------
210
echo "Install test plugin to ${PLUGINDST_DIR}"
211
if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then
212
echo "Remove old plugin..."
213
rm -f ${PLUGINDST_DIR}/${TEST_PLUGIN}
214
fi
215
mv -f ${TEST_PLUGIN} ${PLUGINDST_DIR}
216
if [ -f ${PLUGINDST_DIR}/${TEST_PLUGIN} ] ; then
217
echo Test plugin is installed.
218
else
219
fail "Unable to install test plugin to $PLUGINDST_DIR"
220
fi
221
echo ----- PLUGIN IS INSTALLED ------
222
echo
223
echo ----- CLEAN PLUGIN TEMPORARY FILES -----
224
rm -rf DummyReaderPluginSpi*.class META-INF
225
echo ----- CLEANING IS COMPLETE -------
226
echo
227
228
229
case "$OS" in
230
CYGWIN* )
231
TEST_CODEBASE=$(cygpath -m ${PWD})
232
TEST_PLUGIN_JAR=$(cygpath -m ${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN})
233
;;
234
235
# catch all other OSs
236
* )
237
TEST_CODEBASE=${PWD}
238
TEST_PLUGIN_JAR=${PLUGINDST_DIR}${FILESEP}${TEST_PLUGIN}
239
;;
240
esac
241
242
243
# Update policy file to grant read permission
244
echo "grant codeBase \"file:${TEST_CODEBASE}\" {" > classpath.policy
245
echo " permission java.io.FilePermission \"${TEST_PLUGIN_JAR}\", \"read\";" >> classpath.policy
246
echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy
247
echo "};" >> classpath.policy
248
echo "grant codeBase \"file:${TEST_PLUGIN_JAR}\" {" >> classpath.policy
249
echo " permission java.util.PropertyPermission \"test.5076692.property\", \"read\";" >> classpath.policy
250
echo "};" >> classpath.policy
251
252
echo ---------------------
253
echo --- Applet policy ---
254
echo ---------------------
255
cat classpath.policy
256
echo ---------------------
257
echo
258
259
echo -------------------------------
260
echo --- Applet Classpath Test ---
261
echo -------------------------------
262
#
263
# please note that we need to use "==" in setup of the java.security.policy
264
# property in order to overwrite policies defined in the user policy file
265
# For more details see:
266
# http://java.sun.com/j2se/1.5.0/docs/guide/security/PolicyFiles.html)
267
#
268
269
${TESTJAVA}/bin/java ${TESTVMOPTS} -cp ".${PATHSEP}${TEST_PLUGIN_JAR}" \
270
-Djava.security.policy==classpath.policy \
271
-Djava.security.manager IIOPluginTest
272
273
status=$?
274
275
if [ $status -eq "0" ] ; then
276
pass ""
277
else
278
fail "Test failed due to test plugin was not found."
279
fi
280
281
282