简体   繁体   中英

lcov marking lines with function declarations as reachable but not covered

I'm trying to use lcov (v1.13, on OS X, with clang as compiler) to generate code coverage for my test suite and I've hit one annoying problem that I don't know how to solve. There's a few similar questions on SO, but I couldn't find the solution to this one. For some reason, function/member declarations are marked as reachable but not executed, kind of like in the example below (this is inline method definition in a header):

在此处输入图片说明

This renders line coverage metrics useless, so I was hoping there's a way to fix it without marking each declaration as LCOV_EXCL_LINE.

Compiler flags used are pretty standard:

-g -O0 -fno-inline -ftest-coverage -fprofile-arcs -fno-elide-constructors

What's strange is that method definitions in source files are also marked as red, although the bodies are not, eg:

// header.h
class Foo { 
    void bar();      // ignored, marked as unreachable
}  

// header.cpp
void Foo::bar() {    // marked as red (reachable / not executed)
    do_something();  // marked as covered
}

If it's of any importance, the source files are part of a static library that's statically linked to the test harness in CMake.

Answering my own question:

Apparently, lcov -i (initial capture) assumes that starting lines of functions are instrumented, whereas with LLVM they are actually not (whereas with GCC where they are). There is an upstream GitHub issue ( linux-test-project/lcov#30 ) documenting this in more detail.

Until this is fixed upstream in lcov , I've posted a simple workaround -- a Python script that removes function starting lines from base coverage file, which should "fix" it, at least temporarily.

That fix worked for me but only considering line coverage. When dealing with function coverage I do still have problems counting the number of functions within a file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM