Lcov for multiple directories containing gcda files

I want to generate coverage reports using gcov and lcov.

What I have done so far : -

1. I compiled my code using --fprofile-arcs and -fprofile-coverage in g++. 2. I have linked using lcov. 3. I have .gcno files with th eo location. 4. When I execute binary, it is resulting into .gcda files. 

What do I need to do : -

I have to use these data files (.gcda) and want to create a clean report using lcov.

Problem : -

There are several directories in which there are source files and inside each directory I create dir obj / ARCH to store object files.

Therefore, the final directory structure will be: -

  proto ----> MJ1 ----> MJ2 ----> MJ3 ----> MJ4 ----> MJ5 MJ1 ----> .cpp ----> obj/linux/*.o *.gcno *.gcda MJ2 ----> .cpp ----> obj/linux/*.o *.gcno *.gcda 

same with M3, M4, M5.

I run lcov from the proto level and it finds .gcda files but gives some error in finding .h and .C files. Any idea how to make this process independent?

 Error:- ../MjUtil/glob.h:cannot open source file ../MjUtil/MJError.h:cannot open source file ../MjUtil/OsStatisticsFile.h:cannot open source file 

Thanks in advance.

+4
source share
2 answers

Have you tried using the --base-directory . option --base-directory . for lcov?

+1
source

It is generally recommended that you use absolute paths when compiling CPP.

Also, it should not depend on the fact that you run lcov. For instance:

lcov -c -d ../../../ src -o lcov.info

And src dir contains:

main.cpp main.gcno main.gcda

Even if the main.gcno file contains a relative path to main.cpp , lcov will still handle it.

You must also ensure that the gcda / gcno files have not been moved. Using a script or manually. In case they were moved, of course, the relative paths will be wrong and lcov will not be able to find the sources.

0
source

Source: https://habr.com/ru/post/1412585/


All Articles