all: skip or fix tests for GOOS=android

Some x/mobile tests are designed to run from a host with a device
or emulator attached. Some fail if they run directly from a device,
which is the case when GOOS=android.

Fix the tests by skipping them or adjusting them to work on GOOS=android.

Remove gomobile environment naïve variable expansion for $HOME; on
Android devices HOME=/ so every path separator is replaced with
$HOME.

Fixes golang/go#30482

Change-Id: I553e708226922f6284163f0b7d7b1011a9502e34
Reviewed-on: https://go-review.googlesource.com/c/164799
Run-TryBot: Elias Naur <mail@eliasnaur.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Elias Naur
2019-03-02 06:36:18 +00:00
parent 3ac37b7f94
commit b8c6dab863
7 changed files with 63 additions and 27 deletions
+18 -13
View File
@@ -36,20 +36,22 @@ func testMain(m *testing.M) int {
if runtime.GOOS == "windows" {
exe = ".exe"
}
gomobileBin = filepath.Join(binDir, "gomobile"+exe)
gobindBin := filepath.Join(binDir, "gobind"+exe)
if out, err := exec.Command("go", "build", "-o", gomobileBin, "golang.org/x/mobile/cmd/gomobile").CombinedOutput(); err != nil {
log.Fatalf("gomobile build failed: %v: %s", err, out)
if runtime.GOOS != "android" {
gomobileBin = filepath.Join(binDir, "gomobile"+exe)
gobindBin := filepath.Join(binDir, "gobind"+exe)
if out, err := exec.Command("go", "build", "-o", gomobileBin, "golang.org/x/mobile/cmd/gomobile").CombinedOutput(); err != nil {
log.Fatalf("gomobile build failed: %v: %s", err, out)
}
if out, err := exec.Command("go", "build", "-o", gobindBin, "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
log.Fatalf("gobind build failed: %v: %s", err, out)
}
PATH := os.Getenv("PATH")
if PATH != "" {
PATH += string(filepath.ListSeparator)
}
PATH += binDir
os.Setenv("PATH", PATH)
}
if out, err := exec.Command("go", "build", "-o", gobindBin, "golang.org/x/mobile/cmd/gobind").CombinedOutput(); err != nil {
log.Fatalf("gobind build failed: %v: %s", err, out)
}
PATH := os.Getenv("PATH")
if PATH != "" {
PATH += string(filepath.ListSeparator)
}
PATH += binDir
os.Setenv("PATH", PATH)
return m.Run()
}
@@ -99,6 +101,9 @@ func TestJavaSeqBench(t *testing.T) {
// This requires the gradle command in PATH and
// the Android SDK whose path is available through ANDROID_HOME environment variable.
func runTest(t *testing.T, pkgNames []string, javaPkg, javaCls string) {
if gomobileBin == "" {
t.Skipf("no gomobile on %s", runtime.GOOS)
}
gradle, err := exec.LookPath("gradle")
if err != nil {
t.Skip("command gradle not found, skipping")