I use gcov for doing code coverage analysis with lcov for generating graphical output of coverage. This works well for code file where atleast some part of object file has been executed. I want to be able to track files which have not been executed at all. I suspect this has to do with .gcda files not being generated for these files. Is there a way to force the generation of .gcda file for all object files irrespective of execution?
Asked
Active
Viewed 3,701 times
9
-
I want to do the same. I'm dealing with a codebase where the unit tests are compiled as individual executables for each namespace. I can compile each with coverage and I get results for the classes that are involved in the tests. But some files have not had unit tests created for them, so are left out of this. They don't even get compiled as part of the test compilation. What I want is to somehow generate an empty initial .gcda for any .cpp. – Benedict Jun 19 '14 at 14:56
2 Answers
7
The procedure to do this is outlined here:
http://linux.die.net/man/1/lcov
Recommended procedure when capturing data for a test case:
create baseline coverage data file
lcov -c -i -d appdir -o app_base.info
perform test
appdir/test
create test coverage data file
lcov -c -d appdir -o app_test.info
combine baseline and test coverage data
lcov -a app_base.info -a app_test.info -o app_total.info
-
2Btw, the baseline coverage can also be generated after the tests are performed. – maxschlepzig Apr 29 '17 at 18:19
0
For all of your files that are correctly compiled and linked, there will be a .gcda file. If you see that there's a missing *.gcda file check to see if the *.gcno file exists. If it doesn't check to see if all of you Makefiles are correctly build with:
- -ftest-coverage : The .gcno notes file is generated when the source file is compiled with this
- -fprofile-arcs : .gcda count data file is generated when a program containing object files built with the GCC -fprofile-arcs option is executed.
More info on: https://gcc.gnu.org/onlinedocs/gcc/Gcov.html#Gcov

aLt
- 48
- 5
-
1After building a *.gcno is generated, but a *.gcda file is only generated during testing. If a source file has a *.gcno file but not a *.gcda file, it is ignored by gcov >= 4.7. See https://github.com/gcovr/gcovr/issues/33 – Victor Jan 26 '16 at 16:34