From 9b46845985d314be3da4dcafc3df58bcbfe0a670 Mon Sep 17 00:00:00 2001 From: Fudong Bai Date: Tue, 11 Aug 2020 09:40:59 +0000 Subject: [PATCH] vm: adb: add timeout config for low-end devices Signed-off-by: Fudong Bai --- vm/adb/adb.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vm/adb/adb.go b/vm/adb/adb.go index 75e4a1f7..29d11279 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -30,6 +30,7 @@ func init() { type Config struct { Adb string `json:"adb"` // adb binary name ("adb" by default) Devices []string `json:"devices"` // list of adb device IDs to use + Timeout int `json:"timeout"` // adb command timeout // Ensure that a device battery level is at 20+% before fuzzing. // Sometimes we observe that a device can't charge during heavy fuzzing @@ -47,6 +48,7 @@ type Pool struct { type instance struct { adbBin string device string + timeout int console string closed chan bool debug bool @@ -56,6 +58,7 @@ func ctor(env *vmimpl.Env) (vmimpl.Pool, error) { cfg := &Config{ Adb: "adb", BatteryCheck: true, + Timeout: 60, } if err := config.LoadData(env.Config, cfg); err != nil { return nil, fmt.Errorf("failed to parse adb vm config: %v", err) @@ -90,6 +93,7 @@ func (pool *Pool) Create(workdir string, index int) (vmimpl.Instance, error) { inst := &instance{ adbBin: pool.cfg.Adb, device: pool.cfg.Devices[index], + timeout: pool.cfg.Timeout, closed: make(chan bool), debug: pool.env.Debug, } @@ -246,9 +250,10 @@ func (inst *instance) adb(args ...string) ([]byte, error) { log.Logf(0, "executing adb %+v", args) } args = append([]string{"-s", inst.device}, args...) - out, err := osutil.RunCmd(time.Minute, "", inst.adbBin, args...) + timeout := time.Duration(inst.timeout) * time.Second + out, err := osutil.RunCmd(timeout, "", inst.adbBin, args...) if inst.debug { - log.Logf(0, "adb returned") + log.Logf(0, "adb returned ", timeout) } return out, err } -- 2.27.0