]> Cypherpunks repositories - gostls13.git/commitdiff
misc/cgo/testcarchive: re-enable c-archive test on iOS and Android
authorElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 20:47:02 +0000 (21:47 +0100)
committerElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 23:43:27 +0000 (23:43 +0000)
The c-archive test were recently converted from shell script to Go.
Unfortunately, it also lost the ability to target iOS and Android
that lack C compilers and require exec wrappers.

Compile the c-archive test for the host and run it with the target
GOOS/GOARCH environment. Change the test to rely on go env GOOS
and go env GOARCH instead of runtime.GOOS and runtime.GOARCH.

Fixes #8345

Change-Id: I290ace2f7e96b87c55d99492feb7d660140dcb32
Reviewed-on: https://go-review.googlesource.com/21102
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/testcarchive/carchive_test.go
src/cmd/dist/test.go

index b941397cf15b3730cf6c75cee4d865798064ebd0..a853cba32b9ad3d2004ed7402c36074b4a9468dd 100644 (file)
@@ -11,7 +11,6 @@ import (
        "os"
        "os/exec"
        "path/filepath"
-       "runtime"
        "strings"
        "syscall"
        "testing"
@@ -21,7 +20,7 @@ import (
 // Program to run.
 var bin []string
 
-// C compiler wiht args (from $(go env CC) $(go env GOGCCFLAGS)).
+// C compiler with args (from $(go env CC) $(go env GOGCCFLAGS)).
 var cc []string
 
 // An environment with GOPATH=$(pwd).
@@ -30,27 +29,21 @@ var gopathEnv []string
 // ".exe" on Windows.
 var exeSuffix string
 
+var GOOS, GOARCH string
+
 func init() {
        bin = []string{"./testp"}
-       execScript := "go_" + runtime.GOOS + "_" + runtime.GOARCH + "_exec"
+       GOOS = goEnv("GOOS")
+       GOARCH = goEnv("GOARCH")
+       execScript := "go_" + GOOS + "_" + GOARCH + "_exec"
        if executor, err := exec.LookPath(execScript); err == nil {
                bin = []string{executor, "./testp"}
        }
 
-       out, err := exec.Command("go", "env", "CC").Output()
-       if err != nil {
-               fmt.Fprintf(os.Stderr, "go env CC failed:\n%s", err)
-               fmt.Fprintf(os.Stderr, "%s", err.(*exec.ExitError).Stderr)
-               os.Exit(2)
-       }
-       cc = []string{strings.TrimSpace(string(out))}
+       ccOut := goEnv("CC")
+       cc = []string{string(ccOut)}
 
-       out, err = exec.Command("go", "env", "GOGCCFLAGS").Output()
-       if err != nil {
-               fmt.Fprintf(os.Stderr, "go env GOGCCFLAGS failed:\n%s", err)
-               fmt.Fprintf(os.Stderr, "%s", err.(*exec.ExitError).Stderr)
-               os.Exit(2)
-       }
+       out := goEnv("GOGCCFLAGS")
        quote := '\000'
        start := 0
        lastSpace := true
@@ -83,14 +76,14 @@ func init() {
                cc = append(cc, s[start:])
        }
 
-       if runtime.GOOS == "darwin" {
+       if GOOS == "darwin" {
                cc = append(cc, "-Wl,-no_pie")
 
                // For Darwin/ARM.
                // TODO(crawshaw): can we do better?
                cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...)
        }
-       cc = append(cc, "-I", filepath.Join("pkg", runtime.GOOS+"_"+runtime.GOARCH))
+       cc = append(cc, "-I", filepath.Join("pkg", GOOS+"_"+GOARCH))
 
        // Build an environment with GOPATH=$(pwd)
        env := os.Environ()
@@ -108,11 +101,21 @@ func init() {
        n = append(n, "GOPATH="+dir)
        gopathEnv = n
 
-       if runtime.GOOS == "windows" {
+       if GOOS == "windows" {
                exeSuffix = ".exe"
        }
 }
 
+func goEnv(key string) string {
+       out, err := exec.Command("go", "env", key).Output()
+       if err != nil {
+               fmt.Fprintf(os.Stderr, "go env %s failed:\n%s", key, err)
+               fmt.Fprintf(os.Stderr, "%s", err.(*exec.ExitError).Stderr)
+               os.Exit(2)
+       }
+       return strings.TrimSpace(string(out))
+}
+
 func TestInstall(t *testing.T) {
        defer func() {
                os.Remove("libgo.a")
@@ -128,7 +131,7 @@ func TestInstall(t *testing.T) {
                t.Fatal(err)
        }
 
-       ccArgs := append(cc, "-o", "testp"+exeSuffix, "main.c", filepath.Join("pkg", runtime.GOOS+"_"+runtime.GOARCH, "libgo.a"))
+       ccArgs := append(cc, "-o", "testp"+exeSuffix, "main.c", filepath.Join("pkg", GOOS+"_"+GOARCH, "libgo.a"))
        if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil {
                t.Logf("%s", out)
                t.Fatal(err)
@@ -187,11 +190,11 @@ func TestInstall(t *testing.T) {
 }
 
 func TestEarlySignalHandler(t *testing.T) {
-       switch runtime.GOOS {
+       switch GOOS {
        case "darwin":
-               switch runtime.GOARCH {
+               switch GOARCH {
                case "arm", "arm64":
-                       t.Skipf("skipping on %s/%s; see https://golang.org/issue/13701", runtime.GOOS, runtime.GOARCH)
+                       t.Skipf("skipping on %s/%s; see https://golang.org/issue/13701", GOOS, GOARCH)
                }
        case "windows":
                t.Skip("skipping signal test on Windows")
@@ -345,7 +348,7 @@ func TestSignalForwardingExternal(t *testing.T) {
 }
 
 func TestOsSignal(t *testing.T) {
-       switch runtime.GOOS {
+       switch GOOS {
        case "windows":
                t.Skip("skipping signal test on Windows")
        }
@@ -377,7 +380,7 @@ func TestOsSignal(t *testing.T) {
 }
 
 func TestSigaltstack(t *testing.T) {
-       switch runtime.GOOS {
+       switch GOOS {
        case "windows":
                t.Skip("skipping signal test on Windows")
        }
@@ -417,7 +420,7 @@ echo "testar" > PWD/testar.ran
 `
 
 func TestExtar(t *testing.T) {
-       switch runtime.GOOS {
+       switch GOOS {
        case "windows":
                t.Skip("skipping signal test on Windows")
        }
index d8eb0f8a4887311829bc0ba6114077dcc2e80921..d5bb1362fb86e9a27c8dc9f8f43ca48f2d898258 100644 (file)
@@ -496,10 +496,8 @@ func (t *tester) registerTests() {
                                },
                        })
                }
-               if t.supportedBuildmode("c-archive") && t.goos != "android" && !t.iOS() {
-                       // TODO(elias.naur): reenable on android and iOS
-                       // golang.org/issue/8345
-                       t.registerTest("testcarchive", "../misc/cgo/testcarchive", "go", "test", "carchive_test.go")
+               if t.supportedBuildmode("c-archive") {
+                       t.registerHostTest("testcarchive", "misc/cgo/testcarchive", "carchive_test.go")
                }
                if t.supportedBuildmode("c-shared") {
                        t.registerTest("testcshared", "../misc/cgo/testcshared", "./test.bash")
@@ -693,6 +691,27 @@ func (t *tester) supportedBuildmode(mode string) bool {
        }
 }
 
+func (t *tester) registerHostTest(name, dirBanner, pkg string) {
+       t.tests = append(t.tests, distTest{
+               name:    name,
+               heading: dirBanner,
+               fn: func(dt *distTest) error {
+                       return t.runHostTest(dirBanner, pkg)
+               },
+       })
+}
+
+func (t *tester) runHostTest(dirBanner, pkg string) error {
+       env := mergeEnvLists([]string{"GOARCH=" + t.gohostarch, "GOOS=" + t.gohostos}, os.Environ())
+       defer os.Remove(filepath.Join(t.goroot, dirBanner, "test.test"))
+       cmd := t.dirCmd(dirBanner, "go", "test", t.tags(), "-c", "-o", "test.test", pkg)
+       cmd.Env = env
+       if err := cmd.Run(); err != nil {
+               return err
+       }
+       return t.dirCmd(dirBanner, "./test.test").Run()
+}
+
 func (t *tester) cgoTest(dt *distTest) error {
        env := mergeEnvLists([]string{"GOTRACEBACK=2"}, os.Environ())