Skip to content

cmd/go: race option doesn't work to test a code with binary-only package #26875

Closed
@motomux

Description

@motomux

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

Activity

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[/+] on Aug 8, 2018
iamoryanmoshe

iamoryanmoshe commented on Aug 8, 2018

@iamoryanmoshe
Contributor

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

slrz commented on Aug 8, 2018

@slrz

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

motomux commented on Aug 8, 2018

@motomux
Author

@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 commented on Aug 9, 2018

@motomux
Author

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
locked and limited conversation to collaborators on Aug 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @slrz@gopherbot@motomux@iamoryanmoshe

        Issue actions

          cmd/go: race option doesn't work to test a code with binary-only package · Issue #26875 · golang/go