Retrieving line coverage information

Developers
sbonacin83
2010-11-23
2013-05-09
  • sbonacin83

    sbonacin83 - 2010-11-23

    I need to detect whether a specific line has been covered by a single test case. However I need to do this through code and not by looking at the HTML file. In other words, I want to write a function boolean covered(int lineno) that returns true if the line number lineno has been covered. How can I do this? It seems that the XML file does not contain this kind of information.
    Is the coverage.es file format specified anywhere?

    Thanks!

     
  • Marc R. Hoffmann

    You might get some ideas by looking at the EclEmma implementation (http://www.eclemma.org). EclEmma is a code coverage plug-in that integrates EMMA via its APIs. In case your application runs on top of the Eclipse IDE EclEmma itself offers handy APIs to retrieve line level coverage.

    *.es files are serialized Java objects. You can open them via this EMMA API call:

      import com.vladium.emma.data.DataFactory;
      import com.vladium.emma.data.IMergeable;
      File f = ...
      IMergeable data = DataFactory.load(f)[DataFactory.TYPE_COVERAGEDATA];
    

    Cheers,
    -marc

     
  • sbonacin83

    sbonacin83 - 2010-11-24

    Marc,

    Thanks for your answer.

    I need to detect the nodes where the paths of two different runs took different branches. Is that possible with EMMA? I guess EMMA creates CFGs and DFGs: are they available through API calls too?

    Are there any javadocs for EMMA? Where can I find them?

    Thanks,
    Silvano

     
  • Marc R. Hoffmann

    Hallo Silviano,

    unfortunately EMMA does not support branch coverage. The implementation is based on basic blocks (see http://emma.sourceforge.net/faq.html#q.blockcoverage) which does not require to construct call graphs at all (therefore also no API for this).

    AFAIK there is no JavaDoc published, but there is a source download and a public CVS repository.

    Cheers,
    -marc

     
  • sbonacin83

    sbonacin83 - 2010-11-25

    Hi Marc,

    Thanks for helping me out. I have another question: I am trying to run EMMA from within a program but I keep getting the "error": EMMA: no metadata collected at runtime . Here's my code:

          
          String filename = "test.es";
          String[] args = new String[] {
              "-cp", "bin",
              "-sp", "src",
              "-out", filename,
              "-ix", "+program.Triangle",
              "-raw",
              "programs.TriangleTest"
          };
          Command.create("run", "emmarun", args).run();
    

    If I run the same command from a shell it works correctly instead. Do know what could be the problem?

    Thanks,
    Silvano

     
  • Marc R. Hoffmann

    EMMA installs a so called "shutdown hook" that is triggered at JVM shutdown and flushes execution data to disk. That's why no data is written as long as your program is running. Alternatively you might try to call

      com.vladium.emma.rt.RT.dumpCoverageData()

    from your program.

    -marc

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks