JVMDI Code Coverage Analyser for Java

The Sourceforge Project Page

The CVS Repository

Download from the project page

This small utility is a shared library which when loaded into a Java VM (1.4+) which supports JVMDI will record all the lines of code executed. This is a relatively coarse coverage method, but good enough for a lot of purposes.

It is intended to be used during the test cycle to identify methods which have not been adequately tested.

There is a mailing list for interested developers at jvmdicover-devs@lists.sourceforge.net

NOTE: All versions prior to 0.5 have a nasty typo which results in corrupt results if the parameter INIT_BITSET_SIZE is not 0

Compilation is simple

Note: You need Berkerly 'DB' 3 or 4 available.

[jcrisp@dhcppc1 profile]$ sh profile.c     
[jcrisp@dhcppc1 profile]$ sh report.c
report.c: In function `main':
report.c:49: warning: implicit declaration of function `exit'
[jcrisp@dhcppc1 profile]$ export LD_LIBRARY_PATH=.:./hashtable
[jcrisp@dhcppc1 profile]$ java -Xdebug -Xrunprofile:help -cp . test.Test
Java JVMDI Coverage analyser
Options (Specify after -Xrunprofile with a colon (:) and separate with comma (,) 
  incremental - add to the existing data in the profile
                (this allows multiple small test cases)
  file:<name> - define the name of the data file to store the profile
  name:<name> - define the name of the profile stored in the file
  detail      - store additional line information in the profile for detailed reports
  faster      - enable experimental in-memory hashtable support
Example : -Xdebug -Xrunprofile:incremental,file:profile.dat,name:myapp
[jcrisp@dhcppc1 profile]$ java -Xdebug -Xrunprofile:detail -cp . test.Test
DEBUG magic word enabled
Coverage profile initialised.
[jcrisp@dhcppc1 profile]$ ./report
<Profile name='Profile' runCount='1' mainClass='Ltest/Test;'>
  <Method name='Ltest/Test;bar()V' lines='2' span='2' coverage='1.00' passed='yes'>
    <Line number='13'/>
    <Line number='14'/>
  <Method name='Ltest/Test;main([Ljava/lang/String;)V' lines='9' span='9' coverage='1.00' passed='yes'>
    <Line number='18'/>
    <Line number='20'/>
    <Line number='21'/>
    <Line number='22'/>
    <Line number='23'/>
    <Line number='25'/>
    <Line number='23'/>
    <Line number='27'/>
    <Line number='28'/>
  <Method name='Ltest/Test;<init>()V' lines='1' span='1' coverage='1.00' passed='yes'>
    <Line number='3'/>
  <Method name='Ltest/Test;foo()V' lines='2' span='2' coverage='1.00' passed='yes'>
    <Line number='8'/>
    <Line number='9'/>
  <Summary methods='4' passed='4'/>

Process this with XSLT and display.xsl, and you get a nicer summary

David's perl script output is a lot prettier

If you get an error message from java complaining that it can't find the library, check that the library path is set correctly in the LD_LIBRARY_PATH environmental variable, and that all of the required libraries (libprofile.so, libhashtable.so and libdb-4.so) are available. 'ldd libprofile.so' should confirm this

Thanks to SourceForge Logo