aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/test_fuzz_parallel.txt
blob: a49f30a27f917b8837f8e808eda561c769e79eed (plain)
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
# TODO(jayconrod): support shared memory on more platforms.
[!darwin] [!linux] [!windows] skip

[short] skip

# 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

-- 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")
	})
}