aboutsummaryrefslogtreecommitdiffstats
path: root/vm/cuttlefish/cuttlefish.go
diff options
context:
space:
mode:
authorKris Alder <kalder@google.com>2022-04-06 14:57:36 -0700
committerDmitry Vyukov <dvyukov@google.com>2022-04-07 09:12:27 +0200
commitc6ff3e051f85ae554460141ba2ece6dbe9a36bb9 (patch)
tree2aaddb9c1302302fcff47951021c6951b7e802e4 /vm/cuttlefish/cuttlefish.go
parent53c67432e69b0df4ff64448b944cbffaecec20f4 (diff)
vm/cuttlefish: implement copy and run functions
To copy files onto the virutal device, we first copy them to the host GCE instance using the 'gce.Copy()' function and then push it to the device using 'adb push <src> <dst>'. Running commands on the device is also simple and merely prepends "adb shell" to the command run on the GCE instance. This results in an overall command along the lines of "ssh adb shell <command>".
Diffstat (limited to 'vm/cuttlefish/cuttlefish.go')
-rw-r--r--vm/cuttlefish/cuttlefish.go23
1 files changed, 19 insertions, 4 deletions
diff --git a/vm/cuttlefish/cuttlefish.go b/vm/cuttlefish/cuttlefish.go
index 501f6079d..dbba45037 100644
--- a/vm/cuttlefish/cuttlefish.go
+++ b/vm/cuttlefish/cuttlefish.go
@@ -12,6 +12,7 @@ package cuttlefish
import (
"fmt"
+ "path/filepath"
"time"
"github.com/google/syzkaller/pkg/log"
@@ -19,6 +20,10 @@ import (
"github.com/google/syzkaller/vm/vmimpl"
)
+const (
+ deviceRoot = "/data/fuzz"
+)
+
func init() {
vmimpl.Register("cuttlefish", ctor, true)
}
@@ -103,7 +108,19 @@ func (inst *instance) runOnHost(timeout time.Duration, cmd string) error {
}
func (inst *instance) Copy(hostSrc string) (string, error) {
- return "", fmt.Errorf("not implemented")
+ gceDst, err := inst.gceInst.Copy(hostSrc)
+ if err != nil {
+ return "", fmt.Errorf("error copying to worker instance: %s", err)
+ }
+
+ deviceDst := filepath.Join(deviceRoot, filepath.Base(hostSrc))
+ pushCmd := fmt.Sprintf("adb push %s %s", gceDst, deviceDst)
+
+ if err := inst.runOnHost(5*time.Minute, pushCmd); err != nil {
+ return "", fmt.Errorf("error pushing to device: %s", err)
+ }
+
+ return deviceDst, nil
}
func (inst *instance) Forward(port int) (string, error) {
@@ -111,14 +128,12 @@ func (inst *instance) Forward(port int) (string, error) {
}
func (inst *instance) Close() {
- // Stop Cuttlefish before shutting down the GCE instance.
- inst.runOnHost(10*time.Minute, "./bin/stop_cvd")
inst.gceInst.Close()
}
func (inst *instance) Run(timeout time.Duration, stop <-chan bool, command string) (
<-chan []byte, <-chan error, error) {
- return nil, nil, fmt.Errorf("not implemented")
+ return inst.gceInst.Run(timeout, stop, fmt.Sprintf("adb shell %s", command))
}
func (inst *instance) Diagnose(rep *report.Report) ([]byte, bool) {