coverage is empty

917 views
Skip to first unread message

futuret...@gmail.com

unread,
Jul 26, 2019, 8:38:11 PM7/26/19
to bazel-discuss
Can you guys help a former Googler,  I have been trying to generate coverage report with bazel and no matter what I do, the coverage rerport (coverage.dat) remains completely empty (size of file is zero). There are some errors in the logs which I don't know how to fix.

These are the list of steps I have taken so far after installing bazel
1. Download google c++ open source project and run bazel coverage on their tests
2. Defining my own basic project, following is the only function in the lib I am defining and the test function

int ComputePower(int x, int y) {
  if (y < 0) {
std::cout<<"The y is below zero";
std::cout<<"some more lines for testing bazel coverage";
return 0;
  } else {
int result = 1;
for (int i=0; i< y; i++) {
result *= x;
}
return result;
  }
}

and the test is 

TEST(message_test,content) {
  int x = 2;
  int y = 3;
  EXPECT_EQ(ComputePower(x,y),8);
}
my build file for the package is 
cc_library(
    name = "mylib",
    hdrs = ["mylib.h"],
    srcs = ["mylib.cc"],
)


cc_test(
    name = "mytest",
    srcs = ["mytest.cc"],
    deps = [
"@googletest//:gtest_main",
"mylib",
],
)
and my WORKSPACE is 

