bazel: 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 bazel-discuss@googlegroups.com
  • 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:

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.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 46 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Really appreciate a fix here.

Not working on either Linux or Mac with Bazel 3.0.0.

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

GCC 9.2.1 and bazel 3.3.1 is still not working. Got zero-sized coverage.dat.
Thank you for the fix! @helaan Do I use the right version?

bazel version
Build label: 3.3.1
Build target: bazel-out/k8-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Jun 30 15:09:23 2020 (1593529763)
Build timestamp: 1593529763
Build timestamp as int: 1593529763
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --disable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --without-isl --enable-gnu-indirect-function --enable-cet=auto --with-tune=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.2.1 20190812 (Alibaba 9.2.1-2 2.17) (GCC) 
bazel coverage //...
INFO: Using default value for --instrumentation_filter: "//".
INFO: Override the above default with --instrumentation_filter
INFO: Analyzed 3 targets (22 packages loaded, 561 targets configured).
INFO: Found 1 target and 2 test targets...
INFO: Elapsed time: 11.613s, Critical Path: 6.69s
INFO: 27 processes: 26 processwrapper-sandbox, 1 worker.
INFO: Build completed successfully, 49 total actions
//:function_1_test                                                       PASSED in 1.1s
//:function_2_test                                                       PASSED in 1.1s

Executed 2 out of 2 tests: 2 tests pass.
INFO: Build completed successfully, 49 total actions
find bazel-testlogs/ -name coverage.dat | xargs  ls -laa
-r-xr-xr-x 1 root root 0 Jul  2 21:43 bazel-testlogs/function_1_test/coverage.dat
-r-xr-xr-x 1 root root 0 Jul  2 21:43 bazel-testlogs/function_2_test/coverage.dat