-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8346106: Verify.checkEQ: testing utility for recursive value verification #22715
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
Conversation
|
👋 Welcome back epeter! A progress list of the required criteria for merging this PR into |
|
@eme64 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: 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 329 new commits pushed to the
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 |
| /** | ||
| * Verify the content of two Objects, possibly recursively. Only limited types are implemented. | ||
| */ | ||
| public static void checkEQ(Object a, Object b) { | ||
| checkEQ(a, b, ""); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is the only entry point to the Utility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this note could be added to the documentation comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could. But it is also the only public method, so it is already given that way. And who knows: we might add more public methods, and then we could forget to remove that comment. I'd rather not add it.
| @Setup | ||
| public static Object[] setup() { | ||
| // Must make sure to clone input arrays, if it is mutated in the test. | ||
| return new Object[] {INPUT_A.clone(), INPUT_B}; | ||
| } | ||
|
|
||
| @Test | ||
| @Arguments(setup = "setup") | ||
| public static Object test(int[] a, float b) { | ||
| for (int i = 0; i < a.length; i++) { | ||
| a[i] = (int)(a[i] * b); | ||
| } | ||
| // Since we have more than one value, we wrap them in an Object[]. | ||
| return new Object[] {a, b}; | ||
| } | ||
|
|
||
| @Check(test = "test") | ||
| public static void check(Object result) { | ||
| Verify.checkEQ(result, GOLD); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this is how we might generate Templates in the future: Using the @Check method with Verify.checkEQ. It allows the template to basically return whatever it wants, and it will be verified with the interpreter run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we go even further and annotate this directly at the test method? For example:
@Test
@Arguments(setup = "setup")
@VerifyResult(expected = GOLD)
public static Object test(int[] a, float b) {
for (int i = 0; i < a.length; i++) {
a[i] = (int)(a[i] * b);
}
// Since we have more than one value, we wrap them in an Object[].
return new Object[] {a, b};
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We totally could. That would be a separate RFE to the IR framework. We have already filed similar RFEs.
JDK-8310533 [IR Framework] Add possibility to automatically verify that a test method always returns the same result
Adding this verify method could be the building block for that.
Webrevs
|
vnkozlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
| /** | ||
| * Verify the content of two Objects, possibly recursively. Only limited types are implemented. | ||
| */ | ||
| public static void checkEQ(Object a, Object b) { | ||
| checkEQ(a, b, ""); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this note could be added to the documentation comment?
| System.err.println("ERROR: Verify.checkEQ failed: null mismatch"); | ||
| print(a, "a " + context); | ||
| print(b, "b " + context); | ||
| throw new VerifyException("Object array null mismatch."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this message mention "array"? From what I understand, it can compare any two objects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I used to only have it work for arrays ;)
| System.err.println("ERROR: Verify.checkEQ failed: type not supported: " + ca.getName()); | ||
| print(a, "a " + context); | ||
| print(b, "b " + context); | ||
| throw new VerifyException("Object array type not supported: " + ca.getName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pattern repeats 3 times here and also below. Maybe you want to consider to move it to a reportError(String message, String details, a, b, context) method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does repeat somewhat, but not really identically. With different types for a, sometimes with context, sometimes without. Feel free to add code suggestions, because I'm not sure what you are exactly imagining.
| @Setup | ||
| public static Object[] setup() { | ||
| // Must make sure to clone input arrays, if it is mutated in the test. | ||
| return new Object[] {INPUT_A.clone(), INPUT_B}; | ||
| } | ||
|
|
||
| @Test | ||
| @Arguments(setup = "setup") | ||
| public static Object test(int[] a, float b) { | ||
| for (int i = 0; i < a.length; i++) { | ||
| a[i] = (int)(a[i] * b); | ||
| } | ||
| // Since we have more than one value, we wrap them in an Object[]. | ||
| return new Object[] {a, b}; | ||
| } | ||
|
|
||
| @Check(test = "test") | ||
| public static void check(Object result) { | ||
| Verify.checkEQ(result, GOLD); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we go even further and annotate this directly at the test method? For example:
@Test
@Arguments(setup = "setup")
@VerifyResult(expected = GOLD)
public static Object test(int[] a, float b) {
for (int i = 0; i < a.length; i++) {
a[i] = (int)(a[i] * b);
}
// Since we have more than one value, we wrap them in an Object[].
return new Object[] {a, b};
}|
@theoweidmannoracle thanks for reviewing! I think I have responded to all your comments :) |
|
@theoweidmannoracle Is there still anything you would change, or can I get your approval? ;) |
theoweidmannoracle
left a comment
There was a problem hiding this 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!
vnkozlov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last version looks good.
|
@vnkozlov @theoweidmannoracle Thanks for the reviews! |
|
Going to push as commit 35fafbc.
Your commit was automatically rebased without conflicts. |
In testing, we often generate "golden" values, and then compare the results with it. This requires comparison loops etc in every test. I would like to create a dedicated facility for this, to simplify testing in the future. This is also preparation for JDK-8344942, the Template framework.
I have written code like this in various tests before, see:
test/hotspot/jtreg/compiler/loopopts/superword/TestAlignVectorFuzzer.java./test/hotspot/jtreg/compiler/loopopts/superword/TestMemorySegment.javatest/hotspot/jtreg/compiler/loopopts/superword/TestIndependentPacksWithCyclicDependency.java.It is now time to make a proper facility, so I can save time when writing tests in the future.
A related PR, for value generation: #22716
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22715/head:pull/22715$ git checkout pull/22715Update a local copy of the PR:
$ git checkout pull/22715$ git pull https://git.openjdk.org/jdk.git pull/22715/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22715View PR using the GUI difftool:
$ git pr show -t 22715Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22715.diff
Using Webrev
Link to Webrev Comment