From 5095e5d8e2cec3d6209e733652ead8ddc20fc7c2 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Fri, 4 May 2018 12:08:47 +0200 Subject: [PATCH] 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 --- src/cmd/go/go_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 4b68c40382..c05fab00fc 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -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()