ERROR while code coverage report using lcov

北慕城南 提交于 2019-12-01 10:52:48

Does it help if you use absolute paths instead of relative paths when passing files to lcov?

I ran into a similiar problem where lcov also failed to write the file. Not sure if it is a bug in lcov, but the problem was that it got confused with relative paths:

lcov -a test_fast_cxxtest_gcov__base.info -a test_fast_cxxtest_gcov__test.info \
     -o test_fast_cxxtest_gcov__total.info
Combining tracefiles.
Reading tracefile test_fast_cxxtest_gcov__base.info
Reading tracefile test_fast_cxxtest_gcov__test.info
lcov: WARNING: function data mismatch at /home/phil/ghost/constants.h:1862
Writing data to test_fast_cxxtest_gcov__total.info
lcov: ERROR: cannot write to test_fast_cxxtest_gcov__total.info!

Running it with strace revealed that it executes chdir("/") on several locations, which changes the working directory to /. That explains why it cannot write the file.

One workaround is to use absolute paths. For instance, if you are using GNU make, you can use the abspath command:

lcov -a $(abspath test_fast_cxxtest_gcov__base.info) \
     -a $(abspath test_fast_cxxtest_gcov__test.info) \
     -o $(abspath test_fast_cxxtest_gcov__total.info)

After that change, it was finally able to write the file.

(Other options like trying to set the directories using the --base-directory or --directory option did not have an effect, as far as I saw. The version of lcov that I tested with is 1.12.)

The problem is not limited to Ubuntu, as I ran into it on Arch Linux. It could be a regression introduced in 1.12, however, so I reported it (see issue #77630).

Update: Lcov is not part of GCC, so my original bug report was closed, but I got an answer from the Lcov mailing list. The problem is already fixed in commit 632c25. Users of Arch Linux based distros can try the latest snapshot with aur/lcov-git.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!