I'm using code coverage on different test suites and those suites are launched under different directories.
Say my suite1 is launched in directory /path1/mysoft/src
and my suite2 is launched in directory /path2/mysoft/src/
I launch lcov in /path1/mysoft
(respectively with path2
) using lcov -d . -c -o suite1.info
(resp. with suite2
).
Then I want to cumulate the coverage from both test suites. I copy the suite1.info
and suite2.info
files in another directory /path3/mysoft
which also contains the source code from my program.
I can cumulate both with lcov -a suite1.info -a suite2.info -o tests.info
however the coverage for a given file src/example.c
won't be cumulated as lcov
will condider that /path1/mysoft/src/example.c
and /path2/mysoft/src/example.c
are two different files. Therefore cumulating won't work.
How can I cumulate code coverage for the same source code coming from different base directories?
Some unsatistfying solutions
lcov -d . -c --rc geninfo_adjust_src_path=/path1 -o suite1.info
. In this case the coverage will be cumulated correctly by lcov
, however genhtml
will fail because it won't find the source code at the correct place. At this time I don't know what path3
will be, so I can't replace path1
by path3
.lcov
outputs by using the same geninfo_adjust_src_path
option. I've been unable to do so: launching lcov -a suite1.info -a suite2.info --rc geninfo_adjust_src_path='path1 => path3' --rc geninfo_adjust_src_path='path1 => path2' -o tests.info
didn't change anything.Some context
Why am I launching my test suites in different base directories? Well actually the continuous integration is doing that. So path1
is something like /home/gitlab/builds/b8e873c2/0/
. The test suites are each launched in a different job and cumulating the coverage is also done in another job. Each job is launched in a different base directory and the .info
files are retrieved using artifacts.
Thanks for any help!
There is an answer, that may not be the most elegant. As source filenames are stored in plain text, they can be changed pretty easily using sed
for instance.
Therefore all the commands launched could look like this (remind that each is actually launched by a different job):
lcov -d . -c --rc geninfo_adjust_src_path=/path1 -o suite1.info # in /path1/mysoft
lcov -d . -c --rc geninfo_adjust_src_path=/path2 -o suite2.info # in /path2/mysoft
# From /path3/mysoft, after retrieving suite1.info and suite2.info
lcov -a suite1.info -a suite2.info | sed 's/^SF:/mysoft/SF:/path3/mysoft' > tests.info
The two firt lines remove any reference to /path1
or /path2
from the .info
files. The third line adds a reference to /path3
in front of the path to the source files so that the genhtml can find them.