Skip to content

Commit b05024a

Browse files
author
Andrew Lu
committed
8310380: Handle problems in core-related tests on macOS when codesign tool does not work
Reviewed-by: lucy Backport-of: 39c104df44f17c1d65e35becd4272f73e2c6610c
1 parent 0073602 commit b05024a

File tree

4 files changed

+44
-19
lines changed

4 files changed

+44
-19
lines changed

test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
2323

2424
/**
2525
* @test TestJmapCoreMetaspace
26-
* @summary Test verifies that jhsdb jmap could generate heap dump from core when metspace is full
26+
* @summary Test verifies that jhsdb jmap could generate heap dump from core when metaspace is full
2727
* @requires vm.hasSA
2828
* @library /test/lib
2929
* @run driver/timeout=480 TestJmapCore run metaspace

test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -52,7 +52,7 @@ private static enum MethodGroup {
5252
MODE("isInt", "isMixed", "isComp"),
5353
IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isSlowDebugBuild",
5454
"hasSA", "isRoot", "isTieredSupported", "areCustomLoadersSupportedForCDS",
55-
"isHardenedOSX");
55+
"isHardenedOSX", "hasOSXPlistEntries");
5656

5757
public final List<String> methodNames;
5858

test/lib/jdk/test/lib/Platform.java

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -255,28 +255,46 @@ public static boolean hasSA() {
255255
return true;
256256
}
257257

258-
/**
259-
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
260-
*/
261-
public static boolean isHardenedOSX() throws IOException {
262-
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
263-
// for simplicity we'll also include earlier 10.14 versions).
264-
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
265-
return false; // assume not hardened
266-
}
267-
268-
// Find the path to the java binary.
258+
private static Process launchCodesignOnJavaBinary() throws IOException {
269259
String jdkPath = System.getProperty("java.home");
270260
Path javaPath = Paths.get(jdkPath + "/bin/java");
271261
String javaFileName = javaPath.toAbsolutePath().toString();
272262
if (!javaPath.toFile().exists()) {
273263
throw new FileNotFoundException("Could not find file " + javaFileName);
274264
}
275-
276-
// Run codesign on the java binary.
277265
ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
278266
pb.redirectErrorStream(true); // redirect stderr to stdout
279267
Process codesignProcess = pb.start();
268+
return codesignProcess;
269+
}
270+
271+
public static boolean hasOSXPlistEntries() throws IOException {
272+
Process codesignProcess = launchCodesignOnJavaBinary();
273+
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
274+
String line;
275+
while ((line = is.readLine()) != null) {
276+
System.out.println("STDOUT: " + line);
277+
if (line.indexOf("Info.plist=not bound") != -1) {
278+
return false;
279+
}
280+
if (line.indexOf("Info.plist entries=") != -1) {
281+
return true;
282+
}
283+
}
284+
System.out.println("No matching Info.plist entry was found");
285+
return false;
286+
}
287+
288+
/**
289+
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
290+
*/
291+
public static boolean isHardenedOSX() throws IOException {
292+
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
293+
// for simplicity we'll also include earlier 10.14 versions).
294+
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
295+
return false; // assume not hardened
296+
}
297+
Process codesignProcess = launchCodesignOnJavaBinary();
280298
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
281299
String line;
282300
boolean isHardened = false;

test/lib/jdk/test/lib/util/CoreUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -110,6 +110,8 @@ public static String getCoreFileLocation(String crashOutputString) throws IOExce
110110
Asserts.assertGT(new File(coreFileLocation).length(), 0L, "Unexpected core size");
111111
System.out.println("Found core file: " + coreFileLocation);
112112
return coreFileLocation; // success!
113+
} else {
114+
System.out.println("Core file not found. Trying to find a reason why...");
113115
}
114116

115117
// See if we can figure out the likely reason the core file was not found.
@@ -130,6 +132,11 @@ public static String getCoreFileLocation(String crashOutputString) throws IOExce
130132
// We can't generate cores files with hardened binaries on OSX 10.15 and later.
131133
throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later");
132134
}
135+
} else {
136+
// codesign has to add entitlements using the plist. If this is not present we might not generate a core file.
137+
if (!Platform.hasOSXPlistEntries()) {
138+
throw new SkippedException("Cannot produce core file with binary having no plist entitlement entries");
139+
}
133140
}
134141
} else if (Platform.isLinux()) {
135142
// Check if a crash report tool is installed.

0 commit comments

Comments
 (0)