Skip to content

Add support for clang style code coverage #107

Description

@eyal0

There are two sorts of code coverage, gcc style and llvm style. CodeCoverage.cmake uses the gcc style. It generates .gcno and .gcda files and using tools like lcov, gcov, etc, it can create a .info file, which is a common format for coverage and can be accepted by websites like https://coveralls.io/ . This is the way to do coverage on gcc.

Clang is the llvm-based c compiler and it also supports this format but it is not the native and preferred one. As a result, it generates file that are only compatible with older versions of lcov. It also has a lot of compilation issues.

The llvm-native way to do code coverage with clang generates .profraw files. Those files can be merged with the llvm-profdata tool and then converted into an html report or .info file using the llvm-cov tool. Alternatively, you can use the grcov tool to merge and output in one step, and it can output coveralls data directly or .info files. The profdata files are more detailed and they claim that the native way is faster.

I think that it would be nice to either add this into CodeCoverage.cmake or have a new ClangCodeCoverage.cmake. It would work similarly to the existing one, where you first specify which binaries you want to instrument and then you make a target that generates coverage. But internally, the tools and options are very different. If there a lot of "if clang then do this otherwise do that" then it might be unwieldy to try to put both into a single file. But if they have enough in common then they could go together.

Here's my work in progress:

https://github.com/pcb2gcode/pcb2gcode/pull/840/changes#diff-bf3c06ef521f7ef5b8c2e4ff5b05ca579bd29e6016a829870b6e74abb54694b1

Let me know if this is something worth contributing to here. And if so, let me know what you think about having it as a different cmake file versus trying to get both into the same cmake file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions