Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Tip
titleBig Hint

Within about ten lines of command line coding you may be enable to perform live code coverage reporting.

Introduction

Emma is an open source code coverage tool. In our case, Emma enables code coverage by instrumenting the target code. The instrumentation process involves Emma looking at the class or jar files and adding its own layer between the JVM and the code normally called.

...

  1. the code has been compiled with the debug option on
  2. the source code is available,
  3. session data is available in a local file,
  4. a relevant metadata file exists.

See also: QA-helper tool configuration

Command line recipe

Prerequisite

...

$root=When you have your Sakai source code
$target=Where you want your condensed tree
$filter=The directory pattern to search for

Code Block
borderStylesolid
titleExample source code condenserborderStylesolid
#!/usr/bin/perl
use File::Copy;
use File::Find;

my $root="/home/alan/temp/coverage/src/trunk";
my $target="/home/alan/temp/coverage/src/condensed_trunk";
my $filter="src/java/";
my @parts;

print "Copying and condensing source ready for htmlzing\n";
mkdir("$target", 0755) || die "Cannot mkdir $target: $!";
find (\&wanted, $root);

sub wanted{
    @parts=split(/$filter/,$File::Find::name);
    if ((-d $_)&&($parts[1] ne "")){
        if (!(-d "$target/$parts[1]" )){
             mkdir("$target/$parts[1]", 0755) || die "Cannot mkdir $target/$parts[1]: $!";
        }
    }else{
        if ($_=~/.java$/){
             copy($File::Find::name,"$target/$parts[1]");
        }
    }
}

...

{$JAVA_HOME}/bin/java emma

Code Block
borderStylesolid
titleResulting output
borderStylesolid
emma usage: emma <command> command options,
  where <command> is one of:

   run     application runner same as 'emmarun' tool;
   instr   offline instrumentation processor;
   ctl     remote control processor;

   merge   offline data file merge processor.
   report  offline report generator;

  use '<command> -h' to see usage help for a given command

EMMA v2.1, build 5320 (stable)

...

Assuming you are running from a *NIX environment and the now standard bash environment and the target Sakai server has been shutdown. Otherwise, you will need to expand the variables and add the full paths.

Code Block
java emma instr -ix - -ip {$SAKAI_HOME}/webapps/{$EMMA_INST}/WEB-INF/classes -m overwrite
-out= {$EMMA_REPORT_HOME}/{$EMMA_INST}.em

...

Result: The code for the sakai-login-tool is now instrumented and a metadata file sakai-login-tool.em has been created in the report directory. Otherwise, you will need to expand the variables and add the full paths.

Generate report

Restart your server.
Near the beginning of the logging you will see an entry mentioning Emma is alive and listening at a given port number.

...

Code Block
java emma ctl -connect localhost:47653 -command coverage.get,{$EMMA_REP0RT_HOME}/coverage.ec \
-command coverage.reset

Note: 1 The port number is 47653 is default and may be changed
Note: 2 If you want to start with fresh information remember to delete {$EMMA_REP0RT_HOME}/coverage.ec
Note: 3 In theory you may contact other instrumented systems not residing locally

Generate the actual report:

...