...
Text file
src/cmd/go/testdata/script/test_fuzz_non_crash_signal.txt
1# NOTE: this test is skipped on Windows, since there's no concept of signals.
2# When a process terminates another process, it provides an exit code.
3[GOOS:windows] skip
4[!fuzz] skip
5[short] skip
6env GOCACHE=$WORK/cache
7
8# FuzzNonCrash sends itself a signal that does not appear to be a crash.
9# We should not save a crasher.
10! go test -fuzz=FuzzNonCrash
11! exists testdata
12! stdout unreachable
13! stderr unreachable
14stdout 'fuzzing process terminated by unexpected signal; no crash will be recorded: signal: terminated'
15
16# FuzzKill sends itself a signal that cannot be caught by the worker process
17# and does not appear to be a crash.
18# We should not save a crasher.
19! go test -fuzz=FuzzKill
20! exists testdata
21! stdout unreachable
22! stderr unreachable
23stdout 'fuzzing process terminated by unexpected signal; no crash will be recorded: signal: killed'
24
25# FuzzCrash sends itself a signal that looks like a crash.
26# We should save a crasher.
27! go test -fuzz=FuzzCrash
28exists testdata/fuzz/FuzzCrash
29stdout '^\s+fuzzing process hung or terminated unexpectedly: exit status'
30
31-- go.mod --
32module test
33
34go 1.17
35-- fuzz_posix_test.go --
36// +build darwin freebsd linux
37
38package fuzz
39
40import (
41 "syscall"
42 "testing"
43)
44
45func FuzzNonCrash(f *testing.F) {
46 f.Fuzz(func(*testing.T, bool) {
47 pid := syscall.Getpid()
48 if err := syscall.Kill(pid, syscall.SIGTERM); err != nil {
49 panic(err)
50 }
51 // signal may not be received immediately. Wait for it.
52 select{}
53 })
54}
55
56func FuzzKill(f *testing.F) {
57 f.Fuzz(func(*testing.T, bool) {
58 pid := syscall.Getpid()
59 if err := syscall.Kill(pid, syscall.SIGKILL); err != nil {
60 panic(err)
61 }
62 // signal may not be received immediately. Wait for it.
63 select{}
64 })
65}
66
67func FuzzCrash(f *testing.F) {
68 f.Fuzz(func(*testing.T, bool) {
69 pid := syscall.Getpid()
70 if err := syscall.Kill(pid, syscall.SIGILL); err != nil {
71 panic(err)
72 }
73 // signal may not be received immediately. Wait for it.
74 select{}
75 })
76}
View as plain text