8313670: Simplify shared lib name handling code in some tests
Reviewed-by: cjplummer, sspitsyn
This commit is contained in:
parent
8f28809aa8
commit
6dba2026d7
@ -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"));
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
|
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<String> 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<String> libs = new ArrayList<String>();
|
||||
String[] names = { "jvm", "java", "zip" };
|
||||
for (String name : names) {
|
||||
libs.add(String.format(libTemplate, name));
|
||||
libs.add(Platform.buildSharedLibraryName(name));
|
||||
}
|
||||
return libs;
|
||||
}
|
||||
|
@ -54,43 +54,17 @@ public class TestNativeLibraryLoadEvent {
|
||||
System.loadLibrary("instrument");
|
||||
recording.stop();
|
||||
|
||||
List<String> 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<String> 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<String> libs = new ArrayList<String>();
|
||||
String[] names = { "instrument" };
|
||||
for (String name : names) {
|
||||
libs.add(String.format(libTemplate, name));
|
||||
}
|
||||
return libs;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user