This project is read-only.

Consolidated Code coverage report using the OpenCppCoverage

May 21, 2015 at 1:10 PM
Hello, I have been using the openCppCoverage for code coverage for google tests.
I must say its an awesome tool for code coverage. The reports are detailed and important thing is that to compute the coverage the source code is not modified.

However the reports are generated separately for every test case.
I am interested in having a consolidated report generated using all the generated coverage xmls.
Is there any option to achieve this using the OpenCppCodeCoverage ??

I would be glad if some one help to achieve this ?

Thanks in advance.
May 24, 2015 at 10:32 PM

First, thank you for your feedback!

For now, the results are grouped by module (dll or executable) and then by file.

If you have several test projects (several executables to run), you can use -input_coverage to have a single report.
See Merging coverage: --input_coverage / --export_type:binary here

If you want to have single result file instead of the html report, you can use --export_type=cobertura. This will create a xml file compatible with Cobertura plugin.
You can easily parse the xml file and create the aggregation you wish.

Let me known, if it solves your problem,

May 25, 2015 at 1:54 PM
Edited May 25, 2015 at 2:21 PM
Hello Thanks a lot for the help !
It was very useful tip. :)

Actually I executed 3 of my google tests using the options you have suggested in your reply.
I am able to generate the consolidated report in html format for all the 3 test cases.

However in order to generated consolidated report in cobertura format

I did try something like this :
OpenCppCoverage.exe --sources E:\Work_\ --export_type=binary:TestA.cov -- E:\Work_\TestA.exe
OpenCppCoverage.exe --sources E:\Work_\ --export_type=binary:TestB.cov -- E:\Work_\TestB.exe
OpenCppCoverage.exe --sources E:\Work_\ --input_coverage=TestA.cov --input_coverage=TestB.cov -- export_type=cobertura -- E:\Work_\TestC.exe

Hoping that the final report would get generated in the cobertura format , I configure the the above instructions in the Jenkins.
But unfortunately the report displayed by the Jenkins was about the coverage report for the TestC.exe only.
The entries for TestA.exe and TestB was missing.

So, Is there any way so that I can create a consolidated report in cobertura format... ?
so that I can view my coverage report for all the test cases in a single global report.

Once again Thanks
May 26, 2015 at 11:06 PM

I have just created 3 consoles application, TestA, TestB, TestC in C:\Dev\TestA folder and run the following commands:

OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestA.cov -- TestA.exe
OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestB.cov -- TestB.exe
OpenCppCoverage.exe --source=C:\Dev --input_coverage=TestA.cov --input_coverage=TestB.cov --export_type=cobertura -- TestC.exe

In my resulting xml file, TestCCoverage.xml, I can find the following 3 lines (one for each project):
<class name="testa.cpp" filename="dev\testa\testa\testa.cpp"> <-- main for TestA
<class name="testb.cpp" filename="dev\testa\testb\testb.cpp"> <-- main for TestB
<class name="testc.cpp" filename="dev\testa\testc\testc.cpp"> <-- main for TestC

At least for the basic case, it seems to work.

Can you check manually the content on the xml file and not using Jenkins?
Note that if you want a consolidated report in jenkins, you do not need --input_coverage flags. Jenkins will do it for you. I will check the syntax and post it.

I suggest that you try to start with very simple projects like I did and replace progressively by yours. Perhaps you will see something.
Try also to check the log.

Please let me know if it solves your problem,

May 27, 2015 at 1:22 PM
Thanks for the quick reply. :)

I really appreciate you actually created test project to execute my scenario . Thanks again.

About the coverage xml generated using set of instructions in the following fashion

OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestA.cov -- TestA.exe
OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestB.cov -- TestB.exe
OpenCppCoverage.exe --source=C:\Dev --input_coverage=TestA.cov --input_coverage=TestB.cov --export_type=cobertura -- TestC.exe

I am able to view the tags for the TestA.exe and TestB.exe in the generated coverage xml.
I am really wondering if the entries for all these tests are there in the xml then why Jenkins is not able to display the coverage for the first two tests in the display report.

Also you have mentioned that for consolidated report in jenkins, I do not need "--input_coverage" flags. Jenkins does it .. so is it possible for you post the syntax
to achieve the consolidated report for multiple test executables and display in the Jenkins ?
Thanks in advance.
May 27, 2015 at 1:51 PM
I am able to view the entire report for all the test cases in the Jenkins.

OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestA.cov -- TestA.exe
OpenCppCoverage.exe --source=C:\Dev --export_type=binary:TestB.cov -- TestB.exe
OpenCppCoverage.exe --source=C:\Dev --input_coverage=TestA.cov --input_coverage=TestB.cov --export_type=cobertura -- TestC.exe

I did some changes in the configuration of project in the Jenkins which did display the report for all the tests.

Thanks a lot for the help. :)
May 29, 2015 at 12:10 PM

This should also work:

OpenCppCoverage.exe --source=C:\Dev --export_type=cobertura:A-Coverage.xml -- TestA.exe
OpenCppCoverage.exe --source=C:\Dev --export_type=cobertura:B-Coverage.xml -- TestB.exe
OpenCppCoverage.exe --source=C:\Dev --export_type=cobertura:C-Coverage.xml -- TestC.exe

Set Cobertura xml report pattern to *Coverage.xml.
Note that Cobertura xml report pattern is relativ to your workspace folder.

Jun 25, 2015 at 4:01 PM
Hey, Thanka a lot for the help.
I am able to generate the coverage xmls and publish them using the cobertura plugin ( using '--source' option )

In one of our scenario, we need to execute the code coverage using the '--module' toption instead of '--source'.
Also the option '--export_type=cobertura' need to be use for generating the reports in cobertura format.

here is the sample command

OpenCppCoverage.exe --module=C:\Dev\bin --export_type=cobertura:A-Coverage.xml -- TestA.exe
OpenCppCoverage.exe --module=C:\Dev\bin --export_type=cobertura:B-Coverage.xml -- TestB.exe
OpenCppCoverage.exe --module=C:\Dev\bin --export_type=cobertura:C-Coverage.xml -- TestC.exe

So in this case the xmls generated of size 1KB only with no covergae info and hence the Cobertura covergae report is empty :(

My question is does the '--module' option supports the export type as cobertura ?
If yes how to achive that ?
Jun 28, 2015 at 7:28 PM

There is no restriction between '--module' and '--export_type=cobertura'.
"--module=C:\Dev\bin" means do the coverage only for dlls / executable in the folder "C:\Dev\bin".
If the export has no coverage information, it means probably that "C:\Dev\bin" is not the correct filter.

When OpenCppCoverage starts, you have some explanation of why a dll is selected or not for the coverage.
See "I cannot see my module in the code coverage report." for more information.

Let me know if that solve your problem.

Marked as answer by OpenCppCoverage on 11/15/2015 at 3:37 AM