-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
8346107: Generators: testing utility for random value generation #22941
base: master
Are you sure you want to change the base?
8346107: Generators: testing utility for random value generation #22941
Conversation
👋 Welcome back tweidmann! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
@theoweidmannoracle The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
/contributor @eme64 |
@theoweidmannoracle Syntax:
User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address. |
/contributor add @eme64 |
@theoweidmannoracle |
Webrevs
|
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.
Nice work! I have a few comments in the code.
I am also wondering if we can still do this:
- pick a random int distribution -> suppose we get mixed special + uniform
- now sample from different int ranges, all from that same underlying distribution:
- [0, max]
- [10, 20]
- ...
I think it is not possible:
gen = Generators.ints();
// gen is not resrictable, sadly... but I would like to do
gen1 = gen.restrict(0, max);
v1 = gen1.next();
gen2 = gen.restrict(10, 20);
v2 = gen2.next()
If that is indeed not possible:
How can we ensure the continuity of the distribution across different range restrictions, if we want to pick a random distribution?
Edit: let me explain why I need this.
Suppose we will work with the Template Framework, once we have it.
#{g1:int_con(0,int_max)}
#{g2:int_con(0,1000)}
#{g3:int_con}
Basically: I am sampling 3 values from different distributions. Now suppose some thing crazy only happens when all 3 values are close to powers of 2. To make that somewhat likely, I would like to first draw a random distribution (which may be the one with only powers of 2, and neighbors), and then draw all values from that distribution.
/** | ||
* Returns the next value from the stream. | ||
*/ | ||
T next(); |
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.
Should this not have a @return
?
Why don't you run something like:
/oracle-work/jdk-fork0/build/linux-x64-debug/jdk/bin/javadoc -sourcepath test/hotspot/jtreg:./test/lib compiler.lib.generators
And make sure you don't have any errors/warnings :)
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.
What would you like to see here with @return? I don't think there's any more information I can provide? Do you think the entire doc comment should be like below? In my experience that can be detrimental for some IDEs as they will only show the main text (for a lack of a better word) in some circumstances.
/**
* @returns the next value from the stream.
*/
To get away with all the warnings would mean documenting every single parameter everywhere (all lo's and hi's). Do you think that's really necessary?
* "interesting" distributions which might trigger various behaviours in | ||
* optimizations. | ||
* <p> | ||
* Normally, clients get the default Generators instance by referring to the static variable {@link #G}. |
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 would be nice to have an example test that uses it as you would expect.
static void testMixed() { | ||
mockRandomness | ||
.checkEmpty() | ||
.enqueueInteger(0, 10, 7) | ||
.enqueueInteger(0, 10, 5) | ||
.enqueueInteger(0, 31, 4) | ||
.enqueueInteger(0, 10, 1) | ||
.enqueueInteger(0, 31, 18); | ||
var g = mockGS.mixed(mockGS.uniformInts(0, 30), mockGS.single(-1), 7, 3); | ||
Asserts.assertEQ(g.next(), -1); | ||
Asserts.assertEQ(g.next(), 4); | ||
Asserts.assertEQ(g.next(), 18); | ||
} |
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 would be nice if you told us / a future person who extends this, what this mocking does, and how it works.
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.
Do you mean specifically how this test here works or how the mocking works? Or both?
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 just say what values you feed in, and why it produces the results.
That should hopefully help a future person who tries to extend the test for their own type.
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 documented MockRandomnessSource and added comments to this test case. I hope that provides enough clarifications to understand the other tests as it is always the same pattern (and this is definitely the most complicated one).
This PR is a refactoring and partial rewrite of #22716 by @eme64. The goals remain the same:
The refactoring makes use of generics, rendering the generators library more flexible by default, by allowing it work with arbitrary types (with special features for Comparable types), improving the composability of different generators and streamlining the client API for simplicity. This allows test authors to quickly compose their own distributions and generators if necessary. An overview of this functionality is provided in the
Generators
javadoc.Progress
Issue
Contributors
<[email protected]>
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22941/head:pull/22941
$ git checkout pull/22941
Update a local copy of the PR:
$ git checkout pull/22941
$ git pull https://git.openjdk.org/jdk.git pull/22941/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22941
View PR using the GUI difftool:
$ git pr show -t 22941
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22941.diff
Using Webrev
Link to Webrev Comment