Merging coverage reports

Sep 12, 2015 at 1:20 AM
I've been looking for code coverage for my native C++ projects and finally came across this great project. Easy to setup and I can get some useful information already.

I'm now trying to set it up with my TeamCity testing server for continuous integration. My plan was to merge the output from each of my different unit tests into one large coverage file. After testing this though, I see that I get output separated by executable. What I'm looking for is each file coverage to be merged together so I can see if everything is covered between the different unit tests.

So say I run:
OpenCppCoverage --sources=MySources --export_type=binary:test_01.cov -- UnitTest1.exe
OpenCppCoverage --sources=MySources --export_type=binary:test_02.cov -- UnitTest2.exe
OpenCppCoverage --sources=MySources --input_coverage=test_01.cov --input_coverage=test_02.cov -- UnitTest3.exe

I'd want to see that shared file a.cpp was 90% covered overall, and not get three separate sets of coverage, one at 30%, one at 40% etc.

Is this something that's possible that I'm missing?
Coordinator
Sep 15, 2015 at 10:09 PM
Hello,

I have just created 2 projects ConsoleApplication1 and ConsoleApplication2 that shared the same file main.cpp
// main.cpp
int _tmain(int argc, _TCHAR* argv[])
{
    if (argc % 2 == 0)
        return 1;
    return 0;
}
and run the following commands:
OpenCppCoverage --sources ConsoleApplication --export_type=binary -- ConsoleApplication1.exe
OpenCppCoverage --sources ConsoleApplication --input_coverage ConsoleApplication1.cov -- ConsoleApplication2.exe OneArgument
The coverage of the file main.cpp is 100% in both projects.
You need OpenCppCoverage 0.9.3 because this is a new feature.

Let me know if that solve your problem,

OpenCppCoverage
Sep 16, 2015 at 2:03 AM
I created a similar sample application and I can see now what you mean. What I was hoping for though was more a single list of all the files, not broken down by executable. Suppose we extend so there are two main functions:

ConsoleApp1 has a main.cpp like this
#include "../../SharedLibrary/SharedHeader.h"

int _tmain(int argc, _TCHAR* argv[])
{
    if (argc % 2 == 0)
        return function2() - 2;
    return function2() - 2;
}
and ConsoleApp2 has a main.cpp
#include "../../SharedLibrary/SharedHeader.h"

int _tmain(int argc, _TCHAR* argv[])
{
    return function1() - 1;
}
with SharedHeader.h
#pragma once

int function1()
{
    return 1;
}

int function2()
{
    return 2;
}
Now with the same OpenCppCoverage commands I get one report with two sections, one for each executable. Each section then contains the main for the project, plus the shared header, with coverage mixed from both runs. This is good, but I'd like to see one section with all 3 files, rather than 2 sections each with 2 files, one which is shared between the two. Does this make sense?

In a larger scale, I have unit test A, unit test B. They test moduleA and moduleB respectively. But module A and module B each use shared library C which has a few files in it.
Now if I chain everything together, and look at the results, it is true that file C shows the aggregated coverage from Unit Test A and Unit Test B regardless of which section I look in, but to find my results I have to go into each section. I look at Unit Test A section and see module A and library C, but then I have to look at Unit Test B section to see module B. And then I see library C a second time.

I'm finding this hard to describe, but basically I'm looking for an option to see one result section with every file from every executable all mixed together and aggregated together.
Coordinator
Sep 19, 2015 at 4:31 PM
Hello,

If I understand correctly your message, you would like to have no aggregation by module that is a flat list of all files.
This is unfortunately not possible.

If you really need this kind of report, you can run this command:
OpenCppCoverage --sources MySource --input_coverage Coverage1.cov  --input_coverage Coverage2.cov --export_type=cobertura --export_type=html -- YourProgram.exe
It will create a cobertura report in XML format and a classic HTML report.
You can then create a small script that parses the XML and generates the aggregation you need on HTML format for example.

If you want to have the details of the coverage for a file, you can add a link to the generated HTML report. The format is quite simple: HtmlReportFolder/Modules/ModuleName/FileName.html. Both ModuleName and Filename are available in the XML.

Please let me know if you need more detail about this solution.

Hope that help,

OpenCppCoverage
Marked as answer by OpenCppCoverage on 11/16/2015 at 1:25 PM