How to specify .gcno and .gcda directory separately in Gcov? - gcov

I'm going to have multiple .gcda files in my project. One for each test case. Because gcov will merge .gcda for each test case execution, I move each .gcda file to a different directory.
When calling gcov, I tried to specify .gcda (.\data\gcda\evenodd.gcda) and .gcno (.\data\gcno\evenodd.gcno) files.
I used -o data\ but it seems that gcov doesn't scan the path subdirectories.
Then, I tried to specify each file's path like this:
gcov -o data\gcno\evenodd.gcno data\gcda\evenodd.gcda evenodd.c
because I thought it would accept more than one path. Alas, the result is :
By putting the .gcda path first instead of .gcno, this is what I got:
Since the default location of these files is in the source file directory, I tried to put .gcno there and then specify .gcda path. It didn't work.
Based on those results, gcov won't receive more than one path for -o.
Apparently gcov will always look for .gcno and .gcda in pair when -o is specified. Is there a way to do this other than putting both of them in the same directory?

You should not move .gcno/.gcda files to different folder after generation because gcov will not be able to locate related source files. Moreover, gcov has to be run in exact same directory where test executable has been compiled.

Related

gcovr with Cobertura XML output gives absolute path of production files

I have managed to show code coverage data with Cobertura XML in Jenkins.
Its works well, but I wants to see the source code in Jenkins, too.
I accidentally saw, that Jenkins is referring for the source files at my windows harddrive, but the files are on a Jenkins server (different PC). This happens maybe, because in Cobertura output XML, the "filename" refers to an absolute path and not relative from directory. The XML attribute looks like filename="C:/Users/PathToMySources".
How I can change filenames in Cobertura XML to be relative?
gcovr.exe is invoked like this:
gcovr.exe --filter ../MySources/ --branches --html-details Test.html --cobertura Test.xml
My Project look like this:
MyProject
|
|---Library A (has subfolders)
|
|---Library B (has subfolders)
|
|---TestFolder for Library A and B (has subfolders)
This Layout is like this because Library A, B and Testfolders are externals in svn for sharing the library to everyone in the company.
With gcovr I refered for example to Library B. In Library B, I have subfolders. Some Subfolders contains only headers because of template classes in C++.
Now I saw another issue.
With --filter, the header only classes are included in coverage output, with --root they are not included!
In this instance, you can fix things by changing --filter to --root.
Gcovr has a concept of a “root” directory which defaults to the current working directory. The root is used for various purposes like serving as a default filter, but also for deciding how file names are presented in reports.
If a file path is within the root directory, a path relative from the root directory is shown.
Otherwise, an absolute path is shown
It is unusual to ever see an absolute path in a gcovr report, unless you're trying to include coverage for a library outside of your project directory, or if you're using the --html-absolute-paths option.

Gcov not generating.gcda files for few classes

I am using gcov to find code coverage of my application while running functional test cases.
Issue: .gcda files are not getting created for few classes though those classes are being executed
Steps:
Compile Application code with gcov and verify .gcno files are generated for all classes
Create binary image of compiled code and deploy server using that binary
Use cross profiling while deploying server. Home directory structure for my source code was "/proj/QQ/scm/tools/jenkins/db_ws/FunctionTestCoverage/ccode/" and I used below mentioned gcov parameters for cross profiling
GCOV_PREFIX=/automation/testCoverage
GCOV_PREFIX_STRIP=7
Run Functional Test Cases to hit application code
.gcda files gets created for few classes only. It is not getting created for all classes which are being executed.
.gcda files are generating under directory structure "/automation/testCoverage/ccode"
I believe this should not be issue with cross profiling. suppose I have 5 directories in parallel then .gcda files are generating for 2 directories only.
What can be root cause for my issue where .gcda are generating for only few files and how to resolve this?

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 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)

Generating empty .gcda files

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?
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
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

Resources