Contract coverage is not compatible with atomic covermode #1369

Open
opened 2025-12-28 17:16:12 +00:00 by sami · 2 comments
Owner

Originally created by @roman-khimov on GitHub (Sep 13, 2024).

Current Behavior

go test -v -race ./path-to-contract -coverprofile=coverage.txt -covermode=atomic fails with

error: test wrote malformed coverage profile /tmp/go-build2520858745/b001/_cover_.out.

Expected Behavior

Same command working fine. In fact, any of -covermode or -race leads to this while a simple go test -v ./path-to-contract -coverprofile=coverage.txt works fine.

Possible Solution

Not yet known.

Your Environment

Originally created by @roman-khimov on GitHub (Sep 13, 2024). ## Current Behavior `go test -v -race ./path-to-contract -coverprofile=coverage.txt -covermode=atomic` fails with ``` error: test wrote malformed coverage profile /tmp/go-build2520858745/b001/_cover_.out. ``` ## Expected Behavior Same command working fine. In fact, any of `-covermode` or `-race` leads to this while a simple `go test -v ./path-to-contract -coverprofile=coverage.txt` works fine. ## Possible Solution Not yet known. ## Your Environment * Version of the product used: e1d5ac8557d7e087158e6a766d059913a56df79f
Author
Owner

@AnnaShaleva commented on GitHub (Oct 15, 2024):

any of -covermode or -race leads to this

The original problem is with covermode=atomic coverage mode, because -race overwrites coverage collection mode to atomic anyway.

while a simple go test -v ./path-to-contract -coverprofile=coverage.txt works fine.

It works fine because it uses set coverage mode by default.

So the issue is about proper atomic cover mode support. Here what I managed to find out: the described error is returned by go cover when it tries to merge the resulting coverage outputs from different tests. The source code that produces this error is:
golang/go@cbdb3545ad/src/cmd/go/internal/test/cover.go (L69)

In particular, go cover tool can't find the expected covermode: atomic line in the start of specific coverage output file which results in this error. The error looks strange to me, because https://github.com/nspcc-dev/neo-go/pull/3616/commits/2dc588ea9578e54e5971c0730ae78313e5a804cf ensures this line is properly written to the output file. And hence, the only thing that might go wrong is the file location itself. I'd suggest to compile go cover tool with some custom logs, see what exactly causes this error (either an empty file or the line of the wrong form) and see what exactly go cover expects to get.

@AnnaShaleva commented on GitHub (Oct 15, 2024): > any of -covermode or -race leads to this The original problem is with `covermode=atomic` coverage mode, because `-race` overwrites coverage collection mode to `atomic` anyway. > while a simple go test -v ./path-to-contract -coverprofile=coverage.txt works fine. It works fine because it uses `set` coverage mode by default. So the issue is about proper `atomic` cover mode support. Here what I managed to find out: the described error is returned by `go cover` when it tries to merge the resulting coverage outputs from different tests. The source code that produces this error is: https://github.com/golang/go/blob/cbdb3545ad7d15204ef15daf124393aefb7b2c3d/src/cmd/go/internal/test/cover.go#L69 In particular, `go cover` tool can't find the expected `covermode: atomic` line in the start of specific coverage output file which results in this error. The error looks strange to me, because https://github.com/nspcc-dev/neo-go/pull/3616/commits/2dc588ea9578e54e5971c0730ae78313e5a804cf ensures this line is properly written to the output file. And hence, the only thing that might go wrong is the file location itself. I'd suggest to compile `go cover` tool with some custom logs, see what exactly causes this error (either an empty file or the line of the wrong form) and see what exactly `go cover` expects to get.
Author
Owner

@AnnaShaleva commented on GitHub (Oct 16, 2024):

And BTW, the reason is definitely not in the compiler; it's in the neotest coverage module itself.

@AnnaShaleva commented on GitHub (Oct 16, 2024): And BTW, the reason is definitely not in the compiler; it's in the neotest coverage module itself.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nspcc-dev/neo-go#1369
No description provided.