Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JDK-8310380: Handle problems in core-related tests on macOS when codesign tool does not work #14562

Closed
wants to merge 4 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Jun 20, 2023

Currently, a number of tests fail on macOS because they miss the core file (e.g. serviceability/sa/TestJmapCore.java).
The reason is that configure detects on some setups that codesign does not work ("checking if debug mode codesign is possible... no) .
So adding the needed entitlement to generate cores is not done in the build. This is currently not checked later in the tests.
But without the entitlement, a core is not generated.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8310380: Handle problems in core-related tests on macOS when codesign tool does not work (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14562/head:pull/14562
$ git checkout pull/14562

Update a local copy of the PR:
$ git checkout pull/14562
$ git pull https://git.openjdk.org/jdk.git pull/14562/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14562

View PR using the GUI difftool:
$ git pr show -t 14562

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14562.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 20, 2023

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 20, 2023
@openjdk
Copy link

openjdk bot commented Jun 20, 2023

@MBaesken The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot-runtime
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jun 20, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 20, 2023

Webrevs

Copy link
Contributor

@RealLucy RealLucy left a comment

Choose a reason for hiding this comment

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

LGTM.
Thanks for enhancing test analysis.

@openjdk
Copy link

openjdk bot commented Jun 21, 2023

@MBaesken This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8310380: Handle problems in core-related tests on macOS when codesign tool does not work

Reviewed-by: lucy, clanger, cjplummer

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 100 new commits pushed to the master branch:

  • 315242b: 8310975: java.util.FormatItemModifier should not be protected
  • d6dd0dc: 8308452: Extend internal Architecture enum with byte order and address size
  • fb283df: 8310828: java.sql java.sql.rowset packages have no @since info
  • ec45bd6: 8310182: DateTimeFormatter date formats (ISO_LOCAL_DATE) separated with hyphen, not dash
  • 2bd4136: 8310849: Pattern matching for instanceof and arrayType cleanup in j.l.invoke and j.l.reflect
  • 7ce967a: 8281455: Change JVM options with small ranges from 64 to 32 bits, for gc_globals.hpp
  • f6133ed: 8310890: Normalize identifier names
  • 58bb655: 8222329: Readable read(CharBuffer) does not specify that 0 is returned when there is no remaining space in buffer
  • 05e9c41: 8310731: Configure a javax.net.ssl.SNIMatcher for the HTTP/1.1 test servers in java/net/httpclient tests
  • 1587836: 8310425: [JVMCI] compiler/runtime/TestConstantDynamic: lookupConstant returned an object of incorrect type: null
  • ... and 90 more: https://git.openjdk.org/jdk/compare/4ca548fe74419dc9e110489e3d2d3adf695ef37f...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 21, 2023
Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

I made a few review suggestions. Does the symptom happen on both, arm64 and x64?

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could do just one case here:
else if (!Platform.hasPlistEntriesOSX()) {...

public static boolean hasPlistEntriesOSX() throws IOException {
// Find the path to the java binary.
String jdkPath = System.getProperty("java.home");
Path javaPath = Paths.get(jdkPath + "/bin/java");
Copy link
Contributor

@RealCLanger RealCLanger Jun 21, 2023

Choose a reason for hiding this comment

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

You could do it more concisely:

Path javaPath = Paths.get(System.getProperty("java.home") + "/bin/java");
if (Files.notExists(javaPath)) {
throw new FileNotFoundException("Could not find file " + javaPath.toAbsolutePath().toString());

}

// Run codesign on the java binary.
ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
Copy link
Contributor

Choose a reason for hiding this comment

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

And then here 'ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaPath.toAbsolutePath().toString());`

ProcessBuilder pb = new ProcessBuilder("codesign", "--display", "--verbose", javaFileName);
pb.redirectErrorStream(true); // redirect stderr to stdout
Process codesignProcess = pb.start();
BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do the BufferedReader stuff in a try-with-resources and then return false instead of potentially throwing an IOException?

BufferedReader is = new BufferedReader(new InputStreamReader(codesignProcess.getInputStream()));
String line;
while ((line = is.readLine()) != null) {
System.out.println("STDOUT: " + line);
Copy link
Contributor

Choose a reason for hiding this comment

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

This output is for every line seems too much. Maybe just print the lines where you find "Info.plist=not bound" or "Info.plist entries="?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found the output useful when analyzing the issue (and it is just a few lines).

Copy link
Contributor

@plummercj plummercj left a comment

Choose a reason for hiding this comment

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

Copyrights need updating.

return true;
}
}
return false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably would be good to log that no Info.plist entry was found.

@@ -127,6 +127,8 @@ public static String getCoreFileLocation(String crashOutputString, long pid) thr
}

return coreFileLocation; // success!
} else {
System.out.println("Core file not found, try to find a reason for this");
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
System.out.println("Core file not found, try to find a reason for this");
System.out.println("Core file not found. Trying to find a reason why...");

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the message.

@@ -260,6 +260,34 @@ public static boolean hasSA() {
return true;
}


public static boolean hasPlistEntriesOSX() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Almost all of this is replicated from isHardenedOSX(). I wonder if there is a way to do some sharing while still maintaining separate APIs. Combining them into one API might make it harder to understand the code. Maybe a launchCodesign() API that returns the BufferedReader would help.

Copy link
Contributor

@plummercj plummercj left a comment

Choose a reason for hiding this comment

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

Copyrights need updating.

@plummercj
Copy link
Contributor

jdk/test/lib/TestMutuallyExclusivePlatformPredicates.java is failing due to the new API in Platform.java.

@MBaesken
Copy link
Member Author

I adjusted COPYRIGHT info, adjusted TestMutuallyExclusivePlatformPredicates.java .
Also simplified the coding in Platform.java a bit.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks a bit better. But I think instead of adding a Utils.javaPath() method, you can do all this path handling in Platform.launchCodesignOnJavaBinary(). Then even more code would be shared.

@@ -260,6 +260,36 @@ public static boolean hasSA() {
return true;
}

private static codesignProcess launchCodesignOnJavaBinary(String javaFileName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That can't work... should be private static Process 😉

@MBaesken
Copy link
Member Author

Yes it must be 'private static Process' . And I moved the javaPath method into the caller ,

@MBaesken
Copy link
Member Author

MBaesken commented Jun 22, 2023

Looks a bit better. But I think instead of adding a Utils.javaPath() method, you can do all this path handling in Platform.launchCodesignOnJavaBinary(). Then even more code would be shared.

Okay, I had the idea to later use the method javaPath at some more places, but let's do this separately.

Copy link
Contributor

@RealCLanger RealCLanger left a comment

Choose a reason for hiding this comment

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

Looks good to me now.

@MBaesken
Copy link
Member Author

Hi Christoph, thanks for the review !
Chris are you okay with the latest rev. of this change?

@plummercj
Copy link
Contributor

Chris are you okay with the latest rev. of this change?

Sorry, I've been on vacation the past few days. I will have a look at it tomorrow.

return codesignProcess;
}

public static boolean hasPlistEntriesOSX() throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although I understand why you chose this API name (it mimics the form used for isHardenedOSX), I don't think it is a good choice. isHardenedOSX is short for "is this a hardened OSX system". That mapping does not work with hasPlistEntriesOSX, which is more like "does this OSX system have plist entries". I would suggest hasOSXPlistEntries.

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// codesign has to add entitlements using the plist, if this is not present we might not generate a core file
// codesign has to add entitlements using the plist. If this is not present we might not generate a core file.

@MBaesken
Copy link
Member Author

Hi Chris, I renamed the method and adjusted the comment.

@MBaesken
Copy link
Member Author

Thanks for the review !

/integrate

@openjdk
Copy link

openjdk bot commented Jun 28, 2023

Going to push as commit 39c104d.
Since your change was applied there have been 110 commits pushed to the master branch:

  • 526dba1: 8310130: C2: assert(false) failed: scalar_input is neither phi nor a matchin reduction
  • 48e61c1: 8310728: Enable Zc:inline flag in Visual Studio build
  • 56a73a6: 8309591: Socket.setOption(TCP_QUICKACK) uses wrong level
  • afdaa2a: 8309109: AArch64: [TESTBUG] compiler/intrinsics/sha/cli/TestUseSHA3IntrinsicsOptionOnSupportedCPU.java fails on Neoverse N2 and V1
  • 7f09435: 8310982: jdk/internal/util/ArchTest.java fails after JDK-8308452 failed with Method isARM()
  • f07e396: 8310914: Remove 2 malformed java/foreign ProblemList entries
  • a97f98f: 8310585: GetThreadState spec mentions undefined JVMTI_THREAD_STATE_MONITOR_WAITING
  • 2cf5c2f: 8310238: [test bug] javax/swing/JTableHeader/6889007/bug6889007.java fails
  • 269852b: 8294316: SA core file support is broken on macosx-x64 starting with macOS 12.x
  • 4bce38c: 8310830: typo in the parameter name in @throws of ClassDesc::ofDescriptor
  • ... and 100 more: https://git.openjdk.org/jdk/compare/4ca548fe74419dc9e110489e3d2d3adf695ef37f...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jun 28, 2023
@openjdk openjdk bot closed this Jun 28, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 28, 2023
@openjdk
Copy link

openjdk bot commented Jun 28, 2023

@MBaesken Pushed as commit 39c104d.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

4 participants