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

testing: no way to get a snapshot of current coverage data accumulator #34263

Closed
straightdave opened this issue Sep 12, 2019 · 4 comments
Closed

testing: no way to get a snapshot of current coverage data accumulator #34263

straightdave opened this issue Sep 12, 2019 · 4 comments

Comments

@straightdave
Copy link

@straightdave straightdave commented Sep 12, 2019

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

$ go version
go version go1.12.7 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wei.wu/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/wei.wu/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/wei.wu/repos/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/t0/zqt5zk8152n89780p5_qvb9r0000gn/T/go-build258050164=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Tried to find a way to get value of coverage data accumulator.

What did you expect to see?

There's a way to register a coverage data accumulator. Hence there should be a way to get value of coverage data accumulator.

What did you see instead?

Found no way to get the value of a package level non-exposing variable cover.

@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Sep 16, 2019

Hi @straightdave,

Can you please add more detail about what you're trying to do? Does testing.RegisterCover(c) do what you want?

https://godoc.org/testing#RegisterCover

@straightdave

This comment has been minimized.

Copy link
Author

@straightdave straightdave commented Sep 20, 2019

Hi @toothrot
Thanks for the reply 😃

I am trying to upload the line coverage data periodically while the binary code is running. I've tried to use RegisterCover to inject mine Cover instance but failed to get any data other than zero value from it. Meanwhile the hack function GetCover could always return the data no matter when and where I call it.

So the working way (and it's convenient) I found so far is to add this GetCover function to return the package level variable cover in src/testing/cover.go:

var cover Cover

// hack function
func GetCover() Cover {
    return cover
}

Any ideas?

@toothrot

This comment has been minimized.

Copy link
Contributor

@toothrot toothrot commented Sep 20, 2019

@straightdave Thanks for following up!

The Cover struct is documented as such:

NOTE: This struct is internal to the testing infrastructure and may change. It is not covered (yet) by the Go 1 compatibility guidelines.

Many parts of the testing library predate "internal" packages, and were exported for internal usage only. I think there's a single example in the Go codebase of how to use RegisterCover, but again, it could break in the future and we have no promises to support it externally.

Finally, I don't think we will be adding a new API to something that ought to have been internal in the first place, so I am going to close this issue.

I don't know the best way to help you do what you want, but a better place to ask this kind of question is golang-nuts. See https://golang.org/wiki/Questions. It'll reach a wider audience of people who may have tried something similar.

@toothrot toothrot closed this Sep 20, 2019
@straightdave

This comment has been minimized.

Copy link
Author

@straightdave straightdave commented Sep 26, 2019

🤔Makes sense. Thanks @toothrot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.