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