Bug 7900203 - JTreg needs to log instructions for rerunning test outside jtreg

Mike Duigou mike.duigou at oracle.com
Thu Aug 29 12:20:23 PDT 2013

Hi David,

I also had to do this recently so can hopefully provide some hints. The command sequence I used in the end was:

cd jdk/test/java/util/Map
./../../../../build/linux-x86_64-normal-server-fastdebug/images/j2sdk-image/bin/javac -cp ~/jdk-tools/jtreg/lib/testng.jar Defaults.java
./../../../../build/linux-x86_64-normal-server-fastdebug/images/j2sdk-image/bin/java -cp ~/jdk-tools/jtreg/lib/testng.jar:. org.testng.TestNG -testclass Defaults

You could add a VM agent for debugging if you wished or it sounds like you want to use something like:

gdb ./../../../../build/linux-x86_64-normal-server-fastdebug/images/j2sdk-image/bin/java -cp ~/jdk-tools/jtreg/lib/testng.jar:. org.testng.TestNG -testclass Defaults

JTReg tests are just vanilla Java programs. They don't need any special JTReg harness to run. The only extra bit here is to include the TestNG jar in the class path.



On Jul 16 2013, at 16:03 , David Chase wrote:

> The JTReg maintainers suggested I ask this question here.  I would like an answer, not a pointer to a page for me to read that is alleged to contain an answer (but when I read the page, it does not contain an answer, which is why I want an answer -- fool me once, shame on you, fool me twice, shame on you).
> I am trying to run a test from the command line, in java, not under jtreg, because I want to start gdb and set breakpoints.  The test is
>   jdk/test/java/util/Random/RandomStreamTest.java
> It is a testng test.

You'll need to make sure testng is on the command line and use it's test runner as your main so that the test is correctly executed. You'll notice the test class has no static main method. There used to be a common hack in Junit days to define a static main which invoked the test through the test harness.

> I do not know what the name of the class to run the test is; that is not documented (not in jtreg).

You already know it RandomStreamTest. JTReg tests generally are in the root package so you don't need to figure out what package it's in.

> I do not know what parameters that class takes;

it takes whatever parameters are passed in the @run JTreg directives. So if you have

@run main/othervm -Djdk.map.althashing.threshold=0 Collisions -shortrun

then that's the same as

java -Djdk.map.althashing.threshold=0 Collisions -shortrun

> that is not documented  (not in jtreg).
> I do not know what other entries that class takes on the classpath; that is not documented  (not in jtreg).

Just testng.jar (which you can "borrow" from jtreg's lib dir)

> I want to run it on the command line, not from ant.

> That is not documented on the default page for testng, and certainly not in jtreg.
> It is clear that jtreg has to know all these things, else it cannot run the test properly itself, so I think jtreg is perfectly positioned to emit this information for my edification, but failing that, it can be documented.
> Ideally all this information would appear in a cuttable-pastable form for command-line execution, but apparently that would be too boring and mechanical for computers to do, and instead is to be done by the developers who actually wish to debug a failing test.
> As you can tell, I'm loving this a whole lot.

Ping me if you have more questions.

> David

More information about the lambda-dev mailing list