]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.fuzz] internal/fuzz: fix two bugs in BenchmarkWorkerFuzzOverhead
authorJay Conrod <jayconrod@google.com>
Mon, 12 Jul 2021 21:31:58 +0000 (14:31 -0700)
committerJay Conrod <jayconrod@google.com>
Mon, 19 Jul 2021 21:11:08 +0000 (21:11 +0000)
* 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 <jayconrod@google.com>
Trust: Katie Hockman <katie@golang.org>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/internal/fuzz/worker.go
src/internal/fuzz/worker_test.go

index c3f4d743023f3f5f3a24f28dee55b14fb76652a5..d8cc10d3d4eea6c76e1f3ad574fa34885674fda3 100644 (file)
@@ -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 {
index 10d61b19db96eb935313652e86a04fbe2c6b9ecd..b536b3db12a8f4628863971d5266a9bd222d079d 100644 (file)
@@ -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})
        }