Skip to content

Commit 075c56f

Browse files
committed
8310380: Handle problems in core-related tests on macOS when codesign tool does not work
Backport-of: 39c104df44f17c1d65e35becd4272f73e2c6610c
1 parent b993b74 commit 075c56f

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/lib-test/jdk/test/lib/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
@@ -53,7 +53,7 @@ private static enum MethodGroup {
5353
IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isMusl",
5454
"isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported",
5555
"areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported",
56-
"isHardenedOSX");
56+
"isHardenedOSX", "hasOSXPlistEntries");
5757

5858
public final List<String> methodNames;
5959

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
@@ -260,28 +260,46 @@ public static boolean hasSA() {
260260
return true;
261261
}
262262

263-
/**
264-
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
265-
*/
266-
public static boolean isHardenedOSX() throws IOException {
267-
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
268-
// for simplicity we'll also include earlier 10.14 versions).
269-
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
270-
return false; // assume not hardened
271-
}
272-
273-
// Find the path to the java binary.
263+
private static Process launchCodesignOnJavaBinary() throws IOException {
274264
String jdkPath = System.getProperty("java.home");
275265
Path javaPath = Paths.get(jdkPath + "/bin/java");
276266
String javaFileName = javaPath.toAbsolutePath().toString();
277267
if (Files.notExists(javaPath)) {
278268
throw new FileNotFoundException("Could not find file " + javaFileName);
279269
}
280-
281-
// Run codesign on the java binary.
282270
ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
283271
pb.redirectErrorStream(true); // redirect stderr to stdout
284272
Process codesignProcess = pb.start();
273+
return codesignProcess;
274+
}
275+
276+
public static boolean hasOSXPlistEntries() throws IOException {
277+
Process codesignProcess = launchCodesignOnJavaBinary();
278+
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
279+
String line;
280+
while ((line = is.readLine()) != null) {
281+
System.out.println("STDOUT: " + line);
282+
if (line.indexOf("Info.plist=not bound") != -1) {
283+
return false;
284+
}
285+
if (line.indexOf("Info.plist entries=") != -1) {
286+
return true;
287+
}
288+
}
289+
System.out.println("No matching Info.plist entry was found");
290+
return false;
291+
}
292+
293+
/**
294+
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
295+
*/
296+
public static boolean isHardenedOSX() throws IOException {
297+
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
298+
// for simplicity we'll also include earlier 10.14 versions).
299+
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
300+
return false; // assume not hardened
301+
}
302+
Process codesignProcess = launchCodesignOnJavaBinary();
285303
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
286304
String line;
287305
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
@@ -122,6 +122,8 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
122122
}
123123

124124
return coreFileLocation; // success!
125+
} else {
126+
System.out.println("Core file not found. Trying to find a reason why...");
125127
}
126128

127129
// See if we can figure out the likely reason the core file was not found. Recover from
@@ -143,6 +145,11 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
143145
// We can't generate cores files with hardened binaries on OSX 10.15 and later.
144146
throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later");
145147
}
148+
} else {
149+
// codesign has to add entitlements using the plist. If this is not present we might not generate a core file.
150+
if (!Platform.hasOSXPlistEntries()) {
151+
throw new SkippedException("Cannot produce core file with binary having no plist entitlement entries");
152+
}
146153
}
147154
} else if (Platform.isLinux()) {
148155
// Check if a crash report tool is installed.

0 commit comments

Comments
 (0)