author | sundar |
Thu, 28 Jul 2016 19:34:58 +0530 | |
changeset 39834 | 53a6fb443c20 |
parent 39321 | c60f34e8c057 |
child 40124 | 01f8745abd3c |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
2 |
* Copyright (c) 2015, 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 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @summary Test exclude VM plugin |
|
27 |
* @author Jean-Francois Denise |
|
28 |
* @modules jdk.jlink/jdk.tools.jlink.internal |
|
29 |
* jdk.jlink/jdk.tools.jlink.internal.plugins |
|
30 |
* @run main ExcludeVMPluginTest |
|
31 |
*/ |
|
32 |
import java.io.ByteArrayInputStream; |
|
33 |
import java.util.HashMap; |
|
34 |
import java.util.Map; |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
35 |
import jdk.tools.jlink.internal.ResourcePoolManager; |
36511 | 36 |
|
37 |
import jdk.tools.jlink.internal.plugins.ExcludeVMPlugin; |
|
38 |
import jdk.tools.jlink.plugin.Plugin; |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
39 |
import jdk.tools.jlink.plugin.ResourcePool; |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
40 |
import jdk.tools.jlink.plugin.ResourcePoolEntry; |
36511 | 41 |
|
42 |
public class ExcludeVMPluginTest { |
|
43 |
||
44 |
private static final String TAG = "# orig in test\n"; |
|
45 |
||
46 |
private static final String[] ARCHITECTURES = {"/", "/amd64/", "/i386/", "/arm/", |
|
47 |
"/aarch64/", "/toto/"}; |
|
48 |
||
49 |
private static final String[] CLIENT = {"client/" + jvmlib(),}; |
|
50 |
private static final String[] SERVER = {"server/" + jvmlib()}; |
|
51 |
private static final String[] MINIMAL = {"minimal/" + jvmlib()}; |
|
52 |
private static final String[] ALL = {CLIENT[0], SERVER[0], MINIMAL[0]}; |
|
53 |
private static final String JVM_CFG_ALL = TAG + "-server KNOWN\n-client KNOWN\n-minimal KNOWN\n"; |
|
54 |
private static final String JVM_CFG_CLIENT = TAG + "-client KNOWN\n"; |
|
55 |
private static final String JVM_CFG_SERVER = TAG + "-server KNOWN\n"; |
|
56 |
private static final String JVM_CFG_SERVER_ALIAS_OTHERS = TAG + "-server KNOWN\n-client ALIASED_TO -server\n-minimal ALIASED_TO -server\n"; |
|
57 |
private static final String JVM_CFG_CLIENT_ALIAS_OTHERS = TAG + "-client KNOWN\n-server ALIASED_TO -client\n-minimal ALIASED_TO -client\n"; |
|
58 |
private static final String JVM_CFG_MINIMAL_ALIAS_OTHERS = TAG + "-minimal KNOWN\n-server ALIASED_TO -minimal\n-client ALIASED_TO -minimal\n"; |
|
59 |
private static final String JVM_CFG_MINIMAL = TAG + "-minimal KNOWN\n"; |
|
60 |
||
61 |
public static void main(String[] args) throws Exception { |
|
62 |
new ExcludeVMPluginTest().test(); |
|
63 |
} |
|
64 |
||
65 |
public void test() throws Exception { |
|
66 |
boolean failed = false; |
|
67 |
||
68 |
try { |
|
69 |
checkVM("toto", ALL, JVM_CFG_ALL, ALL, JVM_CFG_ALL); |
|
70 |
failed = true; |
|
71 |
throw new Exception("Should have failed"); |
|
72 |
} catch (Exception ex) { |
|
73 |
if (failed) { |
|
74 |
throw ex; |
|
75 |
} |
|
76 |
} |
|
77 |
||
78 |
checkVM("all", ALL, JVM_CFG_ALL, ALL, JVM_CFG_ALL); |
|
79 |
checkVM("all", CLIENT, JVM_CFG_CLIENT, CLIENT, JVM_CFG_CLIENT); |
|
80 |
checkVM("all", SERVER, JVM_CFG_SERVER, SERVER, JVM_CFG_SERVER); |
|
81 |
checkVM("all", MINIMAL, JVM_CFG_MINIMAL, MINIMAL, JVM_CFG_MINIMAL); |
|
82 |
||
83 |
checkVM("server", ALL, JVM_CFG_ALL, SERVER, JVM_CFG_SERVER_ALIAS_OTHERS); |
|
84 |
checkVM("server", SERVER, JVM_CFG_SERVER, SERVER, JVM_CFG_SERVER); |
|
85 |
try { |
|
86 |
checkVM("server", CLIENT, JVM_CFG_CLIENT, SERVER, JVM_CFG_SERVER); |
|
87 |
failed = true; |
|
88 |
throw new Exception("Should have failed"); |
|
89 |
} catch (Exception ex) { |
|
90 |
if (failed) { |
|
91 |
throw ex; |
|
92 |
} |
|
93 |
} |
|
94 |
try { |
|
95 |
checkVM("server", MINIMAL, JVM_CFG_MINIMAL, SERVER, JVM_CFG_SERVER); |
|
96 |
failed = true; |
|
97 |
throw new Exception("Should have failed"); |
|
98 |
} catch (Exception ex) { |
|
99 |
if (failed) { |
|
100 |
throw ex; |
|
101 |
} |
|
102 |
} |
|
103 |
||
104 |
checkVM("client", ALL, JVM_CFG_ALL, CLIENT, JVM_CFG_CLIENT_ALIAS_OTHERS); |
|
105 |
checkVM("client", CLIENT, JVM_CFG_CLIENT, CLIENT, JVM_CFG_CLIENT); |
|
106 |
try { |
|
107 |
checkVM("client", SERVER, JVM_CFG_SERVER, CLIENT, JVM_CFG_CLIENT); |
|
108 |
failed = true; |
|
109 |
throw new Exception("Should have failed"); |
|
110 |
} catch (Exception ex) { |
|
111 |
if (failed) { |
|
112 |
throw ex; |
|
113 |
} |
|
114 |
} |
|
115 |
try { |
|
116 |
checkVM("client", MINIMAL, JVM_CFG_MINIMAL, CLIENT, JVM_CFG_CLIENT); |
|
117 |
failed = true; |
|
118 |
throw new Exception("Should have failed"); |
|
119 |
} catch (Exception ex) { |
|
120 |
if (failed) { |
|
121 |
throw ex; |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
checkVM("minimal", ALL, JVM_CFG_ALL, MINIMAL, JVM_CFG_MINIMAL_ALIAS_OTHERS); |
|
126 |
checkVM("minimal", MINIMAL, JVM_CFG_MINIMAL, MINIMAL, JVM_CFG_MINIMAL); |
|
127 |
try { |
|
128 |
checkVM("minimal", SERVER, JVM_CFG_SERVER, MINIMAL, JVM_CFG_MINIMAL); |
|
129 |
failed = true; |
|
130 |
throw new Exception("Should have failed"); |
|
131 |
} catch (Exception ex) { |
|
132 |
if (failed) { |
|
133 |
throw ex; |
|
134 |
} |
|
135 |
} |
|
136 |
try { |
|
137 |
checkVM("minimal", CLIENT, JVM_CFG_CLIENT, MINIMAL, JVM_CFG_MINIMAL); |
|
138 |
failed = true; |
|
139 |
throw new Exception("Should have failed"); |
|
140 |
} catch (Exception ex) { |
|
141 |
if (failed) { |
|
142 |
throw ex; |
|
143 |
} |
|
144 |
} |
|
145 |
||
146 |
} |
|
147 |
||
148 |
public void checkVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { |
|
149 |
||
150 |
for (String arch : ARCHITECTURES) { |
|
151 |
String[] winput = new String[input.length]; |
|
152 |
String[] woutput = new String[expectedOutput.length]; |
|
153 |
for (int i = 0; i < input.length; i++) { |
|
154 |
winput[i] = "/java.base/native" + arch + input[i]; |
|
155 |
} |
|
156 |
for (int i = 0; i < expectedOutput.length; i++) { |
|
157 |
woutput[i] = "/java.base/native" + arch + expectedOutput[i]; |
|
158 |
} |
|
159 |
doCheckVM(vm, winput, jvmcfg, woutput, expectdJvmCfg); |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
private void doCheckVM(String vm, String[] input, String jvmcfg, String[] expectedOutput, String expectdJvmCfg) throws Exception { |
|
164 |
// Create a pool with jvm.cfg and the input paths. |
|
165 |
byte[] jvmcfgContent = jvmcfg.getBytes(); |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
166 |
ResourcePoolManager poolMgr = new ResourcePoolManager(); |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
167 |
poolMgr.add( |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
168 |
ResourcePoolEntry.create("/java.base/native/jvm.cfg", |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
169 |
ResourcePoolEntry.Type.NATIVE_LIB, jvmcfgContent)); |
36511 | 170 |
for (String in : input) { |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
171 |
poolMgr.add(ResourcePoolEntry.create(in, |
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
172 |
ResourcePoolEntry.Type.NATIVE_LIB, new byte[0])); |
36511 | 173 |
} |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
174 |
ResourcePoolManager outMgr = new ResourcePoolManager(); |
36511 | 175 |
|
39321
c60f34e8c057
8160641: PostProcessingPlugin and ExecutableImage should not be part of plugin API
sundar
parents:
39151
diff
changeset
|
176 |
Plugin p = new ExcludeVMPlugin(); |
36511 | 177 |
Map<String, String> config = new HashMap<>(); |
178 |
if (vm != null) { |
|
179 |
config.put(ExcludeVMPlugin.NAME, vm); |
|
180 |
} |
|
181 |
p.configure(config); |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
182 |
ResourcePool out = p.transform(poolMgr.resourcePool(), outMgr.resourcePoolBuilder()); |
36511 | 183 |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
184 |
String newContent = new String(out.findEntry("/java.base/native/jvm.cfg").get().contentBytes()); |
36511 | 185 |
|
186 |
if (!expectdJvmCfg.equals(newContent)) { |
|
187 |
throw new Exception("Got content " + newContent + " expected " + expectdJvmCfg); |
|
188 |
} |
|
189 |
||
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
190 |
if (out.entryCount() != (expectedOutput.length + 1)) { |
38320 | 191 |
out.entries().forEach(m -> { |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
192 |
System.err.println(m.path()); |
38320 | 193 |
}); |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
194 |
throw new Exception("Invalid output size " + out.entryCount() + " expected " + (expectedOutput.length + 1)); |
36511 | 195 |
} |
196 |
||
38320 | 197 |
out.entries().forEach(md -> { |
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
198 |
if (md.path().equals("/java.base/native/jvm.cfg")) { |
38320 | 199 |
return; |
36511 | 200 |
} |
201 |
boolean contained = false; |
|
202 |
for (String o : expectedOutput) { |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
203 |
if (md.path().equals(o)) { |
36511 | 204 |
contained = true; |
205 |
break; |
|
206 |
} |
|
207 |
} |
|
208 |
if (!contained) { |
|
39834
53a6fb443c20
8162538: plugin API should avoid read only pool, have module view separated from resource view and have pool builder to modify
sundar
parents:
39321
diff
changeset
|
209 |
throw new RuntimeException(md.path() + " not expected"); |
36511 | 210 |
} |
38320 | 211 |
}); |
36511 | 212 |
|
213 |
} |
|
214 |
||
215 |
private static boolean isWindows() { |
|
216 |
return System.getProperty("os.name").startsWith("Windows"); |
|
217 |
} |
|
218 |
||
219 |
private static boolean isMac() { |
|
220 |
return System.getProperty("os.name").startsWith("Mac OS"); |
|
221 |
} |
|
222 |
||
223 |
private static String jvmlib() { |
|
224 |
String lib = "libjvm.so"; |
|
225 |
if (isWindows()) { |
|
226 |
lib = "jvm.dll"; |
|
227 |
} else if (isMac()) { |
|
228 |
lib = "libjvm.dylib"; |
|
229 |
} |
|
230 |
return lib; |
|
231 |
} |
|
232 |
} |