RFR: 8346107: Generators: testing utility for random value generation
Theo Weidmann
tweidmann at openjdk.org
Tue Jan 7 14:11:39 UTC 2025
On Tue, 7 Jan 2025 13:15:04 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> This PR is a refactoring and partial rewrite of https://github.com/openjdk/jdk/pull/22716 by @eme64. The goals remain the same:
>>
>>> For verification testing, it is often critical to generate "interesting" values, to provoke overflows, NaN, etc. And to generate these values in the correct distribution to trigger certain optimizations.
>>>
>>> I would like to start a collection of such generators, that can then be used in testing.
>>>
>>> The goal is to grow this collection in the future, and add new types. For example byte, char, short, or even Float16.
>>>
>>> This will be helpful for the Template framework [JDK-8344942](https://bugs.openjdk.org/browse/JDK-8344942), but also other tests.
>>>
>>> Related PR, for value verification: https://github.com/openjdk/jdk/pull/22715
>>
>> 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.
>
> test/hotspot/jtreg/compiler/lib/generators/EmptyGeneratorException.java line 29:
>
>> 27: * An EmptyGeneratorException is thrown if a generator configuration is requested that would result in an empty
>> 28: * set of values. For example, bounds such as [1, 0] cause an EmptyGeneratorException. Another example would be
>> 29: * restricting a uniform integer generator over the range [0, 1] to [10, 11].
>
> What if I mix distributions, and one of them has no values from that range, but the other does?
Currently the mixed generator does not even support restricting, but I think that's something that I should still add, also with regard to your comment above.
> What if I mix distributions, and one of them has no values from that range, but the other does?
I would make the mixed generator call `restricted` on both its generators, which might in turn throw EmptyGeneratorException, if they cannot be restricted to that range.
> test/hotspot/jtreg/compiler/lib/generators/Generators.java line 257:
>
>> 255: }
>> 256:
>> 257: public Generator<Integer> mixedWithSpecialInts(int weightA, int weightB, int rangeSpecial) {
>
> Suggestion:
>
> public Generator<Integer> uniformMixedWithSpecialInts(int weightA, int weightB, int rangeSpecial) {
>
> Optional, you can also leave it as is.
Oh, yeah, agreed. I wanted to change this and then forgot.
> test/hotspot/jtreg/testlibrary_tests/generators/tests/TestGenerators.java line 78:
>
>> 76: Asserts.assertEQ(g.next(), 4);
>> 77: Asserts.assertEQ(g.next(), 18);
>> 78: }
>
> It would be nice if you told us / a future person who extends this, what this mocking does, and how it works.
Do you mean specifically how this test here works or how the mocking works? Or both?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1905505679
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1905507125
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1905507808
More information about the hotspot-compiler-dev
mailing list