aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/repro
diff options
context:
space:
mode:
authorMarco Vanotti <mvanotti@google.com>2019-11-19 17:04:13 -0800
committerMarco Vanotti <mvanotti@users.noreply.github.com>2019-12-09 15:13:49 -0800
commit4b83c8fbed7b9cea831be880ec8aa1098b465f25 (patch)
tree11d2dbfd4c0a00359c46ec5739c219d3cf0466c8 /pkg/repro
parent31e7766c51de946e7ba7f412a4bb1e402286f226 (diff)
pkg/repro: refactor vm initialization into new fn
This commit moves the instance initialization inside Run() to a subroutine to decrease cyclomatic complexity in the Run function.
Diffstat (limited to 'pkg/repro')
-rw-r--r--pkg/repro/repro.go57
1 files changed, 31 insertions, 26 deletions
diff --git a/pkg/repro/repro.go b/pkg/repro/repro.go
index 2faefe306..3c1c6fba1 100644
--- a/pkg/repro/repro.go
+++ b/pkg/repro/repro.go
@@ -60,6 +60,34 @@ type instance struct {
executorBin string
}
+func initInstance(cfg *mgrconfig.Config, vmPool *vm.Pool, vmIndex int) (*instance, error) {
+ vmInst, err := vmPool.Create(vmIndex)
+ if err != nil {
+ return nil, fmt.Errorf("failed to create VM: %v", err)
+
+ }
+ execprogBin, err := vmInst.Copy(cfg.SyzExecprogBin)
+ if err != nil {
+ vmInst.Close()
+ return nil, fmt.Errorf("failed to copy to VM: %v", err)
+ }
+ executorCmd := targets.Get(cfg.TargetOS, cfg.TargetArch).SyzExecutorCmd
+ if executorCmd == "" {
+ executorCmd, err = vmInst.Copy(cfg.SyzExecutorBin)
+ if err != nil {
+ vmInst.Close()
+ return nil, fmt.Errorf("failed to copy to VM: %v", err)
+ }
+ }
+ return &instance{
+ Instance: vmInst,
+ index: vmIndex,
+ execprogBin: execprogBin,
+ executorBin: executorCmd,
+ }, nil
+
+}
+
func Run(crashLog []byte, cfg *mgrconfig.Config, reporter report.Reporter, vmPool *vm.Pool,
vmIndexes []int) (*Result, *Stats, error) {
if len(vmIndexes) == 0 {
@@ -125,35 +153,12 @@ func Run(crashLog []byte, cfg *mgrconfig.Config, reporter report.Reporter, vmPoo
continue
default:
}
- vmInst, err := vmPool.Create(vmIndex)
+ var err error
+ inst, err = initInstance(cfg, vmPool, vmIndex)
if err != nil {
- ctx.reproLog(0, "failed to create VM: %v", err)
+ ctx.reproLog(0, "failed to init instance: %v", err)
time.Sleep(10 * time.Second)
continue
-
- }
- execprogBin, err := vmInst.Copy(cfg.SyzExecprogBin)
- if err != nil {
- ctx.reproLog(0, "failed to copy to VM: %v", err)
- vmInst.Close()
- time.Sleep(10 * time.Second)
- continue
- }
- executorCmd := targets.Get(cfg.TargetOS, cfg.TargetArch).SyzExecutorCmd
- if executorCmd == "" {
- executorCmd, err = vmInst.Copy(cfg.SyzExecutorBin)
- if err != nil {
- ctx.reproLog(0, "failed to copy to VM: %v", err)
- vmInst.Close()
- time.Sleep(10 * time.Second)
- continue
- }
- }
- inst = &instance{
- Instance: vmInst,
- index: vmIndex,
- execprogBin: execprogBin,
- executorBin: executorCmd,
}
break
}