4

I'm trying to collect code coverage for the project that has c++ and c code both on Ubuntu.

I use '-fprofile-arcs' and '-ftest-coverage' values as CXXFLAGS and CFLAGS; '-lgcov' as LINKFLAGS.

Common C project structure is:

c_code\
     src
     unit_tests

src contains sources of static library.

unit_tests dir contain tests written with googletest framework e. g. tests of kind

TEST_F(test_case_name, test_name) {
    some_gtest_assertions;
}

After the build googletest binary that should contain static library to test inside of it is launched.

Building and running of the project binaries results in generating of *.gcno and *.gcda files. However my C coverage results are empty (C++ is generated well).

lcov command has the folloiwng format:

lcov --capture --directory my_c_gcda_location --output-file c_coverage.info

Logs of lcov show the following for C-related gcda files:

gcov did not create any files for "my_c_gcda_location/*.gcda"`

There are also errors of kind:

*.gcda:stamp mismatch with notes file

Should I specify some additional parameters or perform some additional actions to get coverage results for C? Or what can be the reason of these issues?

4

1 回答 1

6

当 .gcda 文件比 .gcno 文件新时,您可能会遇到“戳记不匹配”。

发生这种情况主要有两个原因: 1. 您可能在运行测试之后和生成跟踪文件之前重新构建了代码。2. 二进制文件可能是在一台机器上构建的,而测试是在另一台机器上运行的,它的时间领先于构建机器。

对于这两种情况,您只需确保 .gcda 的文件创建时间大于 .gcno 和 .c* 文件。

您可以通过执行“touch *.gcda”然后运行 ​​lcov 命令来做到这一点。

于 2015-05-04T13:48:10.977 回答