RFR: 8344942: Template-Based Testing Framework [v55]
Roberto Castañeda Lozano
rcastanedalo at openjdk.org
Thu May 22 09:21:08 UTC 2025
On Wed, 21 May 2025 15:24:18 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> **Goal**
>> We want to generate Java source code:
>> - Make it easy to generate variants of tests. E.g. for each offset, for each operator, for each type, etc.
>> - Enable the generation of domain specific fuzzers (e.g. random expressions and statements).
>>
>> Note: with the Template Library draft I was already able to find a [list of bugs](https://bugs.openjdk.org/issues/?jql=labels%20%3D%20template-framework%20ORDER%20BY%20created%20DESC%2C%20summary%20DESC).
>>
>> **How to get started**
>> When reviewing, please start by looking at:
>> https://github.com/openjdk/jdk/blob/d21a8aabaf3b191e851b6997c11bb30fcd0f942f/test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestSimple.java#L60-L76
>>
>> We have a Template with two arguments. They are typed (Integer and String). We then apply the arguments `template.withArgs(42, "7")`, producing a `TemplateWithArgs`. This can then be `render`ed to a String. And then that can be compiled and executed with the CompileFramework.
>>
>> Second, look at this advanced test:
>> https://github.com/openjdk/jdk/blob/77079807042fc5a3af04e0ccccad4ecd89e21cdb/test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestAdvanced.java#L102-L119
>>
>> And then for a "tutorial", look at:
>> `test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestTutorial.java`
>>
>> It shows these features:
>> - The `body` of a Template is essentially a list of `Token`s that are concatenated.
>> - Templates can be nested: a `TemplateWithArgs` is also a `Token`.
>> - We can use `#name` replacements to directly format values into the String. If we had proper String Templates in Java, we would not need this feature.
>> - We can use `$var` to make variable names unique: if we applied the same template twice, we would get variable collisions. `$var` is then replaced with e.g. `var_7` in one template use and `var_42` in the other template use.
>> - The use of `Hook`s to insert code into outer (earlier) code locations. This is useful, for example, to insert fields on demand.
>> - The use of recursive templates, and `fuel` to limit the recursion.
>> - `Name`s: useful to register field and variable names in code scopes.
>>
>> Next, look at the documentation in. This file is the heart of the Template Framework, and describes all the important features.
>> https://github.com/openjdk/jdk/blob/d21a8aabaf3b191e851b6997c11bb30fcd0f942f/test/hotspot/jtreg/compiler/lib/template_framework/Template.java#L31-L76
>>
>> For a better experience, you may want...
>
> Emanuel Peter has updated the pull request incrementally with one additional commit since the last revision:
>
> move order in tutorial
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 209:
> 207: * <p>
> 208: * Similarly, we may want to model method and class names, and possibly other structural names. We model
> 209: * these names with {@link StructuralName}, which works analogous to {@link DataName}, except that they
Suggestion:
* these names with {@link StructuralName}, which works analogously to {@link DataName}, except that they
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 215:
> 213: * When working with {@link DataName}s and {@link StructuralName}s, it is important to be aware of the
> 214: * relevant scopes, as well as the execution order of the {@link Template} lambdas, as well as the evaluation
> 215: * of the {@link Template#body} tokens. When a {@link Template} is rendered, its lambda is invoke. In the
Suggestion:
* of the {@link Template#body} tokens. When a {@link Template} is rendered, its lambda is invoked. In the
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 261:
> 259: * // nested Template would observe an increment in the count.
> 260: * anotherTemplate.asToken(),
> 261: * // By this point, all methods are called, and the tokens generated. The
Suggestion:
* // By this point, all methods are called, and the tokens generated.
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 608:
> 606: *
> 607: * @param tokens A list of tokens, which can be {@link String}s, boxed primitive types
> 608: * (e.g. {@link Integer}), any {@link Token}, or {@link List}s
For correct javadoc rendering:
Suggestion:
* (for example {@link Integer}), any {@link Token}, or {@link List}s
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 752:
> 750:
> 751: /**
> 752: * Add a {@link DataName} in the current scope, i.e. the innermost of either
For correct javadoc rendering:
Suggestion:
* Add a {@link DataName} in the current scope, that is the innermost of either
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 774:
> 772:
> 773: /**
> 774: * Add a {@link DataName} in the current scope, i.e. the innermost of either
For correct javadoc rendering:
Suggestion:
* Add a {@link DataName} in the current scope, that is the innermost of either
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 799:
> 797:
> 798: /**
> 799: * Add a {@link StructuralName} in the current scope, i.e. the innermost of either
For correct javadoc rendering:
Suggestion:
* Add a {@link StructuralName} in the current scope, that is the innermost of either
test/hotspot/jtreg/compiler/lib/template_framework/Template.java line 813:
> 811:
> 812: /**
> 813: * Add a {@link StructuralName} in the current scope, i.e. the innermost of either
For correct javadoc rendering:
Suggestion:
* Add a {@link StructuralName} in the current scope, that is the innermost of either
test/hotspot/jtreg/compiler/lib/template_framework/TemplateBinding.java line 27:
> 25:
> 26: /**
> 27: * To facilitate recursive uses of Templates, e.g. where a template uses
To prevent `javadoc` from truncating the sentence in the Description column in the package summary view (`package-summary.html`), see https://stackoverflow.com/questions/18282086/how-tell-tell-javadoc-that-my-period-doesnt-end-a-sentence.
Suggestion:
* To facilitate recursive uses of Templates, for example where a template uses
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101857252
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101858376
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101862125
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101870441
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101865914
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101866887
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101867993
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101868739
PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2101839097
More information about the hotspot-compiler-dev
mailing list