From c6ff3e051f85ae554460141ba2ece6dbe9a36bb9 Mon Sep 17 00:00:00 2001 From: Kris Alder Date: Wed, 6 Apr 2022 14:57:36 -0700 Subject: 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 '. 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 ". --- vm/cuttlefish/cuttlefish.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'vm/cuttlefish') 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) { -- cgit mrf-deployment