diff --git a/test/hotspot/jtreg/runtime/signal/SigTestDriver.java b/test/hotspot/jtreg/runtime/signal/SigTestDriver.java index 6fcc41c8ab2..f2b37af1c39 100644 --- a/test/hotspot/jtreg/runtime/signal/SigTestDriver.java +++ b/test/hotspot/jtreg/runtime/signal/SigTestDriver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -144,7 +144,6 @@ public class SigTestDriver { } private static Path libjsig() { - return Platform.jvmLibDir().resolve((Platform.isWindows() ? "" : "lib") - + "jsig." + Platform.sharedLibraryExt()); + return Platform.jvmLibDir().resolve(Platform.buildSharedLibraryName("jsig")); } } diff --git a/test/hotspot/jtreg/serviceability/dcmd/jvmti/AttachFailed/AttachFailedTestBase.java b/test/hotspot/jtreg/serviceability/dcmd/jvmti/AttachFailed/AttachFailedTestBase.java index d6b1159a4b0..6926ec0fbf7 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/jvmti/AttachFailed/AttachFailedTestBase.java +++ b/test/hotspot/jtreg/serviceability/dcmd/jvmti/AttachFailed/AttachFailedTestBase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,14 +39,7 @@ public abstract class AttachFailedTestBase { * Build path to shared object according to platform rules */ public static String getSharedObjectPath(String name) { - String libname; - if (Platform.isWindows()) { - libname = name + ".dll"; - } else if (Platform.isOSX()) { - libname = "lib" + name + ".dylib"; - } else { - libname = "lib" + name + ".so"; - } + String libname = Platform.buildSharedLibraryName(name); return Paths.get(Utils.TEST_NATIVE_PATH, libname) .toAbsolutePath() diff --git a/test/hotspot/jtreg/serviceability/dcmd/jvmti/LoadAgentDcmdTest.java b/test/hotspot/jtreg/serviceability/dcmd/jvmti/LoadAgentDcmdTest.java index c24b23d09a1..725bf086b3b 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/jvmti/LoadAgentDcmdTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/jvmti/LoadAgentDcmdTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -63,7 +63,7 @@ public class LoadAgentDcmdTest { "'-Dtest.jdk=/path/to/jdk'."); } - Path libpath = Paths.get(jdkPath, jdkLibPath(), sharedObjectName("instrument")); + Path libpath = Paths.get(jdkPath, jdkLibPath(), Platform.buildSharedLibraryName("instrument")); if (!libpath.toFile().exists()) { throw new FileNotFoundException( @@ -157,19 +157,6 @@ public class LoadAgentDcmdTest { return "lib"; } - /** - * Build name of shared object according to platform rules - */ - public static String sharedObjectName(String name) { - if (Platform.isWindows()) { - return name + ".dll"; - } - if (Platform.isOSX()) { - return "lib" + name + ".dylib"; - } - return "lib" + name + ".so"; - } - @Test public void jmx() throws Throwable { run(new JMXExecutor()); diff --git a/test/hotspot/jtreg/serviceability/dcmd/vm/DynLibsTest.java b/test/hotspot/jtreg/serviceability/dcmd/vm/DynLibsTest.java index 1593bc164bc..696101a329e 100644 --- a/test/hotspot/jtreg/serviceability/dcmd/vm/DynLibsTest.java +++ b/test/hotspot/jtreg/serviceability/dcmd/vm/DynLibsTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -44,25 +44,9 @@ public class DynLibsTest { public void run(CommandExecutor executor) { OutputAnalyzer output = executor.execute("VM.dynlibs"); - - String osDependentBaseString = null; - if (Platform.isAix()) { - osDependentBaseString = "lib%s.so"; - } else if (Platform.isLinux()) { - osDependentBaseString = "lib%s.so"; - } else if (Platform.isOSX()) { - osDependentBaseString = "lib%s.dylib"; - } else if (Platform.isWindows()) { - osDependentBaseString = "%s.dll"; - } - - if (osDependentBaseString == null) { - Assert.fail("Unsupported OS"); - } - - output.shouldContain(String.format(osDependentBaseString, "jvm")); - output.shouldContain(String.format(osDependentBaseString, "java")); - output.shouldContain(String.format(osDependentBaseString, "management")); + output.shouldContain(Platform.buildSharedLibraryName("jvm")); + output.shouldContain(Platform.buildSharedLibraryName("java")); + output.shouldContain(Platform.buildSharedLibraryName("management")); } @Test diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeLibraryCopier.java b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeLibraryCopier.java index 4f846f997ef..a7a83820621 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeLibraryCopier.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jvmti/NativeLibraryCopier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -34,12 +34,12 @@ import java.nio.file.Paths; public class NativeLibraryCopier { public static void main(String[] args) { Path src = Paths.get(Utils.TEST_NATIVE_PATH) - .resolve(libname(args[0])) + .resolve(Platform.buildSharedLibraryName(args[0])) .toAbsolutePath(); Path dstDir = Paths.get("."); for (int i = 1; i < args.length; ++i) { - Path dst = dstDir.resolve(libname(args[i])).toAbsolutePath(); + Path dst = dstDir.resolve(Platform.buildSharedLibraryName(args[i])).toAbsolutePath(); System.out.println("copying " + src + " to " + dst); try { Files.copy(src, dst); @@ -48,11 +48,4 @@ public class NativeLibraryCopier { } } } - - private static String libname(String name) { - return String.format("%s%s.%s", - Platform.isWindows() ? "" : "lib", - name, - Platform.sharedLibraryExt()); - } } diff --git a/test/jdk/com/sun/tools/attach/warnings/DynamicLoadWarningTest.java b/test/jdk/com/sun/tools/attach/warnings/DynamicLoadWarningTest.java index 970bade3530..dab4d9ac0ce 100644 --- a/test/jdk/com/sun/tools/attach/warnings/DynamicLoadWarningTest.java +++ b/test/jdk/com/sun/tools/attach/warnings/DynamicLoadWarningTest.java @@ -79,9 +79,8 @@ class DynamicLoadWarningTest { @BeforeAll static void setup() throws Exception { // get absolute path to JVM TI agents - String prefix = Platform.isWindows() ? "" : "lib"; - String libname1 = prefix + JVMTI_AGENT1_LIB + "." + Platform.sharedLibraryExt(); - String libname2 = prefix + JVMTI_AGENT2_LIB + "." + Platform.sharedLibraryExt(); + String libname1 = Platform.buildSharedLibraryName(JVMTI_AGENT1_LIB); + String libname2 = Platform.buildSharedLibraryName(JVMTI_AGENT2_LIB); jvmtiAgentPath1 = Path.of(Utils.TEST_NATIVE_PATH, libname1).toAbsolutePath().toString(); jvmtiAgentPath2 = Path.of(Utils.TEST_NATIVE_PATH, libname2).toAbsolutePath().toString(); diff --git a/test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java b/test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java index 77eb0362841..571809ddab4 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestNativeLibrariesEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -70,25 +70,10 @@ public class TestNativeLibrariesEvent { } private static List getExpectedLibs() throws Throwable { - String libTemplate = null; - if (Platform.isWindows()) { - libTemplate = "%s.dll"; - } else if (Platform.isOSX()) { - libTemplate = "lib%s.dylib"; - } else if (Platform.isLinux()) { - libTemplate = "lib%s.so"; - } else if (Platform.isAix()) { - libTemplate = "lib%s.so"; - } - - if (libTemplate == null) { - throw new Exception("Unsupported OS"); - } - List libs = new ArrayList(); String[] names = { "jvm", "java", "zip" }; for (String name : names) { - libs.add(String.format(libTemplate, name)); + libs.add(Platform.buildSharedLibraryName(name)); } return libs; } diff --git a/test/jdk/jdk/jfr/event/runtime/TestNativeLibraryLoadEvent.java b/test/jdk/jdk/jfr/event/runtime/TestNativeLibraryLoadEvent.java index 89c7877b6d4..55053e92800 100644 --- a/test/jdk/jdk/jfr/event/runtime/TestNativeLibraryLoadEvent.java +++ b/test/jdk/jdk/jfr/event/runtime/TestNativeLibraryLoadEvent.java @@ -54,43 +54,17 @@ public class TestNativeLibraryLoadEvent { System.loadLibrary("instrument"); recording.stop(); - List expectedLibs = getExpectedLibs(); + String expectedLib = Platform.buildSharedLibraryName("instrument"); + boolean expectedLibFound = false; for (RecordedEvent event : Events.fromRecording(recording)) { System.out.println("Event:" + event); String lib = Events.assertField(event, "name").notEmpty().getValue(); Events.assertField(event, "success"); - for (String expectedLib : new ArrayList<>(expectedLibs)) { - if (lib.contains(expectedLib)) { - expectedLibs.remove(expectedLib); - } + if (lib.contains(expectedLib)) { + expectedLibFound = true; } } - assertTrue(expectedLibs.isEmpty(), "Missing libraries:" + expectedLibs.stream().collect(Collectors.joining(", "))); + assertTrue(expectedLibFound, "Missing library " + expectedLib); } } - - private static List getExpectedLibs() throws Throwable { - String libTemplate = null; - if (Platform.isWindows()) { - libTemplate = "%s.dll"; - } else if (Platform.isOSX()) { - libTemplate = "lib%s.dylib"; - } else if (Platform.isLinux()) { - libTemplate = "lib%s.so"; - } else if (Platform.isAix()) { - libTemplate = "lib%s.so"; - } - - if (libTemplate == null) { - throw new Exception("Unsupported OS"); - } - - List libs = new ArrayList(); - String[] names = { "instrument" }; - for (String name : names) { - libs.add(String.format(libTemplate, name)); - } - return libs; - } - } diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index c58877c6c5e..25cb8bc3d1e 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.java @@ -362,6 +362,27 @@ public class Platform { } } + /** + * Returns the usual file prefix of a shared library, e.g. "lib" on linux, empty on windows. + * @return file name prefix + */ + public static String sharedLibraryPrefix() { + if (isWindows()) { + return ""; + } else { + return "lib"; + } + } + + /** + * Returns the usual full shared lib name of a name without prefix and extension, e.g. for jsig + * "libjsig.so" on linux, "jsig.dll" on windows. + * @return the full shared lib name + */ + public static String buildSharedLibraryName(String name) { + return sharedLibraryPrefix() + name + "." + sharedLibraryExt(); + } + /* * Returns name of system variable containing paths to shared native libraries. */