Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/jlink/plugins/DefaultStripDebugPluginTest.java
41152 views
1
/*
2
* Copyright (c) 2019, Red Hat, Inc.
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. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
import java.util.Map;
27
28
import jdk.tools.jlink.internal.ResourcePoolManager;
29
import jdk.tools.jlink.internal.plugins.DefaultStripDebugPlugin;
30
import jdk.tools.jlink.internal.plugins.DefaultStripDebugPlugin.NativePluginFactory;
31
import jdk.tools.jlink.plugin.Plugin;
32
import jdk.tools.jlink.plugin.ResourcePool;
33
import jdk.tools.jlink.plugin.ResourcePoolBuilder;
34
import jdk.tools.jlink.plugin.ResourcePoolEntry;
35
import jdk.tools.jlink.plugin.ResourcePoolEntry.Type;
36
37
/*
38
* @test
39
* @summary Test for combination of java debug attributes stripping and
40
* native debug symbols stripping.
41
* @modules jdk.jlink/jdk.tools.jlink.internal
42
* jdk.jlink/jdk.tools.jlink.internal.plugins
43
* jdk.jlink/jdk.tools.jlink.plugin
44
* @run main/othervm DefaultStripDebugPluginTest
45
*/
46
public class DefaultStripDebugPluginTest {
47
48
public void testWithNativeStripPresent() {
49
MockStripPlugin javaPlugin = new MockStripPlugin(false);
50
MockStripPlugin nativePlugin = new MockStripPlugin(true);
51
TestNativeStripPluginFactory nativeFactory =
52
new TestNativeStripPluginFactory(nativePlugin);
53
DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin,
54
nativeFactory);
55
ResourcePoolManager inManager = new ResourcePoolManager();
56
ResourcePool pool = plugin.transform(inManager.resourcePool(),
57
inManager.resourcePoolBuilder());
58
if (!pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent() ||
59
!pool.findEntry(MockStripPlugin.NATIVE_PATH).isPresent()) {
60
throw new AssertionError("Expected both native and java to get called");
61
}
62
}
63
64
public void testNoNativeStripPluginPresent() {
65
MockStripPlugin javaPlugin = new MockStripPlugin(false);
66
TestNativeStripPluginFactory nativeFactory =
67
new TestNativeStripPluginFactory(null);
68
DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin,
69
nativeFactory);
70
ResourcePoolManager inManager = new ResourcePoolManager();
71
ResourcePool pool = plugin.transform(inManager.resourcePool(),
72
inManager.resourcePoolBuilder());
73
if (!pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent()) {
74
throw new AssertionError("Expected java strip plugin to get called");
75
}
76
}
77
78
public static void main(String[] args) {
79
DefaultStripDebugPluginTest test = new DefaultStripDebugPluginTest();
80
test.testNoNativeStripPluginPresent();
81
test.testWithNativeStripPresent();
82
}
83
84
public static class MockStripPlugin implements Plugin {
85
86
private static final String NATIVE_PATH = "/foo/lib/test.so.debug";
87
private static final String JAVA_PATH = "/foo/TestClass.class";
88
private static final String STRIP_NATIVE_NAME = "strip-native-debug-symbols";
89
private static final String OMIT_ARG = "exclude-debuginfo-files";
90
private final boolean isNative;
91
92
MockStripPlugin(boolean isNative) {
93
this.isNative = isNative;
94
}
95
96
@Override
97
public void configure(Map<String, String> config) {
98
if (isNative) {
99
if (config.get(STRIP_NATIVE_NAME) == null ||
100
!config.get(STRIP_NATIVE_NAME).equals(OMIT_ARG)) {
101
throw new AssertionError("Test failed!, Expected native " +
102
"plugin to be properly configured.");
103
} else {
104
System.out.println("DEBUG: native plugin properly configured with: " +
105
STRIP_NATIVE_NAME + "=" + config.get(STRIP_NATIVE_NAME));
106
}
107
}
108
}
109
110
@Override
111
public ResourcePool transform(ResourcePool in,
112
ResourcePoolBuilder out) {
113
in.transformAndCopy((r) -> {return r; }, out); // identity
114
String resPath = JAVA_PATH;
115
ResourcePoolEntry.Type type = Type.CLASS_OR_RESOURCE;
116
if (isNative) {
117
resPath = NATIVE_PATH;
118
type = Type.NATIVE_LIB;
119
}
120
ResourcePoolEntry entry = createMockEntry(resPath, type);
121
out.add(entry);
122
return out.build();
123
}
124
125
private ResourcePoolEntry createMockEntry(String path,
126
ResourcePoolEntry.Type type) {
127
byte[] mockContent = new byte[] { 0, 1, 2, 3 };
128
ResourcePoolEntry entry = ResourcePoolEntry.create(path,
129
type,
130
mockContent);
131
return entry;
132
}
133
134
}
135
136
public static class TestNativeStripPluginFactory implements NativePluginFactory {
137
138
private final MockStripPlugin plugin;
139
140
TestNativeStripPluginFactory(MockStripPlugin plugin) {
141
this.plugin = plugin;
142
}
143
144
@Override
145
public Plugin create() {
146
return plugin;
147
}
148
149
}
150
}
151
152