Search code examples
g++code-coveragecompiler-optimizationgcovlcov

Can GCOV create .gcda file in the different directory structure?


I am trying to generate code coverage report using lcov from home directory. Sorce code is compiled with -coverage option to generate coverage information at compilation time(gcno files are created). Then I have copied the executables and gcno files to home directory.I am trying to check if by ./exe in home directory ,is it possible to generate coverage report.I run the executables in /home and its showing test cases passed but it was discovered that the .gcda files are not created.

I add the following CPP flag:
 -fprofile-dir= “/home” 
and hence run the executable but still .gcda is not created .

Where I need to specify the path so that it will take .gcno files from home directory and generates the .gcdo files in the current directory??


Solution

  • Maybe, you're compiling more than one module, have you checked the dependencies between modules? Please do this:

    1. compile all your code,
    2. then remove the useless .gcno files. (Gcno are generated at compilation time)
    3. Execute your tests (gcda should be created matching gcno files)
    4. Generate your report

    Second possibility:

    1. Compile your code
    2. Execute the tests
    3. Remove useless gcno + gcda files
    4. Generate your report

    Others: I guess you can use some options to generate report for a dedicated module, but I'm not very familiar with those options.

    Regards