aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2018-07-31 17:05:43 +0200
committerDmitry Vyukov <dvyukov@google.com>2018-07-31 18:43:50 +0200
commitba6c552acdce01730ee9d3601702a7614ca1a021 (patch)
treefccb4d0aafd875575c5e64bf63fdc73f2b37cca4
parent97bce4e2ceff482b90b658dc9031cc0c5705cad1 (diff)
syz-manager: refactor vmLoop
Slightly reduce cyclomatic complexity. Update #538
-rw-r--r--syz-manager/manager.go52
1 files changed, 25 insertions, 27 deletions
diff --git a/syz-manager/manager.go b/syz-manager/manager.go
index 5e78ea5ab..86bbf8e28 100644
--- a/syz-manager/manager.go
+++ b/syz-manager/manager.go
@@ -327,7 +327,7 @@ func (mgr *Manager) vmLoop() {
reproDone := make(chan *ReproResult, 1)
stopPending := false
shutdown := vm.Shutdown
- for {
+ for shutdown != nil || len(instances) != vmCount {
mgr.mu.Lock()
phase := mgr.phase
mgr.mu.Unlock()
@@ -337,25 +337,8 @@ func (mgr *Manager) vmLoop() {
continue
}
delete(pendingRepro, crash)
- if !crash.hub {
- if mgr.dash == nil {
- if !mgr.needRepro(crash) {
- continue
- }
- } else {
- cid := &dashapi.CrashID{
- BuildID: mgr.cfg.Tag,
- Title: crash.Title,
- Corrupted: crash.Corrupted,
- }
- needRepro, err := mgr.dash.NeedRepro(cid)
- if err != nil {
- log.Logf(0, "dashboard.NeedRepro failed: %v", err)
- }
- if !needRepro {
- continue
- }
- }
+ if !mgr.needRepro(crash) {
+ continue
}
log.Logf(1, "loop: add to repro queue '%v'", crash.Title)
reproducing[crash.Title] = true
@@ -371,11 +354,7 @@ func (mgr *Manager) vmLoop() {
len(reproQueue) != 0 && reproInstances+instancesPerRepro <= vmCount
}
- if shutdown == nil {
- if len(instances) == vmCount {
- return
- }
- } else {
+ if shutdown != nil {
for canRepro() && len(instances) >= instancesPerRepro {
last := len(reproQueue) - 1
crash := reproQueue[last]
@@ -696,12 +675,12 @@ func (mgr *Manager) saveCrash(crash *Crash) bool {
osutil.WriteFile(filepath.Join(dir, fmt.Sprintf("report%v", oldestI)), crash.Report.Report)
}
- return mgr.needRepro(crash)
+ return mgr.needLocalRepro(crash)
}
const maxReproAttempts = 3
-func (mgr *Manager) needRepro(crash *Crash) bool {
+func (mgr *Manager) needLocalRepro(crash *Crash) bool {
if !mgr.cfg.Reproduce || crash.Corrupted {
return false
}
@@ -718,6 +697,25 @@ func (mgr *Manager) needRepro(crash *Crash) bool {
return false
}
+func (mgr *Manager) needRepro(crash *Crash) bool {
+ if crash.hub {
+ return true
+ }
+ if mgr.dash == nil {
+ return mgr.needLocalRepro(crash)
+ }
+ cid := &dashapi.CrashID{
+ BuildID: mgr.cfg.Tag,
+ Title: crash.Title,
+ Corrupted: crash.Corrupted,
+ }
+ needRepro, err := mgr.dash.NeedRepro(cid)
+ if err != nil {
+ log.Logf(0, "dashboard.NeedRepro failed: %v", err)
+ }
+ return needRepro
+}
+
func (mgr *Manager) saveFailedRepro(desc string, stats *repro.Stats) {
if mgr.dash != nil {
cid := &dashapi.CrashID{