workspace(
    name = "mywork",
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

git_repository(
    name = "googletest",
    tag = "release-1.8.1",
)

Noo matter what I do, the coverage.dat always is empty, I have tried multiple flags but nothing seems to work

My bazel is release 0.28.0
my gcov is 5.4.0 20160609 and its on ubuntu 16.04.11


And last, the test log is 

exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //xx:mytest
-----------------------------------------------------------------------------
+ [[ -z bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files ]]
+ export ROOT=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot
+ ROOT=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot
+ [[ bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files != /* ]]
+ export COVERAGE_MANIFEST=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files
+ COVERAGE_MANIFEST=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files
+ export COVERAGE_DIR=_coverage/xx/mytest/test
+ COVERAGE_DIR=_coverage/xx/mytest/test
+ [[ _coverage/xx/mytest/test == /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot* ]]
+ COVERAGE_DIR=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test
+ mkdir -p /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test
+ COVERAGE_OUTPUT_FILE=bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat
+ [[ bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat == /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot* ]]
+ COVERAGE_OUTPUT_FILE=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat
+ export JAVA_COVERAGE_FILE=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/jvcov.dat
+ JAVA_COVERAGE_FILE=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/jvcov.dat
+ export COVERAGE=1
+ COVERAGE=1
+ export BULK_COVERAGE_RUN=1
+ BULK_COVERAGE_RUN=1
+ for name in '"$LCOV_MERGER"'
+ [[ ! -e bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main ]]
+ export GCOV_PREFIX_STRIP=3
+ GCOV_PREFIX_STRIP=3
+ export GCOV_PREFIX=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test
+ GCOV_PREFIX=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test
+ export LLVM_PROFILE_FILE=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/%h-%p-%m.profraw
+ LLVM_PROFILE_FILE=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/%h-%p-%m.profraw
+ [[ ! -z '' ]]
+ cd /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.runfiles/xpilot
+ /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.runfiles/xpilot/xx/mytest
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from message_test
[ RUN      ] message_test.content
[       OK ] message_test.content (0 ms)
[----------] 1 test from message_test (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[  PASSED  ] 1 test.
+ TEST_STATUS=0
+ touch /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat
+ [[ 0 -ne 0 ]]
+ cd /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot
+ [[ -n external/bazel_tools/tools/test/collect_cc_coverage.sh ]]
+ eval external/bazel_tools/tools/test/collect_cc_coverage.sh
++ external/bazel_tools/tools/test/collect_cc_coverage.sh
+ main
+ init_gcov
+ GCOV=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/gcov
+ ln -s /usr/bin/gcov /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/gcov
+ uses_llvm
+ stat '/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/*.profraw'
+ return 1
+ case "$BAZEL_CC_COVERAGE_TOOL" in
+ gcov_coverage /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/_cc_coverage.gcov
+ local output_file=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/_cc_coverage.gcov
+ shift
+ local gcov_log=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/_cc_coverage.gcov.gcov.log
+ read -r line
+ [[ gcno == \g\c\n\o ]]
+ gcno_path=bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno
++ dirname bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno
++ basename bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno .gcno
+ local gcda=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcda
+ [[ -f /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcda ]]
+ '[' '!' -f /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno ']'
++ dirname bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno
+ mkdir -p /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib
+ cp /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcno
++ dirname /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcda
+ /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/gcov -i -o /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mylib/mylib.pic.gcda
+ cat /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/_cc_coverage.gcov.gcov.log
+ grep Creating
+ cut -d ' ' -f 2
+ cut '-d'\''' -f2
+ read gcov_file
+ read -r line
+ [[ gcno == \g\c\n\o ]]
+ gcno_path=bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno
++ dirname bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno
++ basename bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno .gcno
+ local gcda=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcda
+ [[ -f /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcda ]]
+ '[' '!' -f /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno ']'
++ dirname bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno
+ mkdir -p /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest
+ cp /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcno
++ dirname /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcda
+ /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/gcov -i -o /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/bazel-out/k8-fastbuild/bin/xx/_objs/mytest/mytest.pic.gcda
+ cat /home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test/_cc_coverage.gcov.gcov.log
+ grep Creating
+ cut -d ' ' -f 2
+ cut '-d'\''' -f2
+ read gcov_file
+ read -r line
+ [[ b.cc == \g\c\n\o ]]
+ read -r line
+ [[ ib.h == \g\c\n\o ]]
+ read -r line
+ LCOV_MERGER_CMD='bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main --coverage_dir=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test   --output_file=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat   --filter_sources=/usr/bin/.+   --filter_sources=/usr/lib/.+   --filter_sources=/usr/include.+   --filter_sources=.*external/.+   --source_file_manifest=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files'
+ [[ -n '' ]]
+ [[ -n '' ]]
+ JAVA_RUNFILES=
+ exec bazel-out/k8-fastbuild/bin/external/bazel_tools/tools/test/CoverageOutputGenerator/java/com/google/devtools/coverageoutputgenerator/Main --coverage_dir=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/_coverage/xx/mytest/test --output_file=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/testlogs/xx/mytest/coverage.dat --filter_sources=/usr/bin/.+ --filter_sources=/usr/lib/.+ --filter_sources=/usr/include.+ '--filter_sources=.*external/.+' --source_file_manifest=/home/navid/.cache/bazel/_bazel_navid/7bcadf9ea2f71e1391f7e750aaf6b42e/sandbox/linux-sandbox/25/execroot/xpilot/bazel-out/k8-fastbuild/bin/xx/mytest.instrumented_files
Jul 27, 2019 12:35:26 AM com.google.devtools.coverageoutputgenerator.Main getTracefiles
INFO: No lcov file found.
Jul 27, 2019 12:35:26 AM com.google.devtools.coverageoutputgenerator.Main getGcovInfoFiles
INFO: No gcov info file found.
Jul 27, 2019 12:35:26 AM com.google.devtools.coverageoutputgenerator.Main getProfdataFileOrNull
INFO: No .profdata file found.
Jul 27, 2019 12:35:26 AM com.google.devtools.coverageoutputgenerator.Main main
WARNING: There was no coverage found.











Andreas Ames

unread,
Jul 29, 2019, 5:58:18 AM7/29/19
to futuret...@gmail.com, bazel-discuss
I had to use the the "--instrumentation_filter" option to get coverage data, in your case maybe something like "--instrumentation_filter=//:mylib".


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/8fcf718e-9efc-43fb-8593-b0aa0508beb8%40googlegroups.com.

futuret...@gmail.com

unread,
Jul 31, 2019, 9:28:58 PM7/31/19
to bazel-discuss
Thanks Andreas

It didn't really make a different, I used the instrumentation_filter and I still get completely empty coverage report. 

More info, I have been using a clean linux installation in a virtual machine, I install linux, install git, install bazel and java and there is nothing else on the machine. No matter what I do, coverage report remains empty.

I also tried compiling with clang, I added toolchain defined in https://github.com/grailbio/bazel-toolchain and I added it to my workspace (I found in one of the bazel-tool scripts, collect_cc_coverage.sh) that the code path for llvm compilers is different, still nothing. The coverage report remains empty.

Any help anyone?


On Monday, July 29, 2019 at 2:58:18 AM UTC-7, Andreas Ames wrote:
I had to use the the "--instrumentation_filter" option to get coverage data, in your case maybe something like "--instrumentation_filter=//:mylib".


To unsubscribe from this group and stop receiving emails from it, send an email to bazel-...@googlegroups.com.

Paul Johnston

unread,
Aug 17, 2019, 5:05:02 PM8/17/19
to bazel-discuss
One idea: try generating coverage reports for abseil-cpp (these should definitely work) and compare what's happening in your repo.
Reply all
Reply to author
Forward
0 new messages