/
githubmirror
/
panama-vector
Обзор
Документация
Войти
/
githubmirror
/
panama-vector
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/jdk/tools/jlink/plugins/DefaultStripDebugPluginTest.java
246 строк
12 KB
Arno Zeller
8387324: jlink --strip-debug should filter external debug symbols
30 июл 2026, 10:17
30 июл 2026, 10:17
e04f4dd
Код
Авторство
О чём код?
/* * Copyright (c) 2019, 2026, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2019, Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.util.Map; import jdk.tools.jlink.internal.Platform; import jdk.tools.jlink.internal.ResourcePoolManager; import jdk.tools.jlink.internal.plugins.DefaultStripDebugPlugin; import jdk.tools.jlink.internal.plugins.DefaultStripDebugPlugin.NativePluginFactory; import jdk.tools.jlink.plugin.Plugin; import jdk.tools.jlink.plugin.ResourcePool; import jdk.tools.jlink.plugin.ResourcePoolBuilder; import jdk.tools.jlink.plugin.ResourcePoolEntry; import jdk.tools.jlink.plugin.ResourcePoolEntry.Type; /* * @test * @summary Test for combination of java debug attributes stripping and * native debug symbols stripping. * @modules jdk.jlink/jdk.tools.jlink.internal * jdk.jlink/jdk.tools.jlink.internal.plugins * jdk.jlink/jdk.tools.jlink.plugin * @run main/othervm DefaultStripDebugPluginTest */ public class DefaultStripDebugPluginTest { public void testWithNativeStripPresent() { MockStripPlugin javaPlugin = new MockStripPlugin(false); MockStripPlugin nativePlugin = new MockStripPlugin(true); TestNativeStripPluginFactory nativeFactory = new TestNativeStripPluginFactory(nativePlugin); DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin, nativeFactory); ResourcePoolManager inManager = new ResourcePoolManager(); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DEBUGINFO_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DIZ_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); ResourcePoolManager outManager = new ResourcePoolManager(); ResourcePool pool = plugin.transform(inManager.resourcePool(), outManager.resourcePoolBuilder()); if (!pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent() || !pool.findEntry(MockStripPlugin.NATIVE_PATH).isPresent()) { throw new AssertionError("Expected both native and java to get called"); } if (pool.findEntry(MockStripPlugin.DEBUGINFO_PATH).isPresent()) { throw new AssertionError(".debuginfo file should have been excluded"); } if (pool.findEntry(MockStripPlugin.DIZ_PATH).isPresent()) { throw new AssertionError(".diz file should have been excluded"); } } public void testNoNativeStripPluginPresent() { MockStripPlugin javaPlugin = new MockStripPlugin(false); TestNativeStripPluginFactory nativeFactory = new TestNativeStripPluginFactory(null); DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin, nativeFactory); ResourcePoolManager inManager = new ResourcePoolManager(); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DEBUGINFO_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DIZ_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); ResourcePoolManager outManager = new ResourcePoolManager(); ResourcePool pool = plugin.transform(inManager.resourcePool(), outManager.resourcePoolBuilder()); if (!pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent()) { throw new AssertionError("Expected java strip plugin to get called"); } if (pool.findEntry(MockStripPlugin.DEBUGINFO_PATH).isPresent()) { throw new AssertionError(".debuginfo file should have been excluded"); } if (pool.findEntry(MockStripPlugin.DIZ_PATH).isPresent()) { throw new AssertionError(".diz file should have been excluded"); } } // Disable embedded strip Java plugin, with native plugin present. public void testOnlyNativePlugin() { MockStripPlugin javaPlugin = new MockStripPlugin(false); MockStripPlugin nativePlugin = new MockStripPlugin(true); TestNativeStripPluginFactory nativeFactory = new TestNativeStripPluginFactory(nativePlugin); DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin, nativeFactory); plugin.enableJavaStripPlugin(false); ResourcePoolManager inManager = new ResourcePoolManager(); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DEBUGINFO_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DIZ_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); ResourcePoolManager outManager = new ResourcePoolManager(); ResourcePool pool = plugin.transform(inManager.resourcePool(), outManager.resourcePoolBuilder()); if (pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent() || !pool.findEntry(MockStripPlugin.NATIVE_PATH).isPresent()) { throw new AssertionError("Expected only native to get called"); } if (pool.findEntry(MockStripPlugin.DEBUGINFO_PATH).isPresent()) { throw new AssertionError(".debuginfo file should have been excluded"); } if (pool.findEntry(MockStripPlugin.DIZ_PATH).isPresent()) { throw new AssertionError(".diz file should have been excluded"); } } // Disable embedded strip Java plugin, and without native plugin present. public void testNoOperation() { MockStripPlugin javaPlugin = new MockStripPlugin(false); TestNativeStripPluginFactory nativeFactory = new TestNativeStripPluginFactory(null); DefaultStripDebugPlugin plugin = new DefaultStripDebugPlugin(javaPlugin, nativeFactory); plugin.enableJavaStripPlugin(false); ResourcePoolManager inManager = new ResourcePoolManager(); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DEBUGINFO_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); inManager.add(ResourcePoolEntry.create(MockStripPlugin.DIZ_PATH, ResourcePoolEntry.Type.NATIVE_LIB, new byte[]{0, 1, 2, 3})); ResourcePoolManager outManager = new ResourcePoolManager(); ResourcePool pool = plugin.transform(inManager.resourcePool(), outManager.resourcePoolBuilder()); if (pool.findEntry(MockStripPlugin.JAVA_PATH).isPresent() || pool.findEntry(MockStripPlugin.NATIVE_PATH).isPresent()) { throw new AssertionError("Expected both native and java not called"); } if (pool.findEntry(MockStripPlugin.DEBUGINFO_PATH).isPresent()) { throw new AssertionError(".debuginfo file should have been excluded"); } if (pool.findEntry(MockStripPlugin.DIZ_PATH).isPresent()) { throw new AssertionError(".diz file should have been excluded"); } } public static void main(String[] args) { DefaultStripDebugPluginTest test = new DefaultStripDebugPluginTest(); test.testNoNativeStripPluginPresent(); test.testWithNativeStripPresent(); test.testOnlyNativePlugin(); test.testNoOperation(); } public static class MockStripPlugin implements Plugin { private static final String NATIVE_PATH = "/foo/lib/test.so.debug"; private static final String JAVA_PATH = "/foo/TestClass.class"; // Platform-appropriate debug file paths, matching the patterns chosen by // DefaultStripDebugPlugin.debugFilePattern() for the runtime platform. static final String DEBUGINFO_PATH = platformDebugPath(); static final String DIZ_PATH = "/foo/lib/libfoo.diz"; private static final String STRIP_NATIVE_NAME = "strip-native-debug-symbols"; private static final String OMIT_ARG = "exclude-debuginfo-files"; private final boolean isNative; private static String platformDebugPath() { String platform = Platform.runtime().toString(); if (platform.startsWith("windows")) { return "/foo/bin/libfoo.pdb"; } else if (platform.startsWith("macos")) { return "/foo/lib/libfoo.dylib.dSYM/Contents/Resources/DWARF/libfoo.dylib"; } else { return "/foo/lib/libfoo.so.debuginfo"; } } MockStripPlugin(boolean isNative) { this.isNative = isNative; } @Override public void configure(Map<String, String> config) { if (isNative) { if (config.get(STRIP_NATIVE_NAME) == null || !config.get(STRIP_NATIVE_NAME).equals(OMIT_ARG)) { throw new AssertionError("Test failed!, Expected native " + "plugin to be properly configured."); } else { System.out.println("DEBUG: native plugin properly configured with: " + STRIP_NATIVE_NAME + "=" + config.get(STRIP_NATIVE_NAME)); } } } @Override public ResourcePool transform(ResourcePool in, ResourcePoolBuilder out) { in.transformAndCopy((r) -> {return r; }, out); // identity String resPath = JAVA_PATH; ResourcePoolEntry.Type type = Type.CLASS_OR_RESOURCE; if (isNative) { resPath = NATIVE_PATH; type = Type.NATIVE_LIB; } out.add(createMockEntry(resPath, type)); return out.build(); } private ResourcePoolEntry createMockEntry(String path, ResourcePoolEntry.Type type) { byte[] mockContent = new byte[] { 0, 1, 2, 3 }; ResourcePoolEntry entry = ResourcePoolEntry.create(path, type, mockContent); return entry; } } public static class TestNativeStripPluginFactory implements NativePluginFactory { private final MockStripPlugin plugin; TestNativeStripPluginFactory(MockStripPlugin plugin) { this.plugin = plugin; } @Override public Plugin create() { return plugin; } } }