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/go: race option doesn't work to test a code with binary-only package #26875

Closed
motomux opened this issue Aug 8, 2018 · 4 comments
Closed

Comments

@motomux
Copy link

motomux commented Aug 8, 2018

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

go version go1.10.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/motomuohtski/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/motomuohtski/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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/3t/1rcsh7wn6sb3_w2nbbnp0zc80000gn/T/go-build234195255=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Have a file ${GOPATH}/src/github.com/motomux/hellobop/src/hellobop.go
package hellobop

import "fmt"

func Hello(name string) string {
        return fmt.Sprintf("Hello %s from binary-only package!", name)
}
  1. Have a header file ${GOPATH}/src/github.com/motomux/hellobop/hellobop_header.go
//go:binary-only-package

package hellobop

func Hello(name string) string {
}
  1. Build binary by go build -o ${GOPATH}/pkg/darwin_amd64/github.com/motomux/hellobop.a -x ./src

  2. Have a test file ${GOPATH}/src/github.com/motomux/hellobop/test/helloboa_test.go

  3. Run test by go test ./test

  4. Run test by go test -race ./test

Here is the repository to reproduce the issue.

What did you expect to see?

go test -race runs test without any error.

What did you see instead?

It's failed with the error
go build github.com/motomux/hello: missing or invalid binary-only package

@motomux motomux changed the title test: race option doesn't work to test a code with binary-only package cmd/go: race option doesn't work to test a code with binary-only package Aug 8, 2018
@iamoryanmoshe
Copy link
Contributor

iamoryanmoshe commented Aug 8, 2018

Can you try adding a -o flag for the build (a target parameter for the output file) and run the test again please?

Edit: My bad, didn't notice your'e already compiling with -o.
From the source code it seems the problem originates with the target parameter of the build.
Can you make sure the file exists?

_, err := os.Stat(a.Package.Target)
		if err == nil {

This is the check that makes the test fail (err isn't nil)

Edit 2: can you add the -o parameter to your test line?

@slrz
Copy link

slrz commented Aug 8, 2018

The binary-only package probably needs to be compiled in race mode, too. The error is about not finding a package archive at pkg/darwin_amd64_race/…

@motomux
Copy link
Author

motomux commented Aug 8, 2018

@slrz You are right.
After running the following commands go test with/without race option works

go build -o ${GOPATH}/pkg/darwin_amd64/github.com/motomux/hellobop.a -x ./src
go build -race -o ${GOPATH}/pkg/darwin_amd64_race/github.com/motomux/hellobop.a -x ./src

@motomux motomux closed this as completed Aug 8, 2018
@motomux
Copy link
Author

motomux commented Aug 9, 2018

We don't even need to build with race option to test.
After running the following commands go test with/without race option works

go build -o ${GOPATH}/pkg/darwin_amd64/github.com/motomux/hellobop.a -x ./src
go build -o ${GOPATH}/pkg/darwin_amd64_race/github.com/motomux/hellobop.a -x ./src

@golang golang locked and limited conversation to collaborators Aug 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants