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

cmd/cover: Some code are missed by Go coverage profile #59563

Closed
rumtid opened this issue Apr 12, 2023 · 7 comments
Closed

cmd/cover: Some code are missed by Go coverage profile #59563

rumtid opened this issue Apr 12, 2023 · 7 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.

Comments

@rumtid
Copy link

rumtid commented Apr 12, 2023

What version of Go are you using (go version)?

$ go version
go version go1.20.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes. Also, go1.19.8 works fine.

What operating system and processor architecture are you using (go env)?

darwin, amd64

What did you do?

Run:

$ git clone https://github.com/rumtid/parser.git
$ cd parser

$ /usr/local/go/bin/go test -timeout 30s -coverprofile=/var/folders/ry/vp2b73b17vq3_w50fsqt1xp80000gn/T/vscode-goaU9l71/go-code-cover -run ^TestMe$ github.com/rumtid/parser -coverpkg=all

What did you expect to see?

The coverage profile marks some covered lines in yyParse().

What did you see instead?

Despite yyParse() is invoked, it is not covered according to the profile.

@rumtid rumtid changed the title Some code are missed by Go coverage profile cmd/cover: Some code are missed by Go coverage profile Apr 12, 2023
@ianlancetaylor
Copy link
Contributor

CC @thanm

@thanm
Copy link
Contributor

thanm commented Apr 12, 2023

Thanks for the report. I will take a look.

@thanm
Copy link
Contributor

thanm commented Apr 13, 2023

OK, I think I see what's going on here. I will send a fix shortly.

What's happening here is a side effect of -coverpkg=all, in which we gather coverage data from everything, including the Go runtime and a lot of other low-level packages. This in turn means that the underlying coverage counters can be changing even as the data is being written out, which is the source of this particular bug.

As a workaround, I recommend picking out just the packages that you are actually interested in and passing those to -coverpkg; doing that won't expose you to this particular problem.

@dr2chase dr2chase added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 13, 2023
@gopherbot
Copy link

Change https://go.dev/cl/484535 mentions this issue: coverage: fix count vs emit discrepancy in coverage counter data writing

@rumtid
Copy link
Author

rumtid commented Apr 14, 2023

I see, thanks a lot.

@gopherbot
Copy link

Change https://go.dev/cl/492175 mentions this issue: runtime/coverage: fix problematic test from issue 59563

gopherbot pushed a commit that referenced this issue May 3, 2023
Fix up the coverage testpoint TestIssue59563TruncatedCoverPkgAll
to avoid spurious failures due to racy behavior. Specifically,
we are only interested in verifying coverage for the larger
function of the two in the test package (the smaller one is only
there to trigger additional function registrations while the
test is finalizing the cov data).

Updates #59867.
Updates #59563.

Change-Id: Ibfbbcbf68e0ad7a4d9606cbcfc69d140375c7b87
Reviewed-on: https://go-review.googlesource.com/c/go/+/492175
Run-TryBot: Than McIntosh <thanm@google.com>
Auto-Submit: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
@gopherbot
Copy link

Change https://go.dev/cl/492981 mentions this issue: internal/coverage/encodecounter: followup changes from code review

gopherbot pushed a commit that referenced this issue May 5, 2023
This patch contains a small set of changes with fixes for some
issues that surfaced during the code review for CL 484535. Due
to an error on my part, these never got included in the final version
that was checked in (I rebased, mailed the rebase, but then never
mailed the final patch set with the changes). This patch sends
the remaining bits and pieces.

Updates #59563.

Change-Id: I87dc05a83f8e44c8bfe7203bc2b035defc817af9
Reviewed-on: https://go-review.googlesource.com/c/go/+/492981
Run-TryBot: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants