1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:16:54 -07:00

misc/ios: retry lldb launch if the iOS app is busy

Sometimes, a newly installed the test app is not ready to launch
or the reported app path is stale. Pause and retry the launch if
the lldb script did not run the program.

Change-Id: Ic7745d4b5a02f2e3cb8134341859039812f65a65
Reviewed-on: https://go-review.googlesource.com/111216
Run-TryBot: Elias Naur <elias.naur@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Elias Naur 2018-05-03 11:43:25 +02:00
parent 64f715beb6
commit 4704149e04

View File

@ -129,11 +129,6 @@ func runMain() (int, error) {
return 1, err return 1, err
} }
deviceApp, err := findDeviceAppPath(bundleID)
if err != nil {
return 1, err
}
if err := mountDevImage(); err != nil { if err := mountDevImage(); err != nil {
return 1, err return 1, err
} }
@ -144,7 +139,7 @@ func runMain() (int, error) {
} }
defer closer() defer closer()
if err := run(appdir, deviceApp, os.Args[2:]); err != nil { if err := run(appdir, bundleID, os.Args[2:]); err != nil {
// If the lldb driver completed with an exit code, use that. // If the lldb driver completed with an exit code, use that.
if err, ok := err.(*exec.ExitError); ok { if err, ok := err.(*exec.ExitError); ok {
if ws, ok := err.Sys().(interface{ ExitStatus() int }); ok { if ws, ok := err.Sys().(interface{ ExitStatus() int }); ok {
@ -408,14 +403,7 @@ func idevCmd(cmd *exec.Cmd) *exec.Cmd {
return cmd return cmd
} }
func run(appdir, deviceapp string, args []string) error { func run(appdir, bundleID string, args []string) error {
lldb := exec.Command(
"python",
"-", // Read script from stdin.
appdir,
deviceapp,
)
lldb.Args = append(lldb.Args, args...)
var env []string var env []string
for _, e := range os.Environ() { for _, e := range os.Environ() {
// Don't override TMPDIR on the device. // Don't override TMPDIR on the device.
@ -424,11 +412,39 @@ func run(appdir, deviceapp string, args []string) error {
} }
env = append(env, e) env = append(env, e)
} }
lldb.Env = env attempt := 0
lldb.Stdin = strings.NewReader(lldbDriver) for {
lldb.Stdout = os.Stdout // The device app path is constant for a given installed app,
lldb.Stderr = os.Stderr // but the device might not return a stale device path for
return lldb.Run() // a newly overwritten app, so retry the lookup as well.
deviceapp, err := findDeviceAppPath(bundleID)
if err != nil {
return err
}
lldb := exec.Command(
"python",
"-", // Read script from stdin.
appdir,
deviceapp,
)
lldb.Args = append(lldb.Args, args...)
lldb.Env = env
lldb.Stdin = strings.NewReader(lldbDriver)
lldb.Stdout = os.Stdout
var out bytes.Buffer
lldb.Stderr = io.MultiWriter(&out, os.Stderr)
err = lldb.Run()
// If the program was not started it can be retried without papering over
// real test failures.
started := bytes.HasPrefix(out.Bytes(), []byte("lldb: running program"))
if started || err == nil || attempt == 5 {
return err
}
// Sometimes, the app was not yet ready to launch or the device path was
// stale. Retry.
attempt++
time.Sleep(5 * time.Second)
}
} }
func copyLocalDir(dst, src string) error { func copyLocalDir(dst, src string) error {
@ -665,22 +681,24 @@ for i in range(0, sigs.GetNumSignals()):
sigs.SetShouldNotify(sig, False) sigs.SetShouldNotify(sig, False)
event = lldb.SBEvent() event = lldb.SBEvent()
running = False
while True: while True:
if not listener.WaitForEvent(1, event): if not listener.WaitForEvent(1, event):
continue continue
if not lldb.SBProcess.EventIsProcessEvent(event): if not lldb.SBProcess.EventIsProcessEvent(event):
continue continue
# Pass through stdout and stderr. if running:
while True: # Pass through stdout and stderr.
out = process.GetSTDOUT(8192) while True:
if not out: out = process.GetSTDOUT(8192)
break if not out:
sys.stdout.write(out) break
while True: sys.stdout.write(out)
out = process.GetSTDERR(8192) while True:
if not out: out = process.GetSTDERR(8192)
break if not out:
sys.stderr.write(out) break
sys.stderr.write(out)
state = process.GetStateFromEvent(event) state = process.GetStateFromEvent(event)
if state in [lldb.eStateCrashed, lldb.eStateDetached, lldb.eStateUnloaded, lldb.eStateExited]: if state in [lldb.eStateCrashed, lldb.eStateDetached, lldb.eStateUnloaded, lldb.eStateExited]:
break break
@ -691,6 +709,9 @@ while True:
process.Kill() process.Kill()
debugger.Terminate() debugger.Terminate()
sys.exit(1) sys.exit(1)
# Tell the Go driver that the program is running and should not be retried.
sys.stderr.write("lldb: running program\n")
running = True
# Process stops once at the beginning. Continue. # Process stops once at the beginning. Continue.
process.Continue() process.Continue()