mozilla / grcov

Rust tool to collect and aggregate code coverage data for multiple source files
Mozilla Public License 2.0
1.19k stars 149 forks source link

[Help] Using grcov html output with complex C++ clang-cl project #1234

Closed LarrxX closed 1 month ago

LarrxX commented 1 month ago

Hello,

I am trying to generate an HTML report for a very complex C++ project compiled with clang-cl (the Microsoft frontend for clang). I am using CMake with a Ninja generator (and not a MS Solution/Project).

I have multiple DLLs, multiple test executables and wish to generate a single global project report.

The way I have things set up right now generates a global report, with a listing for each library, and each file within that library. But when I look at each file individually, the display is "weird". For example, a file displays "50% lines, 85.71% functions and 100% branches" and when I click on the file, only 3 lines out of 105 are highlighted in green, 3 lines in red and the rest is just not highlighted. Is that the expected behavior? If so, I am at a loss on how to interpret the results.

What I do to get that report is:

  1. Compile with the --coverage flag : this generates multiple .gcno files in multiple folders next to the .obj`` files (they are scattered all over the build folder in//CMakeFiles/.dir/`)
  2. Run the GoogleTest executables: this creates .gcda files next to the .gcno files
  3. Run grcov with the follwing command: grcov --llvm --branch --binary-path <BUILD_FOLDER>/bin <<BUILD_FOLDER>/<LIBRARY_NAME>/CMakeFiles/<LIBRARY_NAME>.dir <BUILD_FOLDER>/<LIBRARY_NAME2>/CMakeFiles/<LIBRARY_NAME2>.dir --source-dir ../../Sources --output-types html --ignore Dependencies/**/*

I have a feeling that passing a list of folders to the --binary-path argument is where I am going wrong, but I'm not really sure.

What would be the best way to achieve what I am trying to do?

Thank you!

LarrxX commented 1 month ago

Answering myself: after hours of trial and error, I changed the compiler options from --coverage to -fprofile-generate -fcoverage-mapping which generates a single .profraw file.

The htm generated fro that file seems to be fine.