lcov get empty info file after run the `lcov -c -d /xxx -o demo.info --test-name gtest_demo --no-external`
Env:
gcc --version:
gcc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
lcov -v:
lcov: LCOV version 1.15
After compile the source code, I get *gcno files on the target directory, something like that:
-rw-------. 1 kx kx 1302236 Jan 6 00:34 gtest_column_unique.cpp.gcno
-rw-------. 1 kx kx 4919712 Jan 6 00:34 gtest_column_unique.cpp.o
-rw-------. 1 kx kx 1894048 Jan 6 00:34 gtest_weak_hash_32.cpp.gcno
-rw-------. 1 kx kx 7907720 Jan 6 00:34 gtest_weak_hash_32.cpp.o
Then, I run the gtest_demo and get *gcda files on the same directory of *gcno files:
-rw-------. 1 kx kx 63852 Jan 6 01:02 gtest_column_unique.cpp.gcda
-rw-------. 1 kx kx 1302236 Jan 6 00:34 gtest_column_unique.cpp.gcno
-rw-------. 1 kx kx 4919712 Jan 6 00:34 gtest_column_unique.cpp.o
-rw-------. 1 kx kx 82936 Jan 6 01:02 gtest_weak_hash_32.cpp.gcda
-rw-------. 1 kx kx 1894048 Jan 6 00:34 gtest_weak_hash_32.cpp.gcno
-rw-------. 1 kx kx 7907720 Jan 6 00:34 gtest_weak_hash_32.cpp.o
So, I try to generate the coverage info files via this command:
lcov --capture --directory ./{*gcno_FILE_DIR}/ --output-file gtests_demo.info --no-external
Capturing coverage data from ./CMakeFiles/gtest_demo.dir/
Found gcov version: 10.2.0
Using intermediate gcov format
Scanning ./CMakeFiles/gtest_demo.dir/ for .gcda files ...
Found 2 data files in ./CMakeFiles/gtest_demo.dir/
Processing Columns/tests/gtest_weak_hash_32.cpp.gcda
Processing Columns/tests/gtest_column_unique.cpp.gcda
But the gtests_demo.info is empty.
-rw-------. 1 kx kx 0 Jan 6 01:19 gtests_demo.info
Any idea?
Apologies for the obvious question…what happens when you remove the “--no-external” flag?
Do you have a small example you can share?
Thanks
Henry
@henry2cox Sorry for replying so late, I am quarantined due to the pandemic and I don't have a laptop by my side :(
what happens when you remove the “--no-external” flag?
Yes, it works, I will take a closer look at what this parameter does.
BTW,if we run the gtest_demo on other place (i.e. inside the docker). How can I make sure the *gcda files are produced correctly? Maybe we can map the entire build directory into docker? (not sure), or is there any best practice?
Thank in advance :-)
Maybe we can map the entire build directory into docker?
Hmm.. I tried this and the *gcda files are not generated as expected..
You need to have a copy of the .gcno files (generated by your compile command) wherever you are running your executable. The executable needs the data in the .gcno file to be able to reconstruct the basic block and other info in order to be able to generate coverage data.
It is easiest if the layout of your .gcno files/directories is the same as it was in your build (i.e., so the same relative or hard paths lead to the expected files). It may be possible to make things work even if the layout is different – but that will be the long way around the block.
This works with the same GCOV_PREFIX feature described in an answer to a different question.
Henry
You need to have a copy of the .gcno files (generated by your compile command) wherever you are running your executable. The executable needs the data in the .gcno file to be able to reconstruct the basic block and other info in order to be able to generate coverage data. It is easiest if the layout of your .gcno files/directories is the same as it was in your build (i.e., so the same relative or hard paths lead to the expected files). It may be possible to make things work even if the layout is different – but that will be the long way around the block. This works with the same GCOV_PREFIX feature described in an answer to a different question. Henry
Hmm.. I tried this but still cannot get the .gcda files even if the directory structure of the running environment is consistent with that on the build machine (copy the .gcno to the docker and run the gtest_demo)... not sure what's wrong here..
I'm using lcov 1.14 and having the exact same issue. --no-external does not appear to honor --directory, and instead ignores everything
Correction: in only appears to ignore anything if there is no --base-directory set to whatever working directory lcov is running from. Once you add --base-directory ., it successfully ignores system libraries.
Unfortunately it still includes all subfolders in the working directory, even though you still have -d /xxx
Confirmed that the pattern passed to --exclude cannot include ** wildcards in it. It collects the filepaths using the same behaviour as find . -type f -name "<pattern>" does, which is why ** wildcards cause failure.
I'm working on a way to get around this issue
Is this still a problem? If so: does anyone have a testcase which exhibits the issue?
If no responses in a week or two: I will assume that the problem has been addressed, and will close this issue.
No responses/no updates - so I assume that this issue is addressed.
If there is still a problem, please either reopen this issue or file a new one. Please include a detailed description of the problem, and ideally include a testcase that exhibits the problem. Henry