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

Comments

Projects
None yet
3 participants
@motomux
Copy link

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Author

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 Aug 8, 2018

@motomux

This comment has been minimized.

Copy link
Author

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.