diff options
Diffstat (limited to 'misc/android/go_android_exec.go')
-rw-r--r-- | misc/android/go_android_exec.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/misc/android/go_android_exec.go b/misc/android/go_android_exec.go index 1a8ae7070e..0055fb832a 100644 --- a/misc/android/go_android_exec.go +++ b/misc/android/go_android_exec.go @@ -60,6 +60,19 @@ func main() { log.SetFlags(0) log.SetPrefix("go_android_exec: ") + // Concurrent use of adb is flaky, so serialize adb commands. + // See https://github.com/golang/go/issues/23795 or + // https://issuetracker.google.com/issues/73230216. + lockPath := filepath.Join(os.TempDir(), "go_android_exec-adb-lock") + lock, err := os.OpenFile(lockPath, os.O_CREATE|os.O_RDWR, 0666) + if err != nil { + log.Fatal(err) + } + defer lock.Close() + if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil { + log.Fatal(err) + } + // In case we're booting a device or emulator alongside androidtest.bash // wait for it to be ready. adb wait-for-device is not enough, we have to // wait for sys.boot_completed. @@ -87,15 +100,7 @@ func main() { // E.g. template.test from the {html,text}/template packages. binName := fmt.Sprintf("%s-%d", filepath.Base(os.Args[1]), os.Getpid()) deviceBin := fmt.Sprintf("%s/%s", deviceGotmp, binName) - - // The push of the binary happens in parallel with other tests. - // Unfortunately, a simultaneous call to adb shell hold open - // file descriptors, so it is necessary to push then move to - // avoid a "text file busy" error on execution. - // https://code.google.com/p/android/issues/detail?id=65857 - run("push", os.Args[1], deviceBin+"-tmp") - run("shell", "cp '"+deviceBin+"-tmp' '"+deviceBin+"'") - run("shell", "rm '"+deviceBin+"-tmp'") + run("push", os.Args[1], deviceBin) // Forward SIGQUIT from the go command to show backtraces from // the binary instead of from this wrapper. |