]> Cypherpunks.ru repositories - gostls13.git/commitdiff
misc/ios: serialize iOS execution
authorElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 15:03:07 +0000 (16:03 +0100)
committerElias Naur <elias.naur@gmail.com>
Thu, 24 Mar 2016 17:02:42 +0000 (17:02 +0000)
The iOS exec wrapper use complicated machinery to run a iOS binary
on a device.
Running several binaries concurrently doesn't work (reliably), which
can break tests running concurrently. For my setup, the
runtime:cpu124 and sync_cpu tests can't run reliably without one of them
crashing.

Add a file lock to the exec wrapper to serialize execution.

Fixes #14318 (for me)

Change-Id: I023610e014b327f8d66f1d2fd2e54dd0e56f2be0
Reviewed-on: https://go-review.googlesource.com/21074
Reviewed-by: David Crawshaw <crawshaw@golang.org>
misc/ios/go_darwin_arm_exec.go

index 6420dd1d94c31eeaff14bef569348ea373540e32..6f0b98f11248b9cda3573a3c48fd6ed46c659b11 100644 (file)
@@ -34,6 +34,7 @@ import (
        "runtime"
        "strings"
        "sync"
+       "syscall"
        "time"
 )
 
@@ -76,6 +77,20 @@ func main() {
                log.Fatal(err)
        }
 
+       // This wrapper uses complicated machinery to run iOS binaries. It
+       // works, but only when running one binary at a time.
+       // Use a file lock to make sure only one wrapper is running at a time.
+       //
+       // The lock file is never deleted, to avoid concurrent locks on distinct
+       // files with the same path.
+       lockName := filepath.Join(os.TempDir(), "go_darwin_arm_exec.lock")
+       lock, err := os.OpenFile(lockName, os.O_CREATE|os.O_RDONLY, 0666)
+       if err != nil {
+               log.Fatal(err)
+       }
+       if err := syscall.Flock(int(lock.Fd()), syscall.LOCK_EX); err != nil {
+               log.Fatal(err)
+       }
        // Approximately 1 in a 100 binaries fail to start. If it happens,
        // try again. These failures happen for several reasons beyond
        // our control, but all of them are safe to retry as they happen