Skip to content

Commit

Permalink
8310380: Handle problems in core-related tests on macOS when codesign…
Browse files Browse the repository at this point in the history
… tool does not work

Reviewed-by: lucy, clanger, cjplummer
  • Loading branch information
MBaesken committed Jun 28, 2023
1 parent 526dba1 commit 39c104d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -53,7 +53,7 @@ private static enum MethodGroup {
IGNORED("isEmulatedClient", "isDebugBuild", "isFastDebugBuild", "isMusl",
"isSlowDebugBuild", "hasSA", "isRoot", "isTieredSupported",
"areCustomLoadersSupportedForCDS", "isDefaultCDSArchiveSupported",
"isHardenedOSX");
"isHardenedOSX", "hasOSXPlistEntries");

public final List<String> methodNames;

Expand Down
46 changes: 32 additions & 14 deletions test/lib/jdk/test/lib/Platform.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -260,28 +260,46 @@ public static boolean hasSA() {
return true;
}

/**
* Return true if the test JDK is hardened, otherwise false. Only valid on OSX.
*/
public static boolean isHardenedOSX() throws IOException {
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
// for simplicity we'll also include earlier 10.14 versions).
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
return false; // assume not hardened
}

// Find the path to the java binary.
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);
}

// 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();
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.
*/
public static boolean isHardenedOSX() throws IOException {
// We only care about hardened binaries for 10.14 and later (actually 10.14.5, but
// for simplicity we'll also include earlier 10.14 versions).
if (getOsVersionMajor() == 10 && getOsVersionMinor() < 14) {
return false; // assume not hardened
}
Process codesignProcess = launchCodesignOnJavaBinary();
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
String line;
boolean isHardened = false;
Expand Down
9 changes: 8 additions & 1 deletion test/lib/jdk/test/lib/util/CoreUtils.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -127,6 +127,8 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
}

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
Expand All @@ -148,6 +150,11 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
// 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.
Expand Down

9 comments on commit 39c104d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21

@openjdk
Copy link

@openjdk openjdk bot commented on 39c104d Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-39c104df in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 39c104df from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 28 Jun 2023 and was reviewed by Lutz Schmidt, Christoph Langer and Chris Plummer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch https://github.com/openjdk-bots/jdk21.git MBaesken-backport-39c104df:MBaesken-backport-39c104df
$ git checkout MBaesken-backport-39c104df
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21.git MBaesken-backport-39c104df

@GoeLin
Copy link
Member

@GoeLin GoeLin commented on 39c104d Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 39c104d Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GoeLin the backport was successfully created on the branch backport-GoeLin-39c104df in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 39c104df from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 28 Jun 2023 and was reviewed by Lutz Schmidt, Christoph Langer and Chris Plummer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-39c104df:backport-GoeLin-39c104df
$ git checkout backport-GoeLin-39c104df
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-GoeLin-39c104df

@luchenlin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 39c104d Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin Could not automatically backport 39c104df to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java
  • test/lib/jdk/test/lib/Platform.java
  • test/lib/jdk/test/lib/util/CoreUtils.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-39c104df

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 39c104df44f17c1d65e35becd4272f73e2c6610c

# Backport the commit
$ git cherry-pick --no-commit 39c104df44f17c1d65e35becd4272f73e2c6610c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 39c104df44f17c1d65e35becd4272f73e2c6610c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 39c104df44f17c1d65e35becd4272f73e2c6610c.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 39c104df from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 28 Jun 2023 and was reviewed by Lutz Schmidt, Christoph Langer and Chris Plummer.

Thanks!

@luchenlin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 39c104d Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luchenlin Could not automatically backport 39c104df to openjdk/jdk11u-dev due to conflicts in the following files:

  • test/hotspot/jtreg/testlibrary_tests/TestMutuallyExclusivePlatformPredicates.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev.git master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b backport-luchenlin-39c104df

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk.git 39c104df44f17c1d65e35becd4272f73e2c6610c

# Backport the commit
$ git cherry-pick --no-commit 39c104df44f17c1d65e35becd4272f73e2c6610c
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 39c104df44f17c1d65e35becd4272f73e2c6610c'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 39c104df44f17c1d65e35becd4272f73e2c6610c.

Below you can find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 39c104df from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 28 Jun 2023 and was reviewed by Lutz Schmidt, Christoph Langer and Chris Plummer.

Thanks!

Please sign in to comment.