author | coleenp |
Wed, 10 May 2017 14:03:33 +0000 | |
changeset 46450 | 7a361ede7817 |
parent 43972 | 1ade39b8381b |
child 46987 | 21919641299f |
permissions | -rw-r--r-- |
33160 | 1 |
/* |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33160 | 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 |
||
24 |
/** |
|
25 |
* @test |
|
26 |
* @bug 8136421 |
|
42607
acd91f1875d4
8170227: use vm.jvmci property in compiler/jvmci tests
iignatyev
parents:
41705
diff
changeset
|
27 |
* @requires vm.jvmci |
40631
ed82623d7831
8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents:
40059
diff
changeset
|
28 |
* @library /test/lib / |
36508 | 29 |
* @library common/patches |
38152
80e5da81fb2c
8154258: [TESTBUG] Various serviceability tests fail compilation
dsamersoff
parents:
36508
diff
changeset
|
30 |
* @modules java.base/jdk.internal.misc |
43972 | 31 |
* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot |
32 |
* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper |
|
36508 | 33 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions |
33632 | 34 |
* -XX:+EnableJVMCI |
33160 | 35 |
* compiler.jvmci.SecurityRestrictionsTest |
36 |
* NO_SEC_MAN |
|
36508 | 37 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions |
33632 | 38 |
* -XX:+EnableJVMCI |
33160 | 39 |
* compiler.jvmci.SecurityRestrictionsTest |
40 |
* NO_PERM |
|
36508 | 41 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions |
33632 | 42 |
* -XX:+EnableJVMCI |
33160 | 43 |
* compiler.jvmci.SecurityRestrictionsTest |
44 |
* ALL_PERM |
|
36508 | 45 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions |
33632 | 46 |
* -XX:+EnableJVMCI |
33160 | 47 |
* compiler.jvmci.SecurityRestrictionsTest |
48 |
* NO_JVMCI_ACCESS_PERM |
|
36508 | 49 |
* @run main/othervm -XX:+UnlockExperimentalVMOptions |
33632 | 50 |
* -XX:-EnableJVMCI |
33160 | 51 |
* compiler.jvmci.SecurityRestrictionsTest |
52 |
* NO_JVMCI |
|
53 |
*/ |
|
54 |
||
55 |
package compiler.jvmci; |
|
56 |
||
57 |
import jdk.test.lib.Utils; |
|
40059 | 58 |
|
33160 | 59 |
import java.security.AccessControlException; |
60 |
import java.security.Permission; |
|
33183
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
61 |
import java.util.PropertyPermission; |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
62 |
import java.util.function.Consumer; |
33160 | 63 |
|
64 |
public class SecurityRestrictionsTest { |
|
65 |
||
66 |
public static void main(String[] args) { |
|
67 |
try { |
|
68 |
// to init Utils before call SecurityManager |
|
69 |
Class.forName(Utils.class.getName(), true, |
|
70 |
Utils.class.getClassLoader()); |
|
71 |
} catch (ClassNotFoundException e) { |
|
72 |
throw new Error("[TEST BUG]: jdk.test.lib.Utils not found", e); |
|
73 |
} |
|
74 |
try { |
|
75 |
TestCase mode = TestCase.valueOf(args[0]); |
|
76 |
mode.run(); |
|
77 |
} catch (IllegalArgumentException e) { |
|
78 |
throw new Error("[TEST BUG]: Unknown mode " + args[0], e); |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
private enum TestCase { |
|
83 |
NO_SEC_MAN, |
|
84 |
NO_JVMCI { |
|
85 |
@Override |
|
86 |
public Class<? extends Throwable> getExpectedException() { |
|
87 |
return InternalError.class; |
|
88 |
} |
|
89 |
}, |
|
90 |
ALL_PERM { |
|
91 |
@Override |
|
92 |
public SecurityManager getSecurityManager() { |
|
93 |
return new SecurityManager() { |
|
94 |
@Override |
|
95 |
public void checkPermission(Permission perm) { |
|
96 |
} |
|
97 |
}; |
|
98 |
} |
|
99 |
}, |
|
100 |
NO_PERM { |
|
101 |
@Override |
|
102 |
public SecurityManager getSecurityManager() { |
|
103 |
return new SecurityManager(); |
|
104 |
} |
|
105 |
||
106 |
@Override |
|
107 |
public Class<? extends Throwable> getExpectedException() { |
|
108 |
return AccessControlException.class; |
|
109 |
} |
|
110 |
}, |
|
111 |
NO_JVMCI_ACCESS_PERM { |
|
112 |
@Override |
|
113 |
public SecurityManager getSecurityManager() { |
|
114 |
return new SecurityManager() { |
|
115 |
@Override |
|
116 |
public void checkPermission(Permission perm) { |
|
117 |
if (isJvmciPermission(perm)) { |
|
118 |
super.checkPermission(perm); |
|
119 |
} |
|
120 |
} |
|
121 |
||
122 |
@Override |
|
123 |
public void checkPropertyAccess(String key) { |
|
124 |
if (key.startsWith(JVMCI_PROP_START)) { |
|
125 |
super.checkPropertyAccess(key); |
|
126 |
} |
|
127 |
} |
|
128 |
}; |
|
129 |
} |
|
130 |
||
131 |
private boolean isJvmciPermission(Permission perm) { |
|
132 |
String name = perm.getName(); |
|
33183
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
133 |
boolean isJvmciRuntime = perm instanceof RuntimePermission |
33160 | 134 |
&& (JVMCI_SERVICES.equals(name) |
33183
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
135 |
|| name.startsWith(JVMCI_RT_PERM_START)); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
136 |
boolean isJvmciProperty = perm instanceof PropertyPermission |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
137 |
&& name.startsWith(JVMCI_PROP_START); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
138 |
return isJvmciRuntime || isJvmciProperty; |
33160 | 139 |
} |
140 |
||
141 |
@Override |
|
142 |
public Class<? extends Throwable> getExpectedException() { |
|
143 |
return AccessControlException.class; |
|
144 |
} |
|
145 |
}; |
|
146 |
||
147 |
public void run() { |
|
148 |
System.setSecurityManager(getSecurityManager()); |
|
33183
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
149 |
Consumer<Throwable> exceptionCheck = e -> { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
150 |
if (e == null) { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
151 |
if (getExpectedException() != null) { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
152 |
String message = name() + ": Didn't get expected exception " |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
153 |
+ getExpectedException(); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
154 |
throw new AssertionError(message); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
155 |
} |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
156 |
} else { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
157 |
String message = name() + ": Got unexpected exception " |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
158 |
+ e.getClass().getSimpleName(); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
159 |
if (getExpectedException() == null){ |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
160 |
throw new AssertionError(message, e); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
161 |
} |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
162 |
|
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
163 |
Throwable t = e; |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
164 |
while (t.getCause() != null) { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
165 |
t = t.getCause(); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
166 |
} |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
167 |
if (!getExpectedException().isAssignableFrom(t.getClass())) { |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
168 |
message += " instead of " + getExpectedException() |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
169 |
.getSimpleName(); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
170 |
throw new AssertionError(message, e); |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
171 |
} |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
172 |
} |
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
173 |
}; |
33632 | 174 |
Utils.runAndCheckException(() -> { |
175 |
try { |
|
176 |
// CompilerToVM::<cinit> provokes CompilerToVM::<init> |
|
177 |
Class.forName("jdk.vm.ci.hotspot.CompilerToVMHelper"); |
|
178 |
} catch (ClassNotFoundException e) { |
|
179 |
throw new Error("TESTBUG : " + e, e); |
|
180 |
} |
|
181 |
}, exceptionCheck); |
|
33160 | 182 |
} |
183 |
||
184 |
public SecurityManager getSecurityManager() { |
|
185 |
return null; |
|
186 |
} |
|
187 |
||
188 |
public Class<? extends Throwable> getExpectedException() { |
|
189 |
return null; |
|
190 |
} |
|
191 |
||
192 |
private static final String JVMCI_RT_PERM_START |
|
193 |
= "accessClassInPackage.jdk.vm.ci"; |
|
194 |
private static final String JVMCI_SERVICES = "jvmciServices"; |
|
195 |
private static final String JVMCI_PROP_START = "jvmci."; |
|
33183
1ee801e82dda
8139375: [TESTBUG] compiler/jvmci/SecurityRestrictionsTest checks are too tight
tpivovarova
parents:
33160
diff
changeset
|
196 |
|
33160 | 197 |
} |
198 |
} |