Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover mode is incorrect in the coverage data file when enabling -race mode #3018

Closed
lbcjbb opened this issue Nov 28, 2021 · 0 comments · Fixed by #3019
Closed

Cover mode is incorrect in the coverage data file when enabling -race mode #3018

lbcjbb opened this issue Nov 28, 2021 · 0 comments · Fixed by #3019

Comments

@lbcjbb
Copy link
Contributor

lbcjbb commented Nov 28, 2021

What version of rules_go are you using?

v0.29.0

What version of gazelle are you using?

v0.24.0

What version of Bazel are you using?

v4.2.1

Does this issue reproduce with the latest releases of all the above?

Yes. This issue is reproduced with the HEAD of the master branch of rules_go (aaf48cb, 2021/11/12).
No direct correlation with Gazelle and Bazel.

What operating system and processor architecture are you using?

Linux / amd64

Any other potentially useful information about your toolchain?

Tested with local Go toolchain, and 1.17.3 Go toolchain.

What did you do?

Run coverage of a minimal Go test with -race mode.

  • foobar/foobar.go:
package foobar

func foo() {
	_ = "foo"
}
  • foobar/foobar_test.go:
package foobar

import "testing"

func TestCoverMode(t *testing.T) {
	foo()
}
  • foobar/BUILD.bazel:
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
    name = "foobar",
    srcs = ["foobar.go"],
    importpath = "example.com/foobar",
    visibility = ["//visibility:public"],
)

go_test(
    name = "foobar_test",
    srcs = ["foobar_test.go"],
    embed = [":foobar"],
)

And execute the command:

bazel coverage --@io_bazel_rules_go//go/config:race //foobar:all

What did you expect to see?

$ bazel coverage --@io_bazel_rules_go//go/config:race //foobar:all
...
//foobar:foobar_test                                                     PASSED in 0.1s
  .../bazel-out/k8-fastbuild/testlogs/foobar/foobar_test/coverage.dat

Executed 1 out of 1 test: 1 test passes.

$ cat .../bazel-out/k8-fastbuild/testlogs/foobar/foobar_test/coverage.dat
mode: atomic
github.mpi-internal.com/leboncoin/go/foobar/foobar.go:3.12,5.2 1 1

What did you see instead?

$ cat .../bazel-out/k8-fastbuild/testlogs/foobar/foobar_test/coverage.dat
mode: set
github.mpi-internal.com/leboncoin/go/foobar/foobar.go:3.12,5.2 1 1

The cover mode in the coverage data file should be atomic, according with the argument given of the cover command of the builder. Since #2502 the coverage data is collected with the mode atomic when the race detection is enabled.
The coverage data file should specify the correct mode. It's necessary to merge all report data files with the correct aggregation function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant