From e40a490e9c5e71bb3c0aca2a1ddcf7af4845635d Mon Sep 17 00:00:00 2001 From: Joey Jiao Date: Mon, 29 Mar 2021 14:37:22 +0800 Subject: vm/adb: add startup_script config --- vm/adb/adb.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'vm/adb') diff --git a/vm/adb/adb.go b/vm/adb/adb.go index cbd5109b1..92e49c346 100644 --- a/vm/adb/adb.go +++ b/vm/adb/adb.go @@ -40,7 +40,8 @@ type Config struct { BatteryCheck bool `json:"battery_check"` // If this option is set (default), the device is rebooted after each crash. // Set it to false to disable reboots. - TargetReboot bool `json:"target_reboot"` + TargetReboot bool `json:"target_reboot"` + StartupScript string `json:"startup_script"` // script to execute after each startup } type Pool struct { @@ -283,7 +284,21 @@ func (inst *instance) repair() error { } // Switch to root for userdebug builds. inst.adb("root") - return inst.waitForSSH() + inst.waitForSSH() + if inst.cfg.StartupScript != "" { + log.Logf(2, "adb: executing startup_script") + // Execute the contents of the StartupScript on the DUT. + contents, err := ioutil.ReadFile(inst.cfg.StartupScript) + if err != nil { + return fmt.Errorf("unable to read startup_script: %v", err) + } + c := string(contents) + if _, err := inst.adb("shell", fmt.Sprintf("sh -c \"%v\"", vmimpl.EscapeDoubleQuotes(c))); err != nil { + return fmt.Errorf("failed to execute startup_script: %v", err) + } + log.Logf(2, "adb: done executing startup_script") + } + return nil } func (inst *instance) waitForSSH() error { -- cgit mrf-deployment