Commit 4ee85e67 authored by Elias Naur's avatar Elias Naur

misc/cgo/testcshared: support testing on self-hosted android

Only invoke adb for android if we're not running on android already.

Change-Id: I4eb94286a5bf09b382716a0474f3aebec40f5d74
Reviewed-on: https://go-review.googlesource.com/c/go/+/170953
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent ae85ae5d
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"sync" "sync"
"testing" "testing"
...@@ -45,7 +46,7 @@ func testMain(m *testing.M) int { ...@@ -45,7 +46,7 @@ func testMain(m *testing.M) int {
} }
androiddir = fmt.Sprintf("/data/local/tmp/testcshared-%d", os.Getpid()) androiddir = fmt.Sprintf("/data/local/tmp/testcshared-%d", os.Getpid())
if GOOS == "android" { if runtime.GOOS != GOOS && GOOS == "android" {
args := append(adbCmd(), "exec-out", "mkdir", "-p", androiddir) args := append(adbCmd(), "exec-out", "mkdir", "-p", androiddir)
cmd := exec.Command(args[0], args[1:]...) cmd := exec.Command(args[0], args[1:]...)
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
...@@ -177,7 +178,7 @@ func adbCmd() []string { ...@@ -177,7 +178,7 @@ func adbCmd() []string {
} }
func adbPush(t *testing.T, filename string) { func adbPush(t *testing.T, filename string) {
if GOOS != "android" { if runtime.GOOS == GOOS || GOOS != "android" {
return return
} }
args := append(adbCmd(), "push", filename, fmt.Sprintf("%s/%s", androiddir, filename)) args := append(adbCmd(), "push", filename, fmt.Sprintf("%s/%s", androiddir, filename))
...@@ -236,7 +237,7 @@ func run(t *testing.T, extraEnv []string, args ...string) string { ...@@ -236,7 +237,7 @@ func run(t *testing.T, extraEnv []string, args ...string) string {
func runExe(t *testing.T, extraEnv []string, args ...string) string { func runExe(t *testing.T, extraEnv []string, args ...string) string {
t.Helper() t.Helper()
if GOOS == "android" { if runtime.GOOS != GOOS && GOOS == "android" {
return adbRun(t, append(os.Environ(), extraEnv...), args...) return adbRun(t, append(os.Environ(), extraEnv...), args...)
} }
return run(t, extraEnv, args...) return run(t, extraEnv, args...)
...@@ -268,7 +269,7 @@ func createHeaders() error { ...@@ -268,7 +269,7 @@ func createHeaders() error {
return fmt.Errorf("command failed: %v\n%v\n%s\n", args, err, out) return fmt.Errorf("command failed: %v\n%v\n%s\n", args, err, out)
} }
if GOOS == "android" { if runtime.GOOS != GOOS && GOOS == "android" {
args = append(adbCmd(), "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname)) args = append(adbCmd(), "push", libgoname, fmt.Sprintf("%s/%s", androiddir, libgoname))
cmd = exec.Command(args[0], args[1:]...) cmd = exec.Command(args[0], args[1:]...)
out, err = cmd.CombinedOutput() out, err = cmd.CombinedOutput()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment