0

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

BeHappy
  • 138
  • 2
  • 17

2 Answers2

1

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
BeHappy
  • 138
  • 2
  • 17
0

If you invoke gcov yourself, you need to run it from the same directory where the compiler was executed, and you need to give it either the path to the gcno, gcda, or source file. Gcov can only handle one input file at a time.

When gcov runs in the correct place, it can look at compilation metadata to find the correct source file. If there are errors about missing source files, that indicates that you didn't use the correct directory.

Gcovr runs gcov automatically, and has heuristics to figure out the correct directory. However, you should still run it from the directory where you started the compilation (typically, a build directory).

And gcovr will exclude coverage data if it doesn't belong to your project. If you have a separate build directory, you will need to set the --root argument to the directory containing your source code. Gcov processes coverage data for all files that were compiled, which makes this post-processing by gcovr necessary.

In verbose mode, gcovr will output “Parsing coverage data for <file>” when opening a gcov report. It will then use data within the file to decide whether it belongs to your project, and output “Filtering coverage data” if the source code is part of your project, “Excluding coverage data” otherwise.

There are multiple reasons why the coverage report might not be complete:

  • There is a problem with filtering.
  • Gcovr's heuristics can get confused when multiple files have the same name, e.g. two files called util.h in different directories.
  • Gcovr's --html-details report consists of multiple .html files, so make sure that they are all available.

In your BAT file, this invocation might work better:

gcovr --root ../src --print-summary --sort-percentage --html-details --gcov-executable %GCovpath%gcov.exe --output Test.html --verbose

assuming the following directory structure, and that you run gcovr from within build/:

your-project/
  src/
    Header/
      ...
    Source/
      ...
    Testing/
      ...
  build/
    ...

If there are problems with a root path like ../src, consider using an absolute path like C:/path/to/the/src.

amon
  • 57,091
  • 2
  • 89
  • 149
  • Thank you amon for detailed info, however, I am not clear what am I missing. BTW, I am using absolute path. – BeHappy Sep 30 '19 at 21:51