C++ Coverage on Linux is broken
ATTENTION! Please read and follow:
- if this is a question about how to build / test / query / deploy using Bazel, or a discussion starter, send it to [email protected]
- if this is a bug or feature request, fill the form below as best as you can.
Description of the problem / feature request:
When I execute the bazel coverage command with version 0.24.1, I can generate a valid coverage.dat file, but when using a version higher than 0.24.1, the coverage.dat file is empty. This problem exists only when generating coverage for the C++ language.
$ ll bazel-testlogs/id_test/ total 3136 drwxr-xr-x 2 admin admin 4096 Sep 19 15:29 ./ drwxr-xr-x 3 admin admin 4096 Sep 19 15:07 ../ -r-xr-xr-x 1 admin admin 581600 Sep 19 15:07 baseline_coverage.dat* -r-xr-xr-x 1 admin admin 68477 Sep 19 15:29 coverage.dat* -r-xr-xr-x 1 admin admin 179 Sep 19 15:29 test.cache_status* -r-xr-xr-x 1 admin admin 2539566 Sep 19 15:29 test.log* -rw-r--r-- 1 admin admin 904 Sep 19 15:28 test.xml $ bazel version Build label: 0.24.1 Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Tue Apr 2 16:29:26 2019 (1554222566) Build timestamp: 1554222566 Build timestamp as int: 1554222566
$ ll bazel-testlogs/id_test/ total 4108 drwxr-xr-x 2 admin admin 4096 Sep 19 15:25 ./ drwxr-xr-x 3 admin admin 4096 Sep 19 15:07 ../ -r-xr-xr-x 1 admin admin 581600 Sep 19 15:07 baseline_coverage.dat* -r-xr-xr-x 1 admin admin 0 Sep 19 15:25 coverage.dat* -r-xr-xr-x 1 admin admin 176 Sep 19 15:25 test.cache_status* -r-xr-xr-x 1 admin admin 3600923 Sep 19 15:25 test.log* -rw-r--r-- 1 admin admin 904 Sep 19 15:25 test.xml $ bazel version Build label: 0.25.0 Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Wed May 1 21:45:01 2019 (1556747101) Build timestamp: 1556747101 Build timestamp as int: 1556747101
Replace this line with your answer.
Feature requests: what underlying problem are you trying to solve with this feature?
Replace this line with your answer.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Replace this line with your answer.
What operating system are you running Bazel on?
Replace this line with your answer.
What's the output of bazel info release?
Replace this line with your answer.
If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.
Replace this line with your answer.
What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
Replace this line with your answer.
Have you found anything relevant by searching the web?
Replace these lines with your answer.
Places to look:
- StackOverflow: http://stackoverflow.com/questions/tagged/bazel
- GitHub issues: https://github.com/bazelbuild/bazel/issues
- email threads on https://groups.google.com/forum/#!forum/bazel-discuss
Any other information, logs, or outputs that you want to share?
Replace these lines with your answer.
If the files are large, upload as attachment or provide link.
I have a similar problem.
Try to run this script in an empty directory:
echo -n > WORKSPACE
echo 'cc_test(name = "foo_test", srcs = ["main.cpp"])' > BUILD
echo 'int main() {}' > main.cpp
bazel coverage //:foo_test --instrument_test_targets
tail -n 1 bazel-testlogs/foo_test/test.log
On my PC, the script above prints the following log:
INFO: Using default value for --instrumentation_filter: "//".
INFO: Override the above default with --instrumentation_filter
INFO: Analyzed target //:foo_test (21 packages loaded, 478 targets configured).
INFO: Found 1 test target...
Target //:foo_test up-to-date:
bazel-bin/foo_test
INFO: Elapsed time: 2.936s, Critical Path: 2.70s
INFO: 7 processes: 6 linux-sandbox, 1 worker.
INFO: Build completed successfully, 15 total actions
//:foo_test PASSED in 0.2s
Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 15 total actions
WARNING: There was no coverage found.
Note that the last line says there was no coverage.
My environment:
- OS: Arch Linux
- Bazel version: 0.29.1
- GCC version: 9.1.0
All versions larger than 0.24.1 have this problem. My environment: OS: GNU/Linux Bazel version: larger than 0.24.1 GCC version: 4.9.2
It seems that in GCC 9.1.0, the meaning of the -i flag of gcov has changed:
- https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Invoking-Gcov.html
- https://gcc.gnu.org/onlinedocs/gcc-9.1.0/gcc/Invoking-Gcov.html
Instead of generating a “.gcov” file, a “.gcov.json.gz” file is generated. This change may cause my bazel failing to collect coverage data.
I also tested GCC 5.4.0, and noticed that the gcov log doesn’t contain “Creating” text so the following grep command will fail:
https://github.com/bazelbuild/bazel/blob/6193cfd60b5c16d12fab7f280460d611d45ff041/tools/test/collect_cc_coverage.sh#L129
So for now, I see two problems:
-
If the version of GCC is greater than or equal to 5.4, the output of executing
gcovdoes not contain “Creating” text, so this line should be updated:https://github.com/bazelbuild/bazel/blob/6193cfd60b5c16d12fab7f280460d611d45ff041/tools/test/collect_cc_coverage.sh#L129
-
If the version of GCC is greater than or equal to 9.1, the meaning of
-iflag ofgcovhas changed, instead of generating a “.gov” file, a “.gcov.json.gz” file is generated. So the collecting logic should be updated as well.
@EFanZh, Have you tried gcc version 4.9.2? I am using this version with bazel 0.25.0 to generate an empty coverage.dat file.
No, I haven’t tried GCC 4.9.2 or Bazel 0.25.0. But you can find the files matching “*.gcov.log” in Bazel cache directory, and see their content. If there is no “Creating” text, then Bazel cannot generate coverage reports.
I can't find any files mathes “.gcov.log” or ".gcov" in Basel cache directory. All versions larger than 0.24.1 are the same problem. If you are convenient, you can try gcc 4.9.2 with bazel 0.29.1 version.
Is there a “test.log” file in your “bazel-testlogs” directory?
Yes, there is a "test.log" file and there is "creating" text in the file. But the "coverage.dat" file is empty, when generated coverage with bazel version higher than 0.24.1.
$ ll bazel-testlogs/id_test/ total 4068 drwxr-xr-x 2 admin admin 4096 Sep 23 11:39 ./ drwxr-xr-x 4 admin admin 4096 Sep 20 20:34 ../ -r-xr-xr-x 1 admin admin 581600 Sep 19 15:07 baseline_coverage.dat* -r-xr-xr-x 1 admin admin 0 Sep 23 11:38 coverage.dat* -r-xr-xr-x 1 admin admin 176 Sep 23 11:39 test.cache_status* -r-xr-xr-x 1 admin admin 3563900 Sep 23 11:39 test.log* -rw-r--r-- 1 admin admin 912 Sep 23 11:38 test.xml
Some logs are as follows:
- grep Creating
- cut '-d'''' -f2
- read gcov_file
- cut -d ' ' -f 2
- read gcno_path ++ dirname bazel-out/k8-opt/bin/_objs/id_test/id_test.pic.gcno ++ basename bazel-out/k8-opt/bin/_objs/id_test/id_test.pic.gcno .gcno
- local gcda=/home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/id_test/id_test.pic.gcda
- [[ -f /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/id_test/id_test.pic.gcda ]]
- read gcno_path ++ dirname bazel-out/k8-opt/bin/_objs/ray_common/client_connection.gcno ++ basename bazel-out/k8-opt/bin/_objs/ray_common/client_connection.gcno .gcno
- local gcda=/home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.gcda
- [[ -f /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.gcda ]]
- read gcno_path ++ dirname bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno ++ basename bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno .gcno
- local gcda=/home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcda
- [[ -f /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcda ]]
- '[' '!' -f /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno ']' ++ dirname bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno
- mkdir -p /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common
- cp /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcno ++ dirname /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcda
- /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/gcov -i -o /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/bazel-out/k8-opt/bin/_objs/ray_common/client_connection.pic.gcda
- cat /home/admin/.cache/bazel/_bazel_admin/9386c25d2bda9cfe2c78d99fea7976b6/sandbox/processwrapper-sandbox/1/execroot/com_github_ray_project_ray/_coverage/id_test/test/_cc_coverage.gcov.gcov.log
- cut -d ' ' -f 2
- read gcov_file
- cut '-d'''' -f2
- grep Creating
- read gcno_path
The coverage tests are run in a sandbox environment. Add “--sandbox_debug” to the command line that runs the coverage test, so that the log files are kept in its original position.
Using this parameter does not work either. The generated coverage files are empty whether in a sandbox or standalone environment. You can try to collect c++ language coverage in gcc 4.9.2 and bazel 0.29.1 environments to see if the generated coverage.dat file is empty.
That flag is for debugging. It won’t affect the outcome. Now you should be able to find “*.gcov.log” files in your Bazel cache after adding the flag.
Even with this parameter, no ".gcov.log" file is generated by converage command in the bazel cache dir. find ./bazel-ray/ -name ".gcov.log"
Try this command:
find "$(bazel info output_base)" -name '*.gcov.log'
With this command, i find the *.gcov.log file and there is not "creating" text in the file.
@ishikhman If it is determined that this is a bug, then when will it be possible to solve this problem? Because we are now generating c++ coverage for the project, but the bazel version we are using now is 0.26.1.
If it is determined that this is a bug, then when will it be possible to solve this problem? Because we are now generating c++ coverage for the project, but the bazel version we are using now is 0.26.1.
@hlopko could you please help @ruifangChen ? Thanks!
0.25 0.26 0.28, all of these versions have the same problem
0.25 0.26 0.28, all of these versions have the same problem
As well as 0.29.1
@hlopko Hi, could you give me some help? How to get C++ coverage with bazel 0.26.1 and gcc 4.9.2. Thanks very much!