]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: test that Go binaries can be run on QEMU in user-mode
authorAlberto Donizetti <alb.donizetti@gmail.com>
Fri, 4 May 2018 10:08:47 +0000 (12:08 +0200)
committerAlberto Donizetti <alb.donizetti@gmail.com>
Mon, 21 May 2018 18:13:25 +0000 (18:13 +0000)
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>
src/cmd/go/go_test.go

index 4b68c4038209e73f340e765c3c5a3c3505a55fcf..c05fab00fc4692a9de29b78a651f9b567be9fa2e 100644 (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()