bazelbuild / bazelbuild/bazel

llvm-cov coverage not reporting coverage for header files in the .dat file

Open
#19,338 8 comments 0 reactions 0 assignees View on GitHub
coverage P2 team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

Hi,

We are testing out "llvm-cov gcov" coverage (i.e. NOT LLVM Source-Based Coverage) and observe that the output .dat file does not contain coverage information for header files, only for source files. This does not happen with the regular GCC gcov coverage. llvm-cov should in theory be a "drop-in" replacement for gcov.

Here's a detailed description of a minimal test:

Bazel flags:
```
coverage --combined_report=lcov
coverage --experimental_generate_llvm_lcov
```

Toolchain setup:
```
tool_path(
name = "gcov",
path = "/usr/bin/llvm-cov",
),
```

Code:

```
// foo.h
int foo()
{
return 0;
}
```
```
// foo_test.cpp
#include "foo.h"

int main()
{
return foo();
}
```

```
// BUILD.bazel
cc_library(
name = "foo",
hdrs = ["foo.h"],
)

cc_test(
name = "foo_test",
srcs = ["foo_test.cpp"],
deps = [":foo"],
)
```

Following the verbose coverage log, we can see that the `llvm-cov` call works fine and produces a `.gcda.gcov` file that contains coverage information about the code in a header file:

```
file:./foo.h
function:1,1,_Z3foov
lcount:1,1
lcount:3,1
file:foo_test.cpp
function:3,1,main
lcount:3,1
lcount:5,
```

Comparing the verbose logs, I do find one difference:

- For the GCC version, the path to the header file does **not** start with dot-slash (`./`):
```
File 'foo.h'
Lines executed:100.00% of 2
```
- For the LLVM version, the path to the header starts with dot-slash:
```
File './foo.h'
Lines executed:100.00% of 2
```

Is it possible that Bazel's Java LCOV implementation cannot handle files starting with `./`?

Thanks!

### Which category does this issue belong to?

_No response_

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

See above

### Which operating system are you running Bazel on?

Ubuntu 20.04

### What is the output of `bazel info release`?

release 6.3.2

### 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 master; git rev-parse HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_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_

Contributor guide

Open the contributing guide

Research direction

Reproduce the report with the supplied Bazel coverage flags and the minimal foo.h, foo_test.cpp, and BUILD.bazel files. Compare the llvm-cov .gcda.gcov output with the generated .dat file, focusing on the differing ./foo.h path and the Bazel Java LCOV implementation. Done means header-file coverage appears in the .dat output as it does for source files.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, java
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.