How to build JTReg in Eclipse (for Ubuntu 12.04 LTS)

After taking inspiration from doing a whole lot of work with Eclipse and OpenJDK projects I took off on the journey to experiment with JTReg (http://openjdk.java.net/jtreg/) and attempt to build it in an IDE of my choice i.e. Eclipse. These instructions specify how you can build the JTReg using the Eclipse IDE running under Ubuntu (using OpenJDK’s Old build and Infrabuild systems).

I have kept the structure of this blog similar to the previous one so to maintain uniformity in my approach.

Firstly what is JTReg – it is a regression test harness used by the OpenJDK test framework. The different projects and packages in the OpenJDK system can be individually or wholely tested via JTReg.

Below is a list of systems and versions under which the installations and configurations were performed to come up with these instructions:

Synaptic Package Manager 0.75.9

Eclipse Indigo 3.7.2
—Eclipse JDT (Java) 3.7.2
—Eclipse CDT (C/C++)
——6.0.0.dist (C/C++ Remote debug launcher)
——1.0.2.dist (CDT GCC Cross Compiler)
——7.0.0.dist (GDB Common)

Ubuntu 12.04 LTS
Ant 1.8.4
JavaHelp 2.0
Java Test Harness 4.4
JUnit 4-4.8
OpenJDK 8
Java/Javac 1.7

You need to have an environment with OpenJDK installed and setup (as described in the How to build OpenJDK projects in Eclipse (for Ubuntu 12.04 LTS) – just follow the parts from the start upto the section ‘Preparing projects, folders and files’, as hereafter the ‘meaty OpenJDK shabhang’ starts and we don’t need it for the current work.

If you wish to just download the JTReg binary run tests from the command line, follow the instructions on the
Adopt OpenJDK’s Install JTReg page – configurations for both the Old build and the Infrabuild systems are available there.

At this point you should be able to manually run JTReg tests from the command-line interface (terminal).

Build and run JTReg in Eclipse

Downloading and setting up dependencies

Change the current folder location to the $HOME directory folder and download the JTReg source files from http://hg.openjdk.java.net/code-tools/jtreg using the below command:
Download the JTReg source files from http://hg.openjdk.java.net/code-tools/jtreg using the below command:

 $
 $ hg clone http://hg.openjdk.java.net/code-tools/jtreg
 $ 

this will create a folder by the name jtreg in the current location with the JTReg source files in it.

Alternative but less updated location: http://download.java.net/openjdk/jtreg/). If this route is used, then run the below command in the terminal mode, to download the zip file stored at the above location:

 cd ~
 wget http://www.java.net/download/openjdk/jtreg/promoted/4.1/b04/jtreg-4.1-src-b04_14_mar_2012.zip

Create a folder say under the Home directory ~/ called ‘jtreg’, unzip the zip file into this folder.

JavaHelp
Install Javahelp – required to build jtreg

 sudo apt-get install javahelp2

JavaTest Harness
Download the Javatest Harness 4.4 from http://download.java.net/jtharness/download.html

Run the below commands to download it off the web into ~

 cd ~
 wget http://download.java.net/jtharness/4.4.1/Rel/jtharness-4_4_1-MR1-bin-b13-20_dec_2011.zip

Unzip the zip file into /opt/jtharness/4.4 by doing the below:

 cd /opt
 sudo mkdir jtharness
 sudo mkdir jtharness/4.4
 cd jtharness/4.4
 sudo unzip ~/jtharness-4_4_1-MR1-bin-b13-20_dec_2011.zip

Apache Ant
Download Apache Ant 1.8.4 from http://archive.apache.org/dist/ant/binaries/ using the below commands:

 cd ~
 wget http://archive.apache.org/dist/ant/binaries/apache-ant-1.8.4-bin.zip   

 cd /opt
 sudo unzip ~/apache-ant-1.8.4-bin.zip

JUnit
Download JUnit4 jar file from Maven Central (http://search.maven.org/#search and search for junit4) and copy it into the /opt folder by performing the following commands:

 sudo mkdir /opt/junit4
 sudo mv junit-4.nn.jar /opt/junit4

TestNG
Download TestNG jar file from Maven Central (http://search.maven.org/#search and search for testng) and copy it into the /opt folder by performing the following commands:

 sudo mkdir /opt/testng
 sudo mv testng-n.n.jar /opt/testng

Now make changes to the build.properties file to amend paths for JUnit4, TestNG JavaHelp and JavaTest Harness.

Amending the Ant build properties file

As the build.properties file is protected, you will need to invoke it using the below commands:

 cd ~/jtreg/make
 sudo gedit build.properties

Make the following changes to the build.properties file in the ~/jtreg/make/ folder

jtreg.build.resources=/opt
 jhhome = /usr/share/java
 
 # JTHarness or JavaTest (should be should be 4.3 or better)
 #javatest.home = ${jtreg.build.resources}/jtharness/4.3
 javatest.home = ${jtreg.build.resources}/jtharness/4.4
 
 # JavaHelp (should be version 2.0 or better)
 javahelp.home = ${jhhome}
 #jhall.jar = ${javahelp.home}/javahelp/lib/jhall.jar
 jhall.jar = ${javahelp.home}/jhall.jar
 #jh.jar = ${javahelp.home}/javahelp/lib/jh.jar
 jh.jar = ${javahelp.home}/jh.jar
 
 # JUnit (should be 4.5 or better)
 #junit.jar = ${jtreg.build.resources}/junit/4.5/junit-4.5.jar
 junit.jar = ${jtreg.build.resources}/junit4-n.n.n.jar
  
 # TestNG (should be 6.5 or better)
 #testng.jar = ${jtreg.build.resources}/testng/6.7/other-jars/testng-6.7-dist.jar
 testng.jar = ${jtreg.build.resources}/testng/testng-n.n.jar
 
 # Ant ((should be version 1.6.5 or better)
 #ant.home = ${jtreg.build.resources}/ant/1.7.1
 ant.home = ${jtreg.build.resources}/apache-ant-1.8.4
 ant.jar = ${ant.home}/lib/ant.jar

Ensure comments are placed against the old settings (just in case you need to revert). In order to find the correct location of the jh.jar and jhall.jar files use the ‘find’ command in terminal mode.

Setting up environment variables

Add the below two lines to the ~/.bashrc file (Infrabuild)

     export JT_HOME=$HOME/jtreg                         ............. [1]
     
     or 
     
     export JT_HOME=$HOME/jtreg/dist/jtreg              ..............[2]

[1] Applies if the jtreg binary has been downloaded directly from the JTReg website.
[2] Applies if the jtreg source has been downloaded directly from the JTReg repo and a binary is built locally.

     export PRODUCT_HOME=/home/openjdk/sources/jdk8_tl/build/linux-x64-normal-server-release/images/j2sdk-image

Note: the name of the sub-folder under $SOURCE_CODE/jdk8_tl/build/ folder can have other variants i.e. linux-x86_64-normal-server-release, so please check for this in your build environment before applying the above env settings.

Or the below two lines to the ~/.bashrc file (Old build)

     export PRODUCT_HOME=/home/openjdk/sources/jdk8_tl/build/linux-amd64_backup/j2sdk-image

Now source the .bashrc file using the below command:

source ~/.bashrc

Link folder /jtreg/src to the existing project using the Configure Build Path option.

Add the /opt/apache-ant-1.8.4/lib/ant.jar to the project via the Build Path > Configure Build Path > Libraries option.

Add External JARS…, navigate to the /opt/apache-ant-1.8.4/lib/ folder, select ant.jar and click on Okay.

Importing project via Ant Build file

Run Eclipse.
Select File > New > Other > Java Project from Existing Ant build
Once done select the folder ~/jtreg/make/ and then select the build.xml.

Selecting this file populates all the ant tasks, select the option Link to the buildfile in the file system.

Now select the build.xml file, right mouse click and select the Run As > Ant Build… option, and do the below:
1) Select Main, and add -verbose to the Arguments section
2) Select Targets, and select clean from the list of targets and set the order as clean, build (if you want clean builds each time). Do skim through the list of Ant tasks, to learn the different actions that can be performed pre- and post- builds.
3) Select ClassPath and set the ClassPath for Ant Home to Apach Ant 1.8.4 by selecting Ant Home from the list, and then clicking on the Ant Home button on the bottom right hand corner and select /opt/apache-ant-1.8.4/ from the directory tree.
4) Select JRE, and select java-7-openjdk-amd64 from the list. If it does not exist on the list, click on Installed JREs… and install one by adding a JRE from /usr/lib/jvm/java-7-openjdk-amd64.

Now run the ant script by selecting Run As > Ant build.

See sign of success below (last 30 odd lines of echos from the Ant console)

dist-jtreg:
      [zip] Building zip: /home/openjdk/jtreg/dist/jtreg.zip
      [zip] adding entry jtreg/COPYRIGHT
      [zip] adding entry jtreg/LICENSE
      [zip] adding entry jtreg/README
      [zip] adding entry jtreg/doc/jtreg/faq.html
      [zip] adding entry jtreg/doc/jtreg/tag-spec.txt
      [zip] adding entry jtreg/doc/jtreg/usage.txt
      [zip] adding entry jtreg/legal/jtharness/copyright.txt
      [zip] adding entry jtreg/legal/jtharness/license.txt
      [zip] adding entry jtreg/lib/javatest.jar
      [zip] adding entry jtreg/lib/jh.jar
      [zip] adding entry jtreg/lib/jtreg.jar
      [zip] adding entry jtreg/lib/junit.jar
      [zip] adding entry jtreg/linux/bin/jtdiff
      [zip] adding entry jtreg/linux/bin/jtreg
      [zip] adding entry jtreg/solaris/bin/jtdiff
      [zip] adding entry jtreg/solaris/bin/jtreg
      [zip] adding entry jtreg/win32/bin/jtdiff
      [zip] adding entry jtreg/win32/bin/jtreg
      [zip] Building zip: /home/openjdk/jtreg/dist/jtreg-no-junit.zip
      [zip] adding entry jtreg/COPYRIGHT
      [zip] adding entry jtreg/LICENSE
      [zip] adding entry jtreg/README
      [zip] adding entry jtreg/doc/jtreg/faq.html
      [zip] adding entry jtreg/doc/jtreg/tag-spec.txt
      [zip] adding entry jtreg/doc/jtreg/usage.txt
      [zip] adding entry jtreg/legal/jtharness/copyright.txt
      [zip] adding entry jtreg/legal/jtharness/license.txt
      [zip] adding entry jtreg/lib/javatest.jar
      [zip] adding entry jtreg/lib/jh.jar
      [zip] adding entry jtreg/lib/jtreg.jar
      [zip] adding entry jtreg/linux/bin/jtdiff
      [zip] adding entry jtreg/linux/bin/jtreg
      [zip] adding entry jtreg/solaris/bin/jtdiff
      [zip] adding entry jtreg/solaris/bin/jtreg
      [zip] adding entry jtreg/win32/bin/jtdiff
      [zip] adding entry jtreg/win32/bin/jtreg
build:
BUILD SUCCESSFUL
Total time: 37 seconds

Run Configuration

TODO – able to run OpenJDK tests on one or multiple projects / packages from within Eclipse – anyone dares to go this path?

Newly created Eclipse projects

Now you have a number of ready created Eclipse projects in your Eclipse workspace.

Go to the workspace folder where Eclipse creates the project files and settings i.e. into the /home/openjdk/workspace folder.

There is a folder (called jtreg) representing the project you are currently working in, there are atleast two to four hidden files and folders in this location containing the below:

 .project
 .classpath
 .settings

Importing project via Make file

TODO – importing the JTReg Make file and being able to do the same thing as above – anyone wishes to contribute?

Build and run JTReg from CLI (terminal)

The steps mentioned in sections Downloading and setting up dependencies, Amending the Ant build properties file and Setting up environment variables must be performed before going further.

Once the above settings are in place, build JTReg from the CLI via the following commands

 cd ~/sources/jtreg/make
 ant

This should give the same output as illustrated above under Eclipse section:


 jar-jtreg:
      [jar] Building jar: /home/saiubuntu/sources/jtreg/dist/jtreg/lib/jtreg.jar
 
 -dist-jtreg.doc:
     [copy] Copying 1 file to /home/saiubuntu/sources/jtreg/dist/jtreg/doc/jtreg
 
 -dist-jtreg.bin:
 
 -dist-jtreg.legal:
 
 dist-jtreg:
      [zip] Building zip: /home/saiubuntu/sources/jtreg/dist/jtreg.zip
      [zip] Building zip: /home/saiubuntu/sources/jtreg/dist/open-jtreg.zip
 
 build:
 
 BUILD SUCCESSFUL
 Total time: 9 seconds

Once a build is successful, a number of distribution files are created in the following folders under the jtreg folder structure:

 dist
 ├── jtreg
 │   ├── lib
 │   │   ├── javatest.jar
 │   │   ├── jh.jar
 │   │   ├── jtreg.jar
 │   │   └── junit.jar
 │   ├── linux
 │   │   └── bin
 │   │       ├── jtdiff
 │   │       └── jtreg
 │   ├── solaris
 │   │   └── bin
 │   │       ├── jtdiff
 │   │       └── jtreg
 │   └── win32
 │       └── bin
 │           ├── jtdiff
 │           └── jtreg
 ├── jtreg.zip
 └── open-jtreg.zip

The files under each of the OS names i.e. linux, solaris, windows are bash script files that execute the jtreg.jar file, for e.g.

 ./dist/jtreg/linux/bin/jtreg

or

 java -jar dist/jtreg/lib/jtreg.jar 

the above two will do the exact same thing and expects parameters, see usage screen (only a snapshot of the entire text):

 Documentation Options
                Options for additional documentation
    -h [words...] | -help [words...] | -usage [words...]
                    Command line help. Give words to see help info containing
                    those or use "-help all" to see all available help.
    -n | -relnote   Release notes
    -onlineHelp [words...]
                    Show the online help. You can also show the online help from
                    the desktop Help menu.
    -t | -tagspec   Tag specification supported by this implementation
    -version        Give information about the version of jtreg in use.
 ... [multi-page usage text]

The most simplest syntax to run jtreg is

  [absolute/relative path]/jjtreg [options] [folder]

for example

  [absolute/relative path]/jtreg -verbose:fail [absolute/relative path]/jdk/test/java/lang/invoke/

[absolute/relative path] – applies depending on where you position in the OpenJDK folder structure.

It is also possible to build jtreg via the make command but that would require additional installation of dependent components and configuration. Also have a look at Adopt OpenJDK’s Install JTReg page to see how tests are run via the CLI.

Credit and kudos

My sincere thanks to Jonathan Gibbon’s from OpenJDK’s JTReg team who has been kindly responding to my queries and has walked me through the last important steps in the process!

Thanks to the Adopt OpenJDK initiative led by Martijn Verburg and others – its a pleasure to support our community!

Big thanks to Rabea Gransberger for spending the time and meticulously going through the steps and reporting issues and suggestions.

Come and join us and take on a project (like I did) and make something out of the project and yourself!

Please provide any feedback on areas that work differently for you or does not work for you at all. If you have fixed any issue please let us know so that we can update the information here.

I will continue to refine the instructions above and also include your useful feedback as and when I receive them.

About these ads

3 thoughts on “How to build JTReg in Eclipse (for Ubuntu 12.04 LTS)

  1. The instructions are badly written, I can not follow what you are saying from one sentence to the next! For instance, the three lines just before the section “Importing project via Ant Build file”… its like you have jumped off somewhere without telling anyone.. It does not seem like you understand some people might be novices..

    • My apologies if the blog has given you a less positive experience. There’s always room for improvements, so could we work together to refine these instructions so its legible and usable for everyone in general, and give them a better experience?

      Thanks for your comment, apologies for not getting back!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s