summaryrefslogtreecommitdiffstats
path: root/src/cmd/go/testdata/script/test_fuzz_non_crash_signal.txt
blob: 94a0421361fd84ecd63cff1d57fd6e7c062980df (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# NOTE: this test is skipped on Windows, since there's no concept of signals.
# When a process terminates another process, it provides an exit code.
[GOOS:windows] skip
[!fuzz] skip
[short] skip
env GOCACHE=$WORK/cache

# FuzzNonCrash sends itself a signal that does not appear to be a crash.
# We should not save a crasher.
! go test -fuzz=FuzzNonCrash
! exists testdata
! stdout unreachable
! stderr unreachable
stdout 'fuzzing process terminated by unexpected signal; no crash will be recorded: signal: terminated'

# FuzzKill sends itself a signal that cannot be caught by the worker process
# and does not appear to be a crash.
# We should not save a crasher.
! go test -fuzz=FuzzKill
! exists testdata
! stdout unreachable
! stderr unreachable
stdout 'fuzzing process terminated by unexpected signal; no crash will be recorded: signal: killed'

# FuzzCrash sends itself a signal that looks like a crash.
# We should save a crasher.
! go test -fuzz=FuzzCrash
exists testdata/fuzz/FuzzCrash
stdout '^\s+fuzzing process hung or terminated unexpectedly: exit status'

-- go.mod --
module test

go 1.17
-- fuzz_posix_test.go --
// +build darwin freebsd linux

package fuzz

import (
	"syscall"
	"testing"
)

func FuzzNonCrash(f *testing.F) {
	f.Fuzz(func(*testing.T, bool) {
		pid := syscall.Getpid()
		if err := syscall.Kill(pid, syscall.SIGTERM); err != nil {
			panic(err)
		}
		// signal may not be received immediately. Wait for it.
		select{}
	})
}

func FuzzKill(f *testing.F) {
	f.Fuzz(func(*testing.T, bool) {
		pid := syscall.Getpid()
		if err := syscall.Kill(pid, syscall.SIGKILL); err != nil {
			panic(err)
		}
		// signal may not be received immediately. Wait for it.
		select{}
	})
}

func FuzzCrash(f *testing.F) {
	f.Fuzz(func(*testing.T, bool) {
		pid := syscall.Getpid()
		if err := syscall.Kill(pid, syscall.SIGILL); err != nil {
			panic(err)
		}
		// signal may not be received immediately. Wait for it.
		select{}
	})
}