From 40491a5effaa7bed3d46061d58c9e63b99c7b7cd Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Mon, 12 Jul 2021 14:31:58 -0700 Subject: [PATCH] [dev.fuzz] internal/fuzz: fix two bugs in BenchmarkWorkerFuzzOverhead * The exec count must be set to 0 before calling workerServer.fuzz. This was causing fuzz to run indefinitely after the first benchmark iteration, since it wouldn't hit the termination condition of being equal to fuzzArgs.Limit. * Added an assertion that the count must be lower than fuzzArgs.Limit at the beginning of workerServer.fuzz. * Also closed and deleted shared memory at the end of each benchmark run. Change-Id: Iab465f8a4997ebd652aec04d0ff9bb60b802829e Reviewed-on: https://go-review.googlesource.com/c/go/+/334129 Trust: Jay Conrod Trust: Katie Hockman Run-TryBot: Jay Conrod TryBot-Result: Go Bot Reviewed-by: Katie Hockman --- fuzz/worker.go | 3 +++ fuzz/worker_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/fuzz/worker.go b/fuzz/worker.go index c3f4d74..d8cc10d 100644 --- a/fuzz/worker.go +++ b/fuzz/worker.go @@ -632,6 +632,9 @@ func (ws *workerServer) fuzz(ctx context.Context, args fuzzArgs) (resp fuzzRespo resp.Count = mem.header().count ws.memMu <- mem }() + if args.Limit > 0 && mem.header().count >= args.Limit { + panic(fmt.Sprintf("mem.header().count %d already exceeds args.Limit %d", mem.header().count, args.Limit)) + } vals, err := unmarshalCorpusFile(mem.valueCopy()) if err != nil { diff --git a/fuzz/worker_test.go b/fuzz/worker_test.go index 10d61b1..b536b3d 100644 --- a/fuzz/worker_test.go +++ b/fuzz/worker_test.go @@ -25,6 +25,11 @@ func BenchmarkWorkerFuzzOverhead(b *testing.B) { if err != nil { b.Fatalf("failed to create temporary shared memory file: %s", err) } + defer func() { + if err := mem.Close(); err != nil { + b.Error(err) + } + }() initialVal := []interface{}{make([]byte, 32)} encodedVals := marshalCorpusFile(initialVal...) @@ -36,6 +41,7 @@ func BenchmarkWorkerFuzzOverhead(b *testing.B) { for i := 0; i < b.N; i++ { ws.m = newMutator() mem.setValue(encodedVals) + mem.header().count = 0 ws.fuzz(context.Background(), fuzzArgs{Limit: 1}) }