generating branch coverage data for lcov

时光总嘲笑我的痴心妄想 提交于 2019-11-30 03:24:57
Paul Rutland

The latest version of LCOV disabled branch coverage by default.

You need to re-enable it by either:

  • editing your ~/.lcovrc file (copied from /etc/lcovrc) to change lcov_branch_coverage setting to 1
  • adding --rc lcov_branch_coverage=1 to your lcov command lines

.lcovrc files is file of settings that need to place in path of lcov file. Frankly, I didn't research much on use of this file.

You need to add additional parameter as "--rc lcov_branch_coverage=1" to lcov for all calls. In your case add this parameter to all your three calls. If you miss one, it will drop branch coverage.

Also --branch-coverage is needed for genhtml.

Sorry, not so much an "idea" as a confirmation that you're doing everything correctly. Your exact commands worked on this simple code:

#include <iostream>
using namespace std;

bool foo(int i)
{
    if (i != 0) {
        return 12 / i;
    } else {
        return 0;
    }
}

int main(int argc, char** argv)
{
    cout << foo(argc) << endl;
    return 0;
}

The lcov coverage table has statistics for Lines, Functions, and Branches. Maybe double-check that you're actually looking at the correct output HTML?

MikeF

based on this post, the difference may depend on the version of gcc you are using. Can you share which versions you are using. I am not getting branch coverage on:

 i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!