Search code examples
gcovgcovr

How to make gcov and gcovr pick up source and header files


I am trying to generate coverage report for project using .bat file as detailed below.

  1. I see very few .gcov files. Also, when I click on link on generated html output, I am not able to see file details (file not found error). How do I fix it?
  2. After I execute .bat file, I see output like ‘parsing coverage data for QString.h’ (QT library files). Is it expected?

I have seen many related questions but I am not able to figure out

(in report_coverage.bat)
    set GCovrpath= C:\python37\script\lib\
    set GCovpath= C:\abc\ghj\bin\
    set datafiles= C:\source\mywork\root\testing\unittests\rose\build\debug\
    set gcovr_src= C:\source\mywork\root\

    %GCovpath%gcov.exe  %datafiles% >> output.log 
     gcovr %datafiles% -s -p --html --html-details --gcov-executable %GCovpath%gcov.exe -o Test.html –verbose

Here are details….

Compile and execute code using

QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage

QMAKE_LFLAGS += --coverage .GCNO and .GCDA files are generated as expected

It seems simple directory structure

 Root
     Header
           Rose
           Marigold
           Jasmin   
     Source
           Rose
           Marigold
           Jasmin   
     Testing
           UnitTests
               Rose
                  build
                       debug
               Marigold
                  build
                       debug
               Jasmin   
                  build
                       debug

Thank you.

Update: See answer below


Solution

  • I can not emphasis enough "\" for windows.

    run this command from debug folder(because test.exe is here)

    gcov -b -l -s C:\source\mywork\root\ debug\*.gcno
    

    run this command from Unit tests folder (this will exclude .h files and files containing test)

    gcovr -g -k -v  --root C:\source\mywork\root\ -e ".*\.h"    -e ".*test[_-|A-Z|a-z|0-9]*\.cpp"   --html --html-details -o report.html