diff --git a/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java b/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java index 3dd060be231..b8e00e53848 100644 --- a/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.java +++ b/test/hotspot/jtreg/serviceability/sa/TestJmapCoreMetaspace.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 @@ -23,7 +23,7 @@ /** * @test TestJmapCoreMetaspace - * @summary Test verifies that jhsdb jmap could generate heap dump from core when metspace is full + * @summary Test verifies that jhsdb jmap could generate heap dump from core when metaspace is full * @requires vm.hasSA * @library /test/lib * @run driver/timeout=480 TestJmapCore run metaspace diff --git a/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java b/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java index 045be5361d7..355cd8ac200 100644 --- a/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java +++ b/test/lib-test/jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 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 @@ -53,7 +53,7 @@ public class TestMutuallyExclusivePlatformPredicates { IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isMusl", "isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported", "areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported", - "isHardenedOSX"); + "isHardenedOSX", "hasOSXPlistEntries"); public final List methodNames; diff --git a/test/lib/jdk/test/lib/Platform.java b/test/lib/jdk/test/lib/Platform.java index 647c62834aa..c58877c6c5e 100644 --- a/test/lib/jdk/test/lib/Platform.java +++ b/test/lib/jdk/test/lib/Platform.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 @@ -260,6 +260,36 @@ public class Platform { return true; } + private static Process launchCodesignOnJavaBinary() throws IOException { + String jdkPath = System.getProperty("java.home"); + Path javaPath = Paths.get(jdkPath + "/bin/java"); + String javaFileName = javaPath.toAbsolutePath().toString(); + if (Files.notExists(javaPath)) { + throw new FileNotFoundException("Could not find file " + javaFileName); + } + ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName); + pb.redirectErrorStream(true); // redirect stderr to stdout + Process codesignProcess = pb.start(); + return codesignProcess; + } + + public static boolean hasOSXPlistEntries() throws IOException { + Process codesignProcess = launchCodesignOnJavaBinary(); + BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); + String line; + while ((line = is.readLine()) != null) { + System.out.println("STDOUT: " + line); + if (line.indexOf("Info.plist=not bound") != -1) { + return false; + } + if (line.indexOf("Info.plist entries=") != -1) { + return true; + } + } + System.out.println("No matching Info.plist entry was found"); + return false; + } + /** * Return true if the test JDK is hardened, otherwise false. Only valid on OSX. */ @@ -269,19 +299,7 @@ public class Platform { if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) { return false; // assume not hardened } - - // Find the path to the java binary. - String jdkPath = System.getProperty("java.home"); - Path javaPath = Paths.get(jdkPath + "/bin/java"); - String javaFileName = javaPath.toAbsolutePath().toString(); - if (Files.notExists(javaPath)) { - throw new FileNotFoundException("Could not find file " + javaFileName); - } - - // Run codesign on the java binary. - ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName); - pb.redirectErrorStream(true); // redirect stderr to stdout - Process codesignProcess = pb.start(); + Process codesignProcess = launchCodesignOnJavaBinary(); BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream())); String line; boolean isHardened = false; diff --git a/test/lib/jdk/test/lib/util/CoreUtils.java b/test/lib/jdk/test/lib/util/CoreUtils.java index f69ef5ce08e..f7a486def2b 100644 --- a/test/lib/jdk/test/lib/util/CoreUtils.java +++ b/test/lib/jdk/test/lib/util/CoreUtils.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 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 @@ -127,6 +127,8 @@ public class CoreUtils { } return coreFileLocation; // success! + } else { + System.out.println("Core file not found. Trying to find a reason why..."); } // See if we can figure out the likely reason the core file was not found. Recover from @@ -148,6 +150,11 @@ public class CoreUtils { // We can't generate cores files with hardened binaries on OSX 10.15 and later. throw new SkippedException("Cannot produce core file with hardened binary on OSX 10.15 and later"); } + } else { + // codesign has to add entitlements using the plist. If this is not present we might not generate a core file. + if (!Platform.hasOSXPlistEntries()) { + throw new SkippedException("Cannot produce core file with binary having no plist entitlement entries"); + } } } else if (Platform.isLinux()) { // Check if a crash report tool is installed.