utls/fuzz/worker_test.go
Jay Conrod 40491a5eff [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 <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>
2021-07-19 21:11:08 +00:00

48 lines
1.1 KiB
Go

// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fuzz
import (
"context"
"fmt"
"os"
"testing"
)
func BenchmarkWorkerFuzzOverhead(b *testing.B) {
origEnv := os.Getenv("GODEBUG")
defer func() { os.Setenv("GODEBUG", origEnv) }()
os.Setenv("GODEBUG", fmt.Sprintf("%s,fuzzseed=123", origEnv))
ws := &workerServer{
fuzzFn: func(_ CorpusEntry) error { return nil },
workerComm: workerComm{memMu: make(chan *sharedMem, 1)},
}
mem, err := sharedMemTempFile(workerSharedMemSize)
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...)
mem.setValue(encodedVals)
ws.memMu <- mem
b.ResetTimer()
for i := 0; i < b.N; i++ {
ws.m = newMutator()
mem.setValue(encodedVals)
mem.header().count = 0
ws.fuzz(context.Background(), fuzzArgs{Limit: 1})
}
}