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

8295239: Refactor java/util/Formatter/Basic script into a Java native test launcher #10715

Conversation

justin-curtis-lu
Copy link
Member

@justin-curtis-lu justin-curtis-lu commented Oct 14, 2022

Issue: Formatter unit tests are launched via basic.sh

Fix: Replace basic.sh with a Java test launcher

Note: Java.internal.math was included in the original configuration of Basic, but I removed it as it was not used within the Basic unit tests

Original output on success

New output on success


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-8295239: Refactor java/util/Formatter/Basic script into a Java native test launcher

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 10715

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

Using diff file

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

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@bridgekeeper
Copy link

bridgekeeper bot commented Oct 14, 2022

👋 Welcome back justin-curtis-lu! 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
Copy link

openjdk bot commented Oct 14, 2022

@justin-curtis-lu The following labels will be automatically applied to this pull request:

  • core-libs
  • i18n

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 core-libs core-libs-dev@openjdk.org i18n i18n-dev@openjdk.org labels Oct 14, 2022
@justin-curtis-lu justin-curtis-lu marked this pull request as ready for review October 17, 2022 22:04
@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 17, 2022
@mlbridge
Copy link

mlbridge bot commented Oct 17, 2022

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Hi Justin,

A few comments on a quick pass through your changes

@@ -101,6 +90,6 @@ public static void main(String[] args) {
throw new RuntimeException((fail + pass) + " tests: "
+ fail + " failure(s), first", first);
else
out.println("all " + (fail + pass) + " tests passed");
System.out.println("all " + (fail + pass) + " tests passed");
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps use System.out.printf vs println and "fail" should not be needed as all tests passed

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you Lance, will take a look at this and the rest of the comments

Copy link
Member

Choose a reason for hiding this comment

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

Careful. I suspect that "fail" is the number of tests that are expected to fail.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Iris,
It got hidden in the code snippet, but line 89 is if (fail != 0),
so I do believe fail is redundant in 93.



@Test
public void testUsPac() 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.

You could use a DataProvider

Copy link
Member

Choose a reason for hiding this comment

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

I had the same thought

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Lance and Brent, replaced it with a JUnit parametrized test (DataProvider equivalent)

.reportDiagnosticSummary();
}catch(RuntimeException err){
throw new RuntimeException(String.format("$$$ %s: Test(s) failed or TestJVM did not build correctly." +
" Check stderr output from diagnostics summary above%n", err.getMessage()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to catch the RuntimeException and then throw a new RuntimeException? I think you might want to consider reworking this

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you Lance, I dropped the catch altogether as there is already enough info in the test log output

@@ -101,6 +90,6 @@ public static void main(String[] args) {
throw new RuntimeException((fail + pass) + " tests: "
+ fail + " failure(s), first", first);
else
out.println("all " + (fail + pass) + " tests passed");
System.out.printf("all " + pass + " tests passed");
Copy link
Member

Choose a reason for hiding this comment

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

This line is missing a newline; add a \n, or use println().

Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest rewriting as System.out.printf("all %s tests passed%n", pass);

You could make a similar change to line 90 using String.format as done in the line 98 which was deleted

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 dropped the new line since when the output comes out of the sub process log

Without the newline it looks like
[ ... ]

vs

[...
]

Comment on lines 45 to 47
private static final String TZ_UP = "US/Pacific";
// Asia/Novosibirsk time zone
private static final String TZ_AN = "Asia/Novosibirsk";
Copy link
Member

Choose a reason for hiding this comment

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

IMO it's not necessary to create constants if they'll only be used as a ValueSource

Copy link
Contributor

Choose a reason for hiding this comment

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

True, but really a personal choice as it makes the ValueSource less wordy ;-)

Copy link
Member

Choose a reason for hiding this comment

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

Also, when reading through a ValueSource / DataProvider, it's nice to see the actual values (vs variable/constant names) when practical/possible.

// Asia/Novosibirsk time zone
private static final String TZ_AN = "Asia/Novosibirsk";
// Locale flag for testJVM
private static final String LOCALE_PROV = "-Djava.locale.providers=CLDR";
Copy link
Member

Choose a reason for hiding this comment

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

A name like "JAVA_OPTS" would better express how this value is used.

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

// Locale flag for testJVM
private static final String LOCALE_PROV = "-Djava.locale.providers=CLDR";
// Test class
private static final String SOURCE_CLASS = "Basic";
Copy link
Member

Choose a reason for hiding this comment

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

This is the name of a compiled class to be run, not a source file, so perhaps, "TEST_CLASS"?

Copy link
Contributor

Choose a reason for hiding this comment

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

agree

/* @test
* @summary Unit tests for formatter
* @library /test/lib
* @compile Basic.java
Copy link
Member

Choose a reason for hiding this comment

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

For the record, I've not deduced how/why the rest of the .java files in the test get compiled to .class files...

Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect because the other classes are in the test.src directory they are being compiled which can be verified by Justin looking at the jtr log for the test

Copy link
Contributor

@LanceAndersen LanceAndersen left a comment

Choose a reason for hiding this comment

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

Hi Justin,

We are getting close ;-)

Please see below

@@ -101,6 +90,6 @@ public static void main(String[] args) {
throw new RuntimeException((fail + pass) + " tests: "
+ fail + " failure(s), first", first);
else
out.println("all " + (fail + pass) + " tests passed");
System.out.printf("all " + pass + " tests passed");
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest rewriting as System.out.printf("all %s tests passed%n", pass);

You could make a similar change to line 90 using String.format as done in the line 98 which was deleted

// Locale flag for testJVM
private static final String LOCALE_PROV = "-Djava.locale.providers=CLDR";
// Test class
private static final String SOURCE_CLASS = "Basic";
Copy link
Contributor

Choose a reason for hiding this comment

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

agree

else
out.println("all " + (fail + pass) + " tests passed");
System.out.printf("All %s tests passed", pass);
Copy link
Member

Choose a reason for hiding this comment

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

%d, yes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, will change that

Copy link
Member

Choose a reason for hiding this comment

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

And one on the previous line

else
out.println("all " + (fail + pass) + " tests passed");
System.out.printf("All %s tests passed", pass);
Copy link
Member

Choose a reason for hiding this comment

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

And one on the previous line

else
out.println("all " + (fail + pass) + " tests passed");
if (fail != 0) {
throw new RuntimeException(String.format("%d tests: %d failure(s)" +
Copy link
Member

Choose a reason for hiding this comment

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

You might consider including ", first" with the rest of the message string, instead of concatenating it. That line might end up slightly long, but it may be worth it.

Also, use %s forfirst, as it's a Throwable ;)
(You could also perhaps change first -> first.toString() in the final argument to format, to clarify.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, will reassign it to one line.

"Also, use %s forfirst, as it's a Throwable",
I believe I am assigning %d to pass+fail and fail. I pass first as a Throwable to the runtime exception constructor.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, right. Carry on.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of using String.format() static method, using "...".formatted() is slightly shorter/concise.

Comment on lines 87 to 90
// Build and run Basic class with correct configuration
ProcessBuilder pb = ProcessTools.createTestJvm(JAVA_OPTS, TEST_CLASS);
pb.environment().put("TZ", timeZone);
Process process = pb.start();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: indentation

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed, thanks!

Comment on lines 101 to 102
output.shouldHaveExitValue(0)
.reportDiagnosticSummary();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: indentation

@openjdk
Copy link

openjdk bot commented Oct 20, 2022

@justin-curtis-lu 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:

8295239: Refactor java/util/Formatter/Basic script into a Java native test launcher

Reviewed-by: lancea, bchristi, naoto

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 141 new commits pushed to the master branch:

  • f5dabf9: 8295088: Update External Spec page to show tabs for hosts
  • 2181042: 8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback
  • f41711e: 8295650: JFR: jfr scrub should warn if an event type doesn't exist
  • 0c13d66: 8295530: Update Zlib Data Compression Library to Version 1.2.13
  • 15bebf9: 8295666: Linux x86 build fails after 8292591
  • 5064718: 8294460: CodeSection::alignment checks for CodeBuffer::SECT_STUBS incorrectly
  • 8b010e0: 8030616: sun/management/jmxremote/bootstrap/RmiBootstrapTest fails intermittently with cannot find a free port
  • b35922b: 8295714: GHA ::set-output is deprecated and will be removed
  • dfd2d83: 8295657: SA: Allow larger object alignments
  • a345df2: 8280131: jcmd reports "Module jdk.jfr not found." when "jdk.management.jfr" is missing
  • ... and 131 more: https://git.openjdk.org/jdk/compare/ac1941425bdb1a25aa3364eef9eb1092ee716761...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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@LanceAndersen, @bchristi-git, @naotoj) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Oct 20, 2022
if (fail != 0) {
var tests_message = "%d tests: %d failure(s)%n".formatted(fail + pass, fail);
var trace_message = "Traceback of the first error located";
String message = "%s %s".formatted(tests_message, trace_message);
Copy link
Contributor

Choose a reason for hiding this comment

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

could use "var" as the previous statements ;-)

@justin-curtis-lu
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Oct 21, 2022
@openjdk
Copy link

openjdk bot commented Oct 21, 2022

@justin-curtis-lu
Your change (at version 781b352) is now ready to be sponsored by a Committer.

@bchristi-git
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Oct 21, 2022

Going to push as commit 902162c.
Since your change was applied there have been 141 commits pushed to the master branch:

  • f5dabf9: 8295088: Update External Spec page to show tabs for hosts
  • 2181042: 8295375: debug agent class tracking should not piggy back on the cbClassPrepare() callback
  • f41711e: 8295650: JFR: jfr scrub should warn if an event type doesn't exist
  • 0c13d66: 8295530: Update Zlib Data Compression Library to Version 1.2.13
  • 15bebf9: 8295666: Linux x86 build fails after 8292591
  • 5064718: 8294460: CodeSection::alignment checks for CodeBuffer::SECT_STUBS incorrectly
  • 8b010e0: 8030616: sun/management/jmxremote/bootstrap/RmiBootstrapTest fails intermittently with cannot find a free port
  • b35922b: 8295714: GHA ::set-output is deprecated and will be removed
  • dfd2d83: 8295657: SA: Allow larger object alignments
  • a345df2: 8280131: jcmd reports "Module jdk.jfr not found." when "jdk.management.jfr" is missing
  • ... and 131 more: https://git.openjdk.org/jdk/compare/ac1941425bdb1a25aa3364eef9eb1092ee716761...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Oct 21, 2022
@openjdk openjdk bot closed this Oct 21, 2022
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Oct 21, 2022
@openjdk
Copy link

openjdk bot commented Oct 21, 2022

@bchristi-git @justin-curtis-lu Pushed as commit 902162c.

💡 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 i18n i18n-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

None yet

5 participants