File size: 1,622 Bytes
e36aeda | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | [!fuzz] skip
[short] skip
env GOCACHE=$WORK/cache
# When running seed inputs, T.Parallel should let multiple inputs run in
# parallel.
go test -run=FuzzSeed
# When fuzzing, T.Parallel should be safe to call, but it should have no effect.
# We just check that it doesn't hang, which would be the most obvious
# failure mode.
# TODO(jayconrod): check for the string "after T.Parallel". It's not printed
# by 'go test', so we can't distinguish that crasher from some other panic.
! go test -run=FuzzMutate -fuzz=FuzzMutate
exists testdata/fuzz/FuzzMutate
# Testdata should now contain a corpus entry which will fail FuzzMutate.
# Run the test without fuzzing, setting -parallel to different values to make
# sure it fails, and doesn't hang.
! go test -run=FuzzMutate -parallel=1
! go test -run=FuzzMutate -parallel=2
! go test -run=FuzzMutate -parallel=4
-- go.mod --
module fuzz_parallel
go 1.17
-- fuzz_parallel_test.go --
package fuzz_parallel
import (
"sort"
"sync"
"testing"
)
func FuzzSeed(f *testing.F) {
for _, v := range [][]byte{{'a'}, {'b'}, {'c'}} {
f.Add(v)
}
var mu sync.Mutex
var before, after []byte
f.Cleanup(func() {
sort.Slice(after, func(i, j int) bool { return after[i] < after[j] })
got := string(before) + string(after)
want := "abcabc"
if got != want {
f.Fatalf("got %q; want %q", got, want)
}
})
f.Fuzz(func(t *testing.T, b []byte) {
before = append(before, b...)
t.Parallel()
mu.Lock()
after = append(after, b...)
mu.Unlock()
})
}
func FuzzMutate(f *testing.F) {
f.Fuzz(func(t *testing.T, _ []byte) {
t.Parallel()
t.Error("after T.Parallel")
})
}
|