How to get gcovr to report 0% for untested files? - code-coverage

I have a number of source files in my project which are not tested at all. So they have gcno files but no gcda files. gcovr just skips them entirely, which artificially inflates my test coverage reporting. I've looked through the various options in gcov and gcovr, but I haven't seen any way of generating a 0% coverage metric for untested files. Is there any way to do this?

Gcovr does try to report coverage for uncovered files, but:
your gcc/gcov version must be sufficiently up to date
the file must contain executable code, e.g. the compiler might remove inline functions that are never called
For details, see the gcovr FAQ: https://gcovr.com/en/master/faq.html#why-are-uncovered-files-not-reported

Related

Getting the decision coverage HTML report with gcovr

I am using gcovr to generate the coverage analysis of some unit tests, and wanted to generate the HTML decision coverage report.
I am using Matlab, and am calling gcov and gcovr and generating the report following the instructions in the gcov 5.1 user's manual:
[status,report] = system([path_to_my_function,' & gcovr --gcov-executable gcov --decisions --html-details -o',name_of_my_html_report])
However, I am getting all the time an error saying that --decisions command is not defined for gcov. I have been trying different locations for the command, but didn't work, and looking on the Internet, but didn't find anything.
Does anybody have an idea of the possible error I may be doing?
Thank you!

Getting llvm-cov to talk to codecov.io

I'm in the process of (finally!) setting up code coverage monitoring for my brand new C++ project. Due to the fact that I need some advanced C++20 features (read, coroutines), I am using clang 6 as compiler.
Now, I followed this guide on how to do basic code coverage for your project, and everything worked like magic. If I do:
clang++ -fprofile-instr-generate -fcoverage-mapping test.cpp -o test.out
LLVM_PROFILE_FILE="coverage/test.profraw" ./test.out
llvm-profdata merge -sparse coverage/test.profraw -o coverage/test.profdata
llvm-cov show ./test.out -instr-profile=coverage/test.profdata
I get a nice, colored report on my terminal that tells me what is covered and what is not.
So far so good! I thought I was close to what I wanted, but then the pain started when I tried to get the report uploaded to codecov.io.
I have tried a few things, including:
Running their https://codecov.io/bash script on my coverage folder in the hope that maybe it would catch on my test.profdata. No dice, and it makes sense, since even llvm-cov needs the path to the executable file to run.
Using the export functionality: when running llvm-cov export --instr-profile=coverage/test.profdata ./test.out I get a good-looking JSON file (via terminal). I tried throwing the output in a coverage.json file, which actually got uploaded, but then codecov just says that there was an error parsing it, with no further information.
I'm feeling completely lost. Everything seems so black-box-ish on their website that I just don't understand how to get anything done that doesn't by chance perfectly fit the cases that they can manage.
How can I get this working with codecov? If codecov can't handle my reports, is there any other equivalent online code coverage that I can use to get this to work?
It looks like the bash script codecov uses to upload coverage data to their site looks for files matching a wide range of patterns associated with formats that it understands. These are poorly documented, but you can at least see which patterns are viable by looking at the script on Github. Of course, this doesn't tell you what expectations codecov has about the format of files matching a given pattern, as you discovered when your coverage.json file was rejected.
Through trial and error I have found that the following produces a file that codecov will interpret correctly when you run the bash script:
llvm-cov show ./test.out -instr-profile=default.profdata > coverage.txt
I haven't extensively tested what file names are allowed, but it seems that you can put whatever additional characters you want between coverage and .txt in the name of the file that you're piping the coverage data to (e.g. you could call it coverage_my_file_name.txt).
EDIT: Just in case this is helpful to anyone, it turns out that an important corollary to the above is that it's critical that you avoid naming anything that isn't a coverage report something that matches this pattern. I just dealt with a scenario where I had a bunch of executables named coverage_[more_text_here].out that were getting uploaded with the reports. It turns out that attempting to parse assembly code as a coverage report can cause codecov to mysteriously fail without any useful errors.
Another option is to use GCOV profiling, which is a little less precise than source-based, but it is supported by codecov.io. You need the "--coverage" compiler flag to enable it.
You can use grcov (which you can also download from https://github.com/mozilla/grcov/releases) to parse the gcno/gcda files and upload them via the codecov.io bash uploader:
grcov OBJ_DIR -s SRC_DIR -t lcov --branch > lcov.info
bash codecov.sh -f "lcov.info"
I'm planning to add support for source-based reports to grcov, which will make it easier to support the format on codecov too.

how to see line coverage in Bullseye

Recently I started using BullseyeCoverage.
I'm going through the steps: compiling with BullseyeCoverage, running some test cases on the binaries created, generating a coverage report.
In the coverage report there are: function coverage, and condition/decision coverage. However, there is no line coverage. I tried to find a way of generating line coverage statistics, unsuccessfully. I thought of using covbr to this end, but, I need something that will cover all of my sources altogether.
Thanks for your help!
Bullseye does not support line coverage (which is also called statement coverage).For reasons, see http://www.bullseye.com/statementCoverage.html

Can EclEmma be used with obfuscated jar file

Can EclEmma eclipse plugin be used for code coverage with obfuscated (with Proguard) jar file?
Thanks.
I don't think that this makes sense, because the source files would have to be obfuscated too, to generate an appropriate report.
A report is always generated using the source files of the project and these must match the class files exactly.
I don't think that you want to look at a coverage report of obfuscated code.

Test code coverage without source code?

What tools are out there that can perform code coverage analysis at the machine code level rather than the source code level? I'm looking for a possible solution to perform fuzz testing on software that I do not have source code access.
I think the IBM Rational test coverage tools instrument object code.
Assuming you had such a tool, but no access to the source, what exactly
would code coverage mean, other than 100%?
If you didn't have 100% coverage, you'd know you hadn't exercised something.
But you would have no way of knowing what.
For compiled code (not Java), try Valgrind.
Old post... but my two cents.
If you have a bunch of jars and if you know what classes/methods you are using, you can instrument the jars with Emma and run your sample application against those jars.
In my case, I have jars which are actually proprietary components (to generate html code) which our company uses to build it's web-pages. We have a sample application that utilizes these components and a bunch of tests that are run against the sample app. I wrote an ant task to copy the maven dependencies to a directory, instrument them and run the tests against these instrumented jars. This task is invoked from the maven POM and is hence part of the build process.
Also, as part of the build process, we process the emma coverage data to produce a report. This report shows the classes and methods in the jar for which we do not have the source code! Hope this helps.
If you have the number of entry points (public methods), you can test the coverage for that. I don't know any tool for that though.
Otherwise you would have to test the assembly code coverage, and I don't know if it is possible.

Resources