bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
22.98k stars 4.03k forks source link

Bazel coverage `collect_coverage.sh` Segmentation fault #23476

Open kwhitehouse opened 2 weeks ago

kwhitehouse commented 2 weeks ago

Description of the bug:

Background

I'm trying to generate code coverage using Bazel for a cc_test.

Details

When I run the following command, all my tests pass.

bazel test ... --test_output=all

When I attempt to generate coverage results by adding the flags --collect_code_coverage --combined_report=lcov, I see a failure to generate coverage.

bazel test ... --test_output=all --collect_code_coverage --combined_report=lcov

The error unfortunately doesn't give a ton of details - it just indicates a segmentation fault somewhere in collect_coverage.sh.

  1 exec ${PAGER:-/usr/bin/less} "$0" || exit 1
  2 Executing tests from //helloworld:my_test
  3 -----------------------------------------------------------------------------
  4 Running main() from gmock_main.cc
  5 [==========] Running 1 test from 1 test suite.
  6 [----------] Global test environment set-up.
  7 [----------] 1 test from MyTest
  8 [ RUN      ] MyTest.HelloWorld
  9 [       OK ] MyTest.HelloWorld (0 ms)
 10 [----------] 1 test from CheckTest (0 ms total)
 11 
 12 [----------] Global test environment tear-down
 13 [==========] 1 test from 1 test suite ran. (0 ms total)
 14 [  PASSED  ] 1 test.
 15 external/bazel_tools/tools/test/collect_coverage.sh: line 166: 39492 Segmentation fault: 11  "$@"

Which category does this issue belong to?

C++ Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

No response

Which operating system are you running Bazel on?

I get the same outcome when running my tests on macOS and on Linux

What is the output of bazel info release?

release 7.3.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

comius commented 1 week ago

cc @c-mita

c-mita commented 1 week ago

It looks like your test executable is segfaulting after running the tests.

What happens if you build your test program with --collect_code_coverage and the execute it?

bazel build --collect_code_coverage --instrumentation_filter=".*" //helloworld:my_test
./bazel-bin/helloworld/my_test