bazelbuild / bazel

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

Questions: Failed to generate .gcda file with bazel coverage in ubuntu #20041

Open bmeoaountiful opened 10 months ago

bmeoaountiful commented 10 months ago

I am doing some coverage test on xla project. The result shows test command runs successfully, and coverage files(*.gcno) are generat. but no runtime .gcda file generate,

bazel coverage --config=cuda --copt=-w --jobs=48 -k --experimental_cc_coverage --combined_report=lcov --instrumentation_filter=xla/service/* --instrument_test_targets  -- //xla/service/...

I am using bazel 6.1.0. os Ubuntu20.04 Does any one know how to resolve this?

c-mita commented 10 months ago

What are you observing? Is the output coverage.dat file empty?

Bazel does not normally track the .gcda files after test execution; the .gcda files are not part of the official coverage output. But you can force it to output everything into a directory under bazel-testlogs with --experimental_fetch_all_coverage_outputs

bazel coverage --experimental_fetch_all_coverage_outputs //foo:bar
$ find bazel-testlogs/foo/bar/_coverage
[gcno, files gcda files, and other files]
geckert-dev commented 10 months ago

I have been looking for a way to get the .gcna files for months. It seemed as if bazel was "eating" the .gcda and .gcov.json.gz files (because the .gcno files were sitting in the _objs directories, right where they should be.

THANK YOU!!!

bmeoaountiful commented 10 months ago

experimental_fetch_all_coverage_outputs

yes, the output coverage.data is empty. and there is no .gcda file when bazel coverage with --experimental_fetch_all_coverage_outputs.

c-mita commented 10 months ago

A few questions:

ivanhoe89 commented 2 months ago

@bmeoaountiful Without knowing your application I would check how your application shuts down. If its not a graceful shutdown (like you kill your application) it happens that gcov (maybe other coverage tool) can not flush coverage point hits.

By the way, in C/C++ you can do a manual flush in the code directly with:

extern "C" void __gcov_flush(); //I think this become depracted in later versions and you may have to use __gcov_dump()...

To avoid putting this function call in production code I suggest to put the call behind compile switch.