Skip to content

Commit 904e669

Browse files
committed
pkg/fuzzer: improve TestFuzz
Ensure that corpus and signal are non-zero after the bugs have been found. Fix coverage configuration - the test was de facto running on a fallback coverage.
1 parent 37880f4 commit 904e669

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/fuzzer/fuzzer_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,9 @@ func (f *testFuzzer) run() {
164164
Config: rpcserver.Config{
165165
Config: vminfo.Config{
166166
Debug: true,
167+
Cover: true,
167168
Target: f.target,
168-
Features: flatrpc.FeatureSandboxNone,
169+
Features: flatrpc.FeatureSandboxNone | flatrpc.FeatureCoverage,
169170
Sandbox: flatrpc.ExecEnvSandboxNone,
170171
},
171172
Procs: 4,
@@ -176,14 +177,15 @@ func (f *testFuzzer) run() {
176177
OutputWriter: &output,
177178
}
178179
cfg.MachineChecked = func(features flatrpc.Feature, syscalls map[*prog.Syscall]bool) queue.Source {
179-
cfg.Cover = true
180180
return f
181181
}
182182
if err := rpcserver.RunLocal(ctx, cfg); err != nil {
183183
f.t.Logf("executor output:\n%s", output.String())
184184
f.t.Fatal(err)
185185
}
186186
assert.Equal(f.t, len(f.expectedCrashes), len(f.crashes), "not all expected crashes were found")
187+
assert.NotEmpty(f.t, f.fuzzer.Config.Corpus.StatProgs.Val(), "must have non-empty corpus")
188+
assert.NotEmpty(f.t, f.fuzzer.Config.Corpus.StatSignal.Val(), "must have non-empty signal")
187189
}
188190

189191
func (f *testFuzzer) Next() *queue.Request {
@@ -218,12 +220,16 @@ func (f *testFuzzer) OnDone(req *queue.Request, res *queue.Result) bool {
218220
f.crashes[crash]++
219221
}
220222
f.iter++
223+
corpusProgs := f.fuzzer.Config.Corpus.StatProgs.Val()
224+
signal := f.fuzzer.Config.Corpus.StatSignal.Val()
221225
if f.iter%100 == 0 {
222226
f.t.Logf("<iter %d>: corpus %d, signal %d, max signal %d, crash types %d, running jobs %d",
223-
f.iter, f.fuzzer.Config.Corpus.StatProgs.Val(), f.fuzzer.Config.Corpus.StatSignal.Val(),
224-
len(f.fuzzer.Cover.maxSignal), len(f.crashes), f.fuzzer.statJobs.Val())
227+
f.iter, corpusProgs, signal, len(f.fuzzer.Cover.maxSignal),
228+
len(f.crashes), f.fuzzer.statJobs.Val())
225229
}
226-
if f.iter > f.iterLimit || len(f.crashes) == len(f.expectedCrashes) {
230+
criteriaMet := len(f.crashes) == len(f.expectedCrashes) &&
231+
corpusProgs > 0 && signal > 0
232+
if f.iter > f.iterLimit || criteriaMet {
227233
f.done()
228234
f.finished.Store(true)
229235
}

0 commit comments

Comments
 (0)