1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:44:43 -07:00

cmd/go: test that Go binaries can be run on QEMU in user-mode

We have a workaround in place in the runtime (see CL 16853 and
CL 111176) to keep arm and arm64 Go binaries working under QEMU
in user-emulation mode (Issue #13024).

This change adds a regression test about arm/arm64 QEMU emulation
to cmd/go.

Change-Id: Ic67f476e7c30a7d7852d9b01834f1dcabfac2ff7
Reviewed-on: https://go-review.googlesource.com/111477
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Alberto Donizetti 2018-05-04 12:08:47 +02:00
parent d583ca764a
commit 5095e5d8e2

View File

@ -5131,6 +5131,49 @@ func TestUpxCompression(t *testing.T) {
}
}
// Test that Go binaries can be run under QEMU in user-emulation mode
// (See issue #13024).
func TestQEMUUserMode(t *testing.T) {
if testing.Short() && testenv.Builder() == "" {
t.Skipf("skipping in -short mode on non-builder")
}
testArchs := []struct {
g, qemu string
}{
{"arm", "arm"},
{"arm64", "aarch64"},
}
tg := testgo(t)
defer tg.cleanup()
tg.tempFile("main.go", `package main; import "fmt"; func main() { fmt.Print("hello qemu-user") }`)
tg.parallel()
src, obj := tg.path("main.go"), tg.path("main")
for _, arch := range testArchs {
out, err := exec.Command("qemu-"+arch.qemu, "--version").CombinedOutput()
if err != nil {
t.Logf("Skipping %s test (qemu-%s not available)", arch.g, arch.qemu)
continue
}
tg.setenv("GOARCH", arch.g)
tg.run("build", "-o", obj, src)
out, err = exec.Command("qemu-"+arch.qemu, obj).CombinedOutput()
if err != nil {
t.Logf("qemu-%s output:\n%s\n", arch.qemu, out)
t.Errorf("qemu-%s failed with %v", arch.qemu, err)
continue
}
if want := "hello qemu-user"; string(out) != want {
t.Errorf("bad output from qemu-%s:\ngot %s; want %s", arch.qemu, out, want)
}
}
}
func TestGOTMPDIR(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()