RFR: 8346107: Generators: testing utility for random value generation [v10]

Emanuel Peter epeter at openjdk.org
Thu Jan 9 12:08:39 UTC 2025


On Thu, 9 Jan 2025 11:38:03 GMT, Theo Weidmann <tweidmann 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.
>
> Theo Weidmann has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update ExampleTest.java

A few more comments about the tests.

test/hotspot/jtreg/testlibrary_tests/generators/tests/ExampleTest.java line 81:

> 79:                 underTest.doIt(g.next());
> 80:             }
> 81:         }

Nitpick: why the inner loop, and not just a longer outer loop?

test/hotspot/jtreg/testlibrary_tests/generators/tests/TestGenerators.java line 370:

> 368:             Asserts.assertGreaterThanOrEqual(x, lo);
> 369:             Asserts.assertLessThanOrEqual(x, hi);
> 370:         }

It might be a bit of work, but it could be nice if we had these range checks for all of the restrictable generators.

test/hotspot/jtreg/testlibrary_tests/generators/tests/TestGenerators.java line 480:

> 478:         mockSource.checkEmpty().enqueueFloat(2, 5, 4);
> 479:         var f4 = mockGS.safeRestrictFloat(mockGS.uniformFloats(0, 1),2, 5);
> 480:         Asserts.assertEQ(f4.next(), 4f);

You could test `safeRestrict...` on all generators from `G`, and also the random ones like `G.ints()`

Pick random restriction bounds, and just check that the results are in bounds

-------------

PR Review: https://git.openjdk.org/jdk/pull/22941#pullrequestreview-2539733716
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1908661169
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1908667086
PR Review Comment: https://git.openjdk.org/jdk/pull/22941#discussion_r1908670387


More information about the hotspot-compiler-dev mailing list