[External] : Re: Centrally set a system property that gets passed to all tests in a sub-directory?

Jonathan Gibbons jonathan.gibbons at oracle.com
Mon Nov 22 16:52:00 UTC 2021


Your solution (about using ProcessBuilder) indirectly suggests that the 
ability to centrally set a system property does not really need to be in 
jtreg.

Instead of using `@run main/othervm ...` to run a test, and having jtreg 
set system properties for you, you can use `@run driver` which is 
similar to `@run main` except that it does not start an extra JVM. This 
allows a test to run any custom code and start the JVM itself with all 
the necessary desired characteristics.  Obviously, this can be done with 
a test library, if that is convenient, and that library could set up 
system properties and environment variables and any shared command-line 
options.

-- Jon


On 11/21/21 7:22 PM, Jaikiran Pai wrote:
> Thank you Jon.
>
> The original use case where I felt the need for this was in context of 
> https://bugs.openjdk.java.net/browse/JDK-8277507 where I wanted to 
> introduce this diagnostic system property for launched test cases 
> under a specific test directory. Given that the issue affected all the 
> tests in that directory (there were around 20 tests spread across 2 
> sub-directories), I didn't want to change each one of them separately.
>
> I ended up using a different way to achieve this, but that's mainly 
> because I realized later that these tests were launching a separate 
> process (using ProcessBuilder) after they were launched by jtreg. So 
> this ability to add this property centrally from a TEST.properties 
> wouldn't have helped anyway. But I think this might be a useful 
> enhancement in general. Do you think this is worth filing a JBS 
> enhancement?
>
> -Jaikiran
>
> On 21/11/21 9:08 pm, Jonathan Gibbons wrote:
>> Sorry, there is no such feature.
>>
>> -- Jon
>>
>> On 11/21/21 2:00 AM, Jaikiran Pai wrote:
>>> Is there a way in jtreg where a particular Java system property can 
>>> be passed to all tests that run in othervm mode and belong to a 
>>> particular sub-directory in the test root?
>>>
>>> Something like "othervm.test.java.opts"? What I'm trying to solve is 
>>> instead of editing each of the 10+ test classes that have a @run 
>>> testng/othervm or @run main/othervm to include -Dfoo=bar in the test 
>>> definition, I would like to have a TEST.properties for that 
>>> sub-directory which would contain this system property to be set 
>>> while launching those tests? I have been looking the documentation 
>>> https://openjdk.java.net/jtreg/tag-spec.html#config but couldn't 
>>> find anything that would help in this case.
>>>
>>>
>>> -Jaikiran
>>>


More information about the jtreg-use mailing list