0

I have a large project with unittest binaries running on the other machines. So, the gcda files were generated on the other machines. Then, I download them to the local machine but the different dirs. Each of the dirs has the sources code.

For example: dir gcda1/src/{*.gcda, *.gcno, *.h, *.cpp}..., dir gcda2/src/{*.gcda, *.gcno, *.h, *.cpp}....

Because the project is very large, so I have to run multiple lcov processes at the same time to generate info files to save time. And then merge these info files.

The problem is, when I merge these info files, it will take dir infos, for example:

gcda1/src/unittest1.cpp
gcda2/src/unittest1.cpp

I want this:

src/unittest1.cpp
#src/unittest1.cpp # this is expected to merge with above

The commands I use:

$ cd gcda1
$ lcov --rc lcov_branch_coverage=1 -c -d ./ -b ./ --no-external -o gcda1.info
$ cd ../gcda2
$ lcov --rc lcov_branch_coverage=1 -c -d ./ -b ./ --no-external -o gcda2.info
$ cd ..
$ lcov -a gcda1/gcda1.info -a gcda1/gcda2.info -o gcda.info
$ genhtml gcda.info -o output

The root dir contains the source code.

1 Answers1

0

Description

Well, I have found a method to solve this problem finally.

The info files lcov generated are plain text file. So we can edit them directly.

Once you open these files, you will see every file line start with SF. Like below:

SF:/path/to/your/source/code.h
SF:/path/to/your/source/code.cpp
...

Problem

In my problem, these will be:

// file gcda1.info
SF:/path/to/root_dir/gcda1/src/unittest1.cpp
// file gcda2.info
SF:/path/to/root_dir/gcda2/src/unittest1.cpp

And, after lcov merge, it will be:

// file gcda.info
SF:/path/to/root_dir/gcda1/src/unittest1.cpp
SF:/path/to/root_dir/gcda2/src/unittest1.cpp

But, I expect this:

// file gcda.info
SF:/path/to/root_dir/src/unittest1.cpp

Method

My method to solve the problem is editing the info files directly.

First, edit gcda1.info and gcda2.info, change /path/to/root_dir/gcda1/src/unittest1.cpp to /path/to/root_dir/src/unittest1.cpp, and /path/to/root_dir/gcda2/src/unittest1.cpp to /path/to/root_dir/src/unittest1.cpp.

Then merge them like below and generate html report:

$ lcov -a gcda1.info -a gcda2.info -o gcda.info
$ genhtml gcda.info -o output

In a large project, we could not manually edit each info file, otherwise you will collapse.

We can use sed to help us. Like below:

$ sed "s/\(^SF.*\/\)gcda[0-9]+\/\(.*\)/\1\2/g" gcda_tmp.info > gcda.info