How to improve the branch coverage using gcovr tool - gcov

I have written a sample program using C++. I have written corresponding unit tests using GUNIT framework. I was successfully able to generate.gcda and .gcno files for every source file. I used (gcov -b -l -p -c *.gcno) command in the folder where the .gcno files were generated. I am using gcov 7.5.0 . When i ran this command i saw that it gave me a)Lines covergae in percentage b)Branches covered in percentage c)Taken atleast once . Next i ran (gcovr --html -o Filename.html -r /path_to_C_sourceFiles/ .) command to generate the html output for this data. In the html file i see that the branch covergae data is extracted from the taken atleast once data which was generated by the gcov. Why is the html not taking the branches covered percentage from the gcov data and displaying it as branch covergae. Taken atleast data given by the gcov tool is a reduced number when compared to branches percentage. What is this taken atleast once?

A branch is covered if it was taken at least once. If a branch is executed multiple times, it is not more covered. So gcovr primarily considers covered/uncovered status for lines and branches, whereas GCC's gcov tool shows execution counts and branch probabilities.
Having access to the branch probabilities can be useful. Not in the context of testing, but perhaps for low-level code optimization. If you need that data, you will likely want to look at the gcov files yourself.
However, the next version of gcovr (expected to be gcovr 4.3) will show branch counts (not percentages) in the HTML report:
For each line with branch coverage data, there will be a popup that shows full branch counts.
You can use this functionality right now if you install gcovr's development version:
pip install git+https://github.com/gcovr/gcovr.git

Related

GCOV: gcda files combination

Good afternoon,
I'd like to know if it could be possible to combine several gcda files without using the lcov -a tracefile1 -a tracefile2 -o output.html.
Actually this is my spec:
compile my code on local server
excute tests on remote server 1 and 2
{
then copy the generated gcda on server1 on the local compilation server and generate the info file thanks to lcov
then copy the generated gcda on server2 on the local compilation server and generate the info file thanks to lcov
then combine both info files
}
The info file generation is actually quite long and I'd like to know if there is a possibility to combine gcdas from servers 1 and 2 without creating the info file.
And generate the info file only for the resulting gcdas?
Gcov as of now does not have any functionality to merge coverage reports.
I have a setup similar to yours and I use lcov to merge the tracefiles(or .info files).You can write scripts that will transfer the .gcda files from remote servers back to your local machine to generate the coverage report. There are other tools available that can solve your problem like TestWellCTC++,Rapicover,etc but they are not open source.
Gcov as of now has functionality to merge coverage reports:
$ gcov-tool merge path1 path2
(by default results will be stored in merged_profile folder).
To add to another answer, gcov can also merge coverage data from multiple runs with the help of gcov-tool:
$ gcov-tool merge dir1 dir2
(by default results will be stored into merged_profile folder).
Unfortunately gcov-tool allows merging only two profiles at a time but you can use gcov-tool-many to work around this.

How to show branch coverage for C++ project on coveralls.io?

I am using the coveralls.io service to display line coverage for my C++ project. I also want to track branch coverage, but cannot get it to work.
On Travis CI, I use this call to generate the coverage report:
coveralls -r <my_project_root> -b <my_build_dir> --verbose --gcov=gcov --gcov-options '\-lpbc';
The coveralls script is previously installed with pip
pip install cpp-coveralls urllib3[secure]
I get the line coverage shown correctly on coveralls.io, but not the branch coverage. I don't know what of the following things I am doing wrong.
Do I have to activate it on coveralls.io explicitly?
Is there something wrong with the coveralls command?
Can coveralls.io even show branch coverage?
Pretty late to the party, but to answer your question(s):
Yes, you will want to enable the Coveralls setting for BRANCH COVERAGE: INCLUDE IN AGGREGATE %:
Of course, this will only work if branch coverage is included in your original coverage report.
That happens in a prior step, when you compile the original project into an "instrumented" version of the source code and generate the GCOV coverage report, before you use the coveralls command to POST the coverage report to Coveralls.
Something like:
gcc -Wall -ftest-coverage -fprofile-arcs cov.c
gcov --branch-probabilities cov.c
Source: gcov Wiki - Example

