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