aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/repro
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-05-24 16:12:36 +0200
committerAleksandr Nogikh <wp32pw@gmail.com>2023-05-25 11:45:51 +0200
commitb36c307e4d7a49e7b738ab63576854eb43855e12 (patch)
tree830cd4fd60bca3271c19a54186f8ccf28e91b695 /pkg/repro
parente5881af751ea9a8409b341a95109823e3ffcedcf (diff)
pkg/repro: factor out an interface
Interact with a syz-execprog instance via an additional interface. This will simplify testing.
Diffstat (limited to 'pkg/repro')
-rw-r--r--pkg/repro/repro.go23
1 files changed, 15 insertions, 8 deletions
diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go
index d1c834ed6..6df634960 100644
--- a/pkg/repro/repro.go
+++ b/pkg/repro/repro.go
@@ -43,7 +43,7 @@ type Stats struct {
type reproInstance struct {
index int
- execProg *instance.ExecProgInstance
+ execProg execInterface
}
type context struct {
@@ -62,6 +62,13 @@ type context struct {
timeouts targets.Timeouts
}
+// execInterface describes what's needed from a VM by a pkg/repro.
+type execInterface interface {
+ Close()
+ RunCProg(p *prog.Prog, duration time.Duration, opts csource.Options) (*instance.RunResult, error)
+ RunSyzProg(syzProg []byte, duration time.Duration, opts csource.Options) (*instance.RunResult, error)
+}
+
var ErrNoPrograms = errors.New("crash log does not contain any programs")
func Run(crashLog []byte, cfg *mgrconfig.Config, features *host.Features, reporter *report.Reporter,
@@ -131,7 +138,7 @@ func (ctx *context) run() (*Result, *Stats, error) {
defer func() {
close(ctx.bootRequests)
for inst := range ctx.instances {
- inst.execProg.VMInstance.Close()
+ inst.execProg.Close()
}
}()
@@ -504,7 +511,7 @@ func (ctx *context) testProg(p *prog.Prog, duration time.Duration, opts csource.
return ctx.testProgs([]*prog.LogEntry{&entry}, duration, opts)
}
-func (ctx *context) testWithInstance(callback func(inst *instance.ExecProgInstance) (rep *instance.RunResult,
+func (ctx *context) testWithInstance(callback func(execInterface) (rep *instance.RunResult,
err error)) (bool, error) {
inst := <-ctx.instances
if inst == nil {
@@ -558,20 +565,20 @@ func (ctx *context) testProgs(entries []*prog.LogEntry, duration time.Duration,
}
ctx.reproLogf(2, "testing program (duration=%v, %+v): %s", duration, opts, program)
ctx.reproLogf(3, "detailed listing:\n%s", pstr)
- return ctx.testWithInstance(func(inst *instance.ExecProgInstance) (*instance.RunResult, error) {
- return inst.RunSyzProg(pstr, duration, opts)
+ return ctx.testWithInstance(func(exec execInterface) (*instance.RunResult, error) {
+ return exec.RunSyzProg(pstr, duration, opts)
})
}
func (ctx *context) testCProg(p *prog.Prog, duration time.Duration, opts csource.Options) (crashed bool, err error) {
- return ctx.testWithInstance(func(inst *instance.ExecProgInstance) (*instance.RunResult, error) {
- return inst.RunCProg(p, duration, opts)
+ return ctx.testWithInstance(func(exec execInterface) (*instance.RunResult, error) {
+ return exec.RunCProg(p, duration, opts)
})
}
func (ctx *context) returnInstance(inst *reproInstance) {
ctx.bootRequests <- inst.index
- inst.execProg.VMInstance.Close()
+ inst.execProg.Close()
}
func (ctx *context) reproLogf(level int, format string, args ...interface{}) {