How to determine absolute path of target using bazel query?

Question
Is there any way I could use bazel query or aspects to identify where on the package path bazel is picking up a package? Something similar to the which command.
The documentation suggests using the --show_package_location. However that is deprecated and no longer supported, see #5592. Additionally, my attempts at using it have not uncovered much useful information. I have tried bazel query //some/target/... --output label_kind --show_package_location as well as other permutations with bazel build and it doesn't add output anything different to the console output.
Motivation
I have two different directories on my package path for fetch, query and build.
--package_path=%workspace%:%workspace%/__fuse__
This configuration supports a workflow where users perform sparse-checkouts of our large repository, while still being able to build code that has not been locally checked out. When building targets, Bazel checks for the locally checked out version of package, and if that doesn't exist, it searches a read only fuse mount.
Sometimes it's unclear to users where a package is getting picked up from, i.e. whether it's the locally checked out version or the one served from fuse. This becomes problematic when they delete or move a Bazel package, and Bazel picks up the version on the fuse mount.
It'd be nice if I could point them to a command that would map each package to where it's being picked up. For example, if i ran the command on ...
//some/package/foo --> package_path/some/package/foo
//some/package/bar --> other_package_path/some/package/bar
I completely missed this in the bazel query documentation.
With bazel query, I simply needed to add --output location, so provided I make a query like:
bazel query //some/package/... --output location
Then bazel query will output
/absolute/path/some/package/BUILD:lineno:colno target_kind label
for each target in //some/package/...

GCOV: GCDA files not generated when to many tests performed

Good morning,
I've got a problem when using GCOV within my working environment.
Gcov is working very well when I run some tests cases (up to 1000) but no gcda are generated when running more tests.
This is how I use it.
I compile my code with gcov flags correctly set
I boot a test server containing the gcov libs, and the variables GCOV_PREFIX and GCOV__PREFIX_STRIP
I launch my regression on this server
Once finished I stop the server and now all the gcda files are generated
use lcov and genhtml to generate the test coverage and the report.
This works very well when I've got few tests to lauch (up to 1000 cases I guess), but if I run more tests, I don't get any gcda files anymore...
I could not find any documentation on this part, is there a buffer somewhere, where all the gcdas files are stored waiting for the server to be released?
Is it possible to parameter this setting?
Is there any documentation on this subject somewhere?
Thanks a lot for your help.
Regards,
Thomas

how to change the path of source file which was referred gcda?

When i build my project for coverage testing with "--coverage -fprofile-arcs -ftest-coverage", and then move the build and source to the other user directory to execute testing. I will get so many problems such as "xxx/cc/cc/getopt_log.c:cannot open source file"
the details as the below:
Processing cs/CMakeFiles/cfa/__/src/base/fault_injection.c.gcda
/home/cov/build/xfcq/src/base/fault_injection.c:cannot open source file
the path of "/home/cov/build/xfcq/src/base/fault_injection.c" is the path of build environment, how to change it as the relative path or the path I specified.
I tried to use GCOV_PREFIX and GCOV_PREFIX_STRIP, these can't work well for me.
I also tried to add -b option for lcov, it does not also work well for me.
e.g., lcov --gcov-tool=/bin/gcov -d . -b xx/src -t "xfcq" -o test_cov.info
do you have idea to resolve it?
Well for using gcov coverage process you should never move the files after building your project, instead you should modify your automated build scripts to build everything to the desired location.
When you compile your project with the specified options it generates *.gcno files for each source file which are necessarily the flow chart like details of the relevant source file.
So, the object files are instrumented in such a way that they should trigger function(added by compiler to generate coverage info ) whenever any line of statement is executed to generate *.gcda files with all the execution information.
Note: I can see that you have specified three options in question (--coverage -fprofile-arcs -ftest-coverage) which is again wrong, as --coverage works as a replacement to the other two.
If you specify only --coverage then it will do for the compilation and the linking too.(remember to use it at both the places positively though)

Resources