Skip to content

Commit 39c104d

Browse files
committed
8310380: Handle problems in core-related tests on macOS when codesign tool does not work
Reviewed-by: lucy, clanger, cjplummer
1 parent 526dba1 commit 39c104d

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
@@ -127,6 +127,8 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
127127
}
128128

129129
return coreFileLocation; // success!
130+
} else {
131+
System.out.println("Core file not found. Trying to find a reason why...");
130132
}
131133

132134
// See if we can figure out the likely reason the core file was not found. Recover from
@@ -148,6 +150,11 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
148150
// We can't generate cores files with hardened binaries on OSX 10.15 and later.
149151
throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later");
150152
}
153+
} else {
154+
// codesign has to add entitlements using the plist. If this is not present we might not generate a core file.
155+
if (!Platform.hasOSXPlistEntries()) {
156+
throw new SkippedException("Cannot produce core file with binary having no plist entitlement entries");
157+
}
151158
}
152159
} else if (Platform.isLinux()) {
153160
// Check if a crash report tool is installed.

0 commit comments

Comments
 (0)