diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2024-04-11 15:06:11 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2024-04-11 14:27:17 +0000 |
| commit | 3f7932d24f9b230ac0e3592093a15a5a8c0a3770 (patch) | |
| tree | 904de8641bddcba7d52263dfb361cdba5faeaa03 /pkg | |
| parent | da2de8407550b81caeab72cf2fe645d1705f409e (diff) | |
vm: combine Run and MonitorExecution
All callers of Run always call MonitorExecution right after it.
Combine these 2 methods. This allows to hide some implementation
details and simplify users of vm package.
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/build/netbsd.go | 3 | ||||
| -rw-r--r-- | pkg/instance/execprog.go | 23 | ||||
| -rw-r--r-- | pkg/instance/instance.go | 8 | ||||
| -rw-r--r-- | pkg/repro/strace.go | 2 |
4 files changed, 17 insertions, 19 deletions
diff --git a/pkg/build/netbsd.go b/pkg/build/netbsd.go index e4390872a..962b6e82c 100644 --- a/pkg/build/netbsd.go +++ b/pkg/build/netbsd.go @@ -155,12 +155,11 @@ func (ctx netbsd) copyKernelToDisk(targetArch, vmType, outputDir, kernel string) } commands = append(commands, "mknod /dev/vhci c 355 0") commands = append(commands, "sync") // Run sync so that the copied image is stored properly. - outc, errc, err := inst.Run(time.Minute, nil, strings.Join(commands, ";")) + _, rep, err := inst.Run(time.Minute, reporter, strings.Join(commands, ";")) if err != nil { return fmt.Errorf("error syncing the instance %w", err) } // Make sure that the command has executed properly. - rep := inst.MonitorExecution(outc, errc, reporter, vm.ExitNormal) if rep != nil { return fmt.Errorf("error executing sync: %v", rep.Title) } diff --git a/pkg/instance/execprog.go b/pkg/instance/execprog.go index 9e97dcd0c..acade5e8e 100644 --- a/pkg/instance/execprog.go +++ b/pkg/instance/execprog.go @@ -37,7 +37,8 @@ type ExecProgInstance struct { } type RunResult struct { - vm.ExecutionResult + Output []byte + Report *report.Report } func SetupExecProg(vmInst *vm.Instance, mgrCfg *mgrconfig.Config, reporter *report.Reporter, @@ -107,25 +108,23 @@ func (inst *ExecProgInstance) runCommand(command string, duration time.Duration) command = inst.StraceBin + filterCalls + ` -s 100 -x -f ` + command prefixOutput = []byte(fmt.Sprintf("%s\n\n<...>\n", command)) } - outc, errc, err := inst.VMInstance.Run(duration, nil, command) + opts := []any{inst.ExitCondition} + if inst.BeforeContextLen != 0 { + opts = append(opts, vm.OutputSize(inst.BeforeContextLen)) + } + output, rep, err := inst.VMInstance.Run(duration, inst.reporter, command, opts...) if err != nil { return nil, fmt.Errorf("failed to run command in VM: %w", err) } - result := &RunResult{ - ExecutionResult: *inst.VMInstance.MonitorExecutionRaw(outc, errc, - inst.reporter, inst.ExitCondition, inst.BeforeContextLen), - } - if len(prefixOutput) > 0 { - result.RawOutput = append(prefixOutput, result.RawOutput...) - } - if result.Report == nil { + if rep == nil { inst.Logf(2, "program did not crash") } else { - if err := inst.reporter.Symbolize(result.Report); err != nil { + if err := inst.reporter.Symbolize(rep); err != nil { inst.Logf(0, "failed to symbolize report: %v", err) } - inst.Logf(2, "program crashed: %v", result.Report.Title) + inst.Logf(2, "program crashed: %v", rep.Title) } + result := &RunResult{append(prefixOutput, output...), rep} return result, nil } diff --git a/pkg/instance/instance.go b/pkg/instance/instance.go index 1e4787c94..4c61b1d24 100644 --- a/pkg/instance/instance.go +++ b/pkg/instance/instance.go @@ -388,11 +388,11 @@ func (inst *inst) testInstance() error { cmd := OldFuzzerCmd(fuzzerBin, executorBin, targets.TestOS, inst.cfg.TargetOS, inst.cfg.TargetArch, fwdAddr, inst.cfg.Sandbox, inst.cfg.SandboxArg, 0, inst.cfg.Cover, true, inst.optionalFlags, inst.cfg.Timeouts.Slowdown) - outc, errc, err := inst.vm.Run(10*time.Minute*inst.cfg.Timeouts.Scale, nil, cmd) + timeout := 10 * time.Minute * inst.cfg.Timeouts.Scale + _, rep, err := inst.vm.Run(timeout, inst.reporter, cmd) if err != nil { return fmt.Errorf("failed to run binary in VM: %w", err) } - rep := inst.vm.MonitorExecution(outc, errc, inst.reporter, vm.ExitNormal) if rep != nil { if err := inst.reporter.Symbolize(rep); err != nil { // TODO(dvyukov): send such errors to dashboard. @@ -424,9 +424,9 @@ func (inst *inst) testRepro() ([]byte, error) { return nil, err } if res != nil && res.Report != nil { - return res.RawOutput, &CrashError{Report: res.Report} + return res.Output, &CrashError{Report: res.Report} } - return res.RawOutput, nil + return res.Output, nil } out := []byte{} if len(inst.reproSyz) > 0 { diff --git a/pkg/repro/strace.go b/pkg/repro/strace.go index 87d3cf64e..ef4f7c934 100644 --- a/pkg/repro/strace.go +++ b/pkg/repro/strace.go @@ -51,7 +51,7 @@ func RunStrace(result *Result, cfg *mgrconfig.Config, reporter *report.Reporter, } return &StraceResult{ Report: runRes.Report, - Output: runRes.RawOutput, + Output: runRes.Output, } } |
