-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
runtime/coverage: coverage from other binaries is not collected in tests #60182
Comments
cc @thanm |
This comment was marked as off-topic.
This comment was marked as off-topic.
@ankitjain1510 That sounds unrelated to filtering of coverage collected by the testing package, so I suggest you open a separate issue for that, or ask on golang-nuts. |
@ankitjain1510 collecting snapshots of coverage from server binaries is a bit different as @FiloSottile mentioned. We have APIs for doing this, but the documentation for them is not written/published (please bear with me on that). Thanks. |
Hi @FiloSottile Thanks for the report. It might be helpful for me to understand your high-level goals here in a bit more detail. From your description it sounds like you have a module with that has a package P with tests, and in the test code you use "go build -cover" to build some sort of auxiliary binary (which might import P), then you would like to see the coverage effects of running the binary reflected in the coverage percentage numbers for P, something like that? Is your main item of interest the coverage percentages or are you looking at text profiles as well? It seems important to ensure that when a "-cover" test binary executes and writes out coverage stats or profiles, the raw material for that report comes only from running the test. So for example, if you were to do something like
it is important that the coverage numbers reported for "somePackage" don't incorporate any of the data files that might be in /tmp/xyz. These sorts of concerns are what motivated the testsupport.go code that you hlghlighted. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Yep pretty much. I have testscript tests that build a set of commands from my module and use them all together in test scripts (for example, use foo-keygen to make a key and then run a server with that key and then use fooctl to inspec tthe database) and I would like to get aggregate coverage profiles. I understand wanting to ignore spurious entries in Anyway it's weirdly inconsistent that sub-invocations of the same test binary leads to profiles that get aggregated but sub-invocations of other binaries doesn't. Even invocations of the same test binary might be from separate test runs that shouldn't be aggregated, too. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
I have a very similar use case which led me to create an issue that was closed as duplicate #63660 To sum it up, I wrote a package that handles context cancelation around signals. Signals cannot be tested as a unit test, and so I created a small testing acceptance binary in my tests that I can run, send signals to, and assert the correct output. When I detect that a However, only the coverage of unit tests is reported using the This seems like a bug. I have noticed that As of today to get full coverage of you application you need to:
When really it should just work:
|
I hit the same issue. In fact, I didn't know that GOCOVERDIR=coverage go test ./... -race -timeout 10m -cover -covermode atomic -args -test.gocoverdir=coverage It took me quite some time to figure out why things do not work. Why when I then internally call So my proposal would be (and or or):
The issue is now that I even cannot manually set |
Or it should be merged into the cover profile provided with -coverprofile. Anything but discarding my data would be acceptable... I just ran into this as well. Very frustrating as it took me a few days to figure out this is why my data was missing. |
When running VM tests with `GOCOVERDIR=$x go test -cover`, Go overrides the GOCOVERDIR for the test process, but does not share the coverage data in any way. Upstream issue is golang/go#60182 Signed-off-by: Chris Koch <chrisko@google.com>
When running VM tests with `GOCOVERDIR=$x go test -cover`, Go overrides the GOCOVERDIR for the test process, but does not share the coverage data in any way. Upstream issue is golang/go#60182 Signed-off-by: Chris Koch <chrisko@google.com>
Can we get alignment on a preferred path here? I'd like to see a solution make it into 1.24. |
1.24 has entered the code freeze stage of the release process, so this will not be making into 1.24. |
I would love if we could align for 1.25 then? I am not a contributor to the Go project. But it seems to me that the coverage reporting needs to be lazy and allow subprocesses to write coverage reports to the same report location, and then join all reports. In a nutshell. It would be a big boon to folks trying to write acceptance/blackbox tests, and the testing of production-like binaries / entrypoints. |
I’m just a minor contributor, I only have the member role to help with issue triage so I’m not involved in that kind of decision. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, with devel go1.21-91b8cc0d.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Within a Go test, built a binary from a different package in the same module with
-cover
and executed it.Ran the test with
-coverpkg=./...
.What did you expect to see?
Coverage of the command invocation included in the test summary.
What did you see instead?
coverage: 0.0% of statements in ./...
I expected this to work because there is explicit support for it in the testing package, which propagates the temporary GOCOVERDIR to the environment.
go/src/cmd/go/internal/test/test.go
Lines 1326 to 1330 in 91b8cc0
Indeed, rogpeppe/go-internal#201 takes advantage of this to run the test binary as a subprocess and collect coverage from that invocation with the coverage of the main test run.
However, there is then code to exclude coverage from other binaries, introduced for #57924.
go/src/runtime/coverage/testsupport.go
Lines 84 to 96 in 91b8cc0
I think running integration tests within a Go test is a more idiomatic way to do it than rigging a script with
go tool covdata
invocations, and it's nice that GOCOVERDIR gets already set up and propagated automatically, but the pattern then breaks when the coverage data is not collected.As an aside, it should be documented somewhere how test coverage is propagated and collected.
The text was updated successfully, but these errors were encountered: