我最近升级了我的工具链,这导致gcovr
无法生成任何覆盖率输出。有人能告诉我这是gcovr的问题,还是我的工具链,或者缺少依赖项?
以下是我用来验证的示例/比较:
example.cpp
// Taken from gcovr user guide.
// example.cpp
int foo(int param)
{
if (param)
{
return 1;
}
else
{
return 0;
}
}
int main(int argc, char* argv[])
{
foo(0);
return 0;
}
gcovr
版本:
gcovr 6.0
Copyright (c) 2013-2023 the gcovr authors
Copyright (c) 2013 Sandia Corporation.
Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
the U.S. Government retains certain rights in this software.
使用g++
版本时:
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我得到正确的结果:
$ g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
$ ./program
$ gcovr
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
example.cpp 7 6 85% 7
------------------------------------------------------------------------------
TOTAL 7 6 85%
------------------------------------------------------------------------------
但是,当使用更新的版本12工具链时:
g++-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0
Copyright (C) 2022 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我得到以下结果:
$ g++-12 -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
$ ./program
$ gcovr
(ERROR) Trouble processing '/home/janjaap/workspace/testgcovr/program-example.gcda' with working directory '/home/janjaap/workspace/testgcovr'.
Stdout of gcov was >>None<< End of stdout
Stderr of gcov was >>None<< End of stderr
Current processed gcov file was None.
Use option --verbose to get extended informations.
Traceback (most recent call last):
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
work(*args, **kwargs)
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
done = run_gcov_and_process_files(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
out, err = gcov_cmd.run_with_args(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).
Traceback (most recent call last):
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
work(*args, **kwargs)
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
done = run_gcov_and_process_files(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
out, err = gcov_cmd.run_with_args(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).
(ERROR) Uncaught EXCEPTION
Traceback (most recent call last):
File "/home/janjaap/.local/bin/gcovr", line 8, in <module>
sys.exit(main())
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 328, in main
covdata = collect_coverage_from_gcov(options)
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 380, in collect_coverage_from_gcov
with Workers(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 173, in __exit__
self.wait()
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 164, in wait
raise self.exceptions[0][1]
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/__main__.py", line 387, in collect_coverage_from_gcov
contexts = pool.wait()
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 164, in wait
raise self.exceptions[0][1]
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/workers.py", line 80, in worker
work(*args, **kwargs)
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 323, in process_datafile
done = run_gcov_and_process_files(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 536, in run_gcov_and_process_files
out, err = gcov_cmd.run_with_args(
File "/home/janjaap/.local/lib/python3.10/site-packages/gcovr/gcov.py", line 515, in run_with_args
raise RuntimeError(
RuntimeError: GCOV returncode was -11 (exited by signal).
1条答案
按热度按时间laximzn51#
当您使用系统默认的
gcc
/g++
以外的编译器运行gcovr时,您必须告诉它使用哪个gcov
工具。由于二进制覆盖率数据格式在编译器版本之间会发生变化,因此必须使用匹配的gcov
。在这里,您使用的是
g++-12
。对应的gcov可能被称为gcov-12
。您可以通过--gcov-executable
选项告诉gcovr使用此选项。进一步阅读:* 在gcovr文档中选择正确的Gcov可执行文件 *。