Wednesday, February 29, 2012

Running the Penrose (or OpenJDK 8) tests

As a follow-up on my previous post, Building project Penrose (or OpenJDK 8), I wanted to run the unit tests. And, as with many other things in OpenJDK, it's different from what I was used to. While other projects typically use JUnit for unit testing, OpenJDK uses a tool called jtreg, which you'll have to install manually before you can run any tests.

Once you have jtreg installed you need to tell the build where it is (the directory specified contains linux/bin/jtreg) and add it to your path - note that the JT_HOME variable is used by the OpenJDK build:
export JT_HOME=/home/david/apps/jtreg
export PATH=$JT_HOME/linux/bin:$PATH

Now you can run the whole test suite (in your clone of http://hg.openjdk.java.net/penrose/jigsaw or whatever your clone of OpenJDK 8 is):
$ make test

The above takes a very long time (edit: in fact it doesn't properly finish at all for me, it just hangs after a number of hours).

If you're developing it's better to run a portion of the tests, for instance a single test directory:
.../jdk/test$ jtreg -testjdk:/home/david/hg/pj_230212/build/linux-i586/jdk-module-image org/openjdk/jigsaw/cli
Test results: passed: 10
Report written to /home/david/hg/pj_230212/jdk/test/JTreport/html/report.html
Results written to /home/david/hg/pj_230212/jdk/test/JTwork

or a single test class:
.../jdk/test$ jtreg -testjdk:/home/david/hg/pj_230212/build/linux-i586/jdk-module-image org/openjdk/jigsaw/cli/ModuleFileTest.java
Test results: passed: 1
Report written to /home/david/hg/pj_230212/jdk/test/JTreport/html/report.html
Results written to /home/david/hg/pj_230212/jdk/test/JTwork

Note that in the above command lines it's important to pass in the full absolute path of the JDK you're running with as some of the tests rely on that to launch certain executables (like javac).

Friday, February 24, 2012

Building project Penrose (or OpenJDK 8)

As OpenJDK Project Penrose was approved last week, I started looking at getting set up to actually be able to contribute to OpenJDK and Penrose.
As I had never built OpenJDK before I started looking for the build page. While OpenJDK build page says that there is no OpenJDK 8 build readme yet, the link behind the 'coming soon' text actually contains some useful information but it relates to old versions of Linux and I want to get this working on Fedora 16 :)

Currently the Penrose codebase is still the same as the Jigsaw code base, so the steps below also apply to building Jigsaw, and they also work for plain OpenJDK 8.
At some point there will be changes in the Penrose codebase, but I don't expect that they will change the build process much, if at all.

While Julien Ponge nicely describes how to get this working on Ubuntu, the steps are a bit different on Fedora 16, so I'm documenting here how to get started from a fresh new Fedora 16 machine.

Get a few dependencies first:
# set up gcc and the static version of libstdc++
sudo yum install gcc gcc-c++ libstdc++-static

# install build deps on alsa, freetype and cups
sudo yum install alsa-lib-devel freetype-devel cups-devel

# install some X11 headers
sudo yum libXt-devel libXext-devel libXrender-devel libXtst-devel

# get mercurial
sudo yum install mercurial

# install Java 7 and ant
sudo yum install java-1.7.0-openjdk-devel ant

Now clone the whole forest of Mercurial trees (you can also use fclone with the Forest extension instead, which will save you from doing calling the bash script manually):
$ hg clone http://hg.openjdk.java.net/penrose/jigsaw pj
$ cd pj
$ bash get_source.sh

Set the following environment variables:
export LANG=C
export ALT_BOOTDIR=/usr/lib/jvm/java-1.7.0-openjdk
export ALLOW_DOWNLOADS=true

At this point 'make sanity', which does a rough check on the setup, should succeed:
$ make sanity
...
Sanity check passed.

Ok, we're ready to build:
$ make
... go for a coffee, walk the dog, book a holiday
... after quite a while you'll see that it's finished
-- Build times ----------
Target all_product_build
Start 2012-02-24 08:15:23
End   2012-02-24 08:52:47
00:00:58 corba
00:17:31 hotspot
00:00:19 jaxp
00:00:23 jaxws
00:17:44 jdk
00:00:29 langtools
00:37:24 TOTAL
-------------------------

There you go, you built Penrose and the result is a JDK 8 installation based on the Penrose codebase:
$ cd build/linux-i586/jdk-module-image/bin
$ ./java -version
openjdk version "1.8.0-internal"
OpenJDK Runtime Environment (build 1.8.0-internal-david_2012_02_24_08_15-b00)
OpenJDK Client VM (build 23.0-b11, mixed mode)

Looking forward to start hacking around in the code :)

Thanks to Andrew Haley and Alan Bateman for helping me with some issues I came across along the way.