...
1[!fuzz] skip
2[short] skip
3env GOCACHE=$WORK/cache
4
5# Test that running a fuzz target that returns without failing or calling
6# f.Fuzz fails and causes a non-zero exit status.
7! go test noop_fuzz_test.go
8! stdout ^ok
9stdout FAIL
10
11# Test that fuzzing a fuzz target that returns without failing or calling
12# f.Fuzz fails and causes a non-zero exit status.
13! go test -fuzz=Fuzz -fuzztime=1x noop_fuzz_test.go
14! stdout ^ok
15stdout FAIL
16
17# Test that calling f.Error in a fuzz target causes a non-zero exit status.
18! go test -fuzz=Fuzz -fuzztime=1x error_fuzz_test.go
19! stdout ^ok
20stdout FAIL
21
22# Test that calling f.Fatal in a fuzz target causes a non-zero exit status.
23! go test fatal_fuzz_test.go
24! stdout ^ok
25stdout FAIL
26
27# Test that successful test exits cleanly.
28go test success_fuzz_test.go
29stdout ^ok
30! stdout FAIL
31
32# Test that successful fuzzing exits cleanly.
33go test -fuzz=Fuzz -fuzztime=1x success_fuzz_test.go
34stdout ok
35! stdout FAIL
36
37# Test that calling f.Fatal while fuzzing causes a non-zero exit status.
38! go test -fuzz=Fuzz -fuzztime=1x fatal_fuzz_test.go
39! stdout ^ok
40stdout FAIL
41
42# Test error with seed corpus in f.Fuzz
43! go test -run FuzzError fuzz_add_test.go
44! stdout ^ok
45stdout FAIL
46stdout 'error here'
47
48[short] stop
49
50# Test that calling panic(nil) in a fuzz target causes a non-zero exit status.
51! go test panic_fuzz_test.go
52! stdout ^ok
53stdout FAIL
54
55# Test that skipped test exits cleanly.
56go test skipped_fuzz_test.go
57stdout ok
58! stdout FAIL
59
60# Test that f.Fatal within f.Fuzz panics
61! go test fatal_fuzz_fn_fuzz_test.go
62! stdout ^ok
63! stdout 'fatal here'
64stdout FAIL
65stdout 'fuzz target'
66
67# Test that f.Error within f.Fuzz panics
68! go test error_fuzz_fn_fuzz_test.go
69! stdout ^ok
70! stdout 'error here'
71stdout FAIL
72stdout 'fuzz target'
73
74# Test that f.Fail within f.Fuzz panics
75! go test fail_fuzz_fn_fuzz_test.go
76! stdout ^ok
77stdout FAIL
78stdout 'fuzz target'
79
80# Test that f.Skip within f.Fuzz panics
81! go test skip_fuzz_fn_fuzz_test.go
82! stdout ^ok
83! stdout 'skip here'
84stdout FAIL
85stdout 'fuzz target'
86
87# Test that f.Skipped within f.Fuzz panics
88! go test skipped_fuzz_fn_fuzz_test.go
89! stdout ^ok
90! stdout 'f.Skipped is'
91stdout FAIL
92stdout 'fuzz target'
93stdout 't.Skipped is false'
94
95# Test that runtime.Goexit within the fuzz function is an error.
96! go test goexit_fuzz_fn_fuzz_test.go
97! stdout ^ok
98stdout FAIL
99
100# Test that a call to f.Fatal after the Fuzz func is executed.
101! go test fatal_after_fuzz_func_fuzz_test.go
102! stdout ok
103stdout FAIL
104
105# Test that missing *T in f.Fuzz causes a non-zero exit status.
106! go test incomplete_fuzz_call_fuzz_test.go
107! stdout ^ok
108stdout FAIL
109
110# Test that a panic in the Cleanup func is executed.
111! go test cleanup_fuzz_test.go
112! stdout ^ok
113stdout FAIL
114stdout 'failed some precondition'
115
116# Test success with seed corpus in f.Fuzz
117go test -run FuzzPass fuzz_add_test.go
118stdout ok
119! stdout FAIL
120! stdout 'off by one error'
121
122# Test fatal with seed corpus in f.Fuzz
123! go test -run FuzzFatal fuzz_add_test.go
124! stdout ^ok
125stdout FAIL
126stdout 'fatal here'
127
128# Test panic with seed corpus in f.Fuzz
129! go test -run FuzzPanic fuzz_add_test.go
130! stdout ^ok
131stdout FAIL
132stdout 'off by one error'
133
134# Test panic(nil) with seed corpus in f.Fuzz
135! go test -run FuzzNilPanic fuzz_add_test.go
136! stdout ^ok
137stdout FAIL
138
139# Test panic with unsupported seed corpus
140! go test -run FuzzUnsupported fuzz_add_test.go
141! stdout ^ok
142stdout FAIL
143
144# Test panic with different number of args to f.Add
145! go test -run FuzzAddDifferentNumber fuzz_add_test.go
146! stdout ^ok
147stdout FAIL
148
149# Test panic with different type of args to f.Add
150! go test -run FuzzAddDifferentType fuzz_add_test.go
151! stdout ^ok
152stdout FAIL
153
154# Test that the wrong type given with f.Add will fail.
155! go test -run FuzzWrongType fuzz_add_test.go
156! stdout ^ok
157stdout '\[string int\], want \[\[\]uint8 int8\]'
158stdout FAIL
159
160# Test fatal with testdata seed corpus
161! go test -run FuzzFail corpustesting/fuzz_testdata_corpus_test.go
162! stdout ^ok
163stdout FAIL
164stdout 'fatal here'
165
166# Test pass with testdata seed corpus
167go test -run FuzzPass corpustesting/fuzz_testdata_corpus_test.go
168stdout ok
169! stdout FAIL
170! stdout 'fatal here'
171
172# Test pass with testdata and f.Add seed corpus
173go test -run FuzzPassString corpustesting/fuzz_testdata_corpus_test.go
174stdout ok
175! stdout FAIL
176
177# Fuzzing pass with testdata and f.Add seed corpus (skip running tests first)
178go test -run=None -fuzz=FuzzPassString corpustesting/fuzz_testdata_corpus_test.go -fuzztime=10x
179stdout ok
180! stdout FAIL
181
182# Fuzzing pass with testdata and f.Add seed corpus
183go test -run=FuzzPassString -fuzz=FuzzPassString corpustesting/fuzz_testdata_corpus_test.go -fuzztime=10x
184stdout ok
185! stdout FAIL
186
187# Test panic with malformed seed corpus
188! go test -run FuzzFail corpustesting/fuzz_testdata_corpus_test.go
189! stdout ^ok
190stdout FAIL
191
192# Test pass with file in other nested testdata directory
193go test -run FuzzInNestedDir corpustesting/fuzz_testdata_corpus_test.go
194stdout ok
195! stdout FAIL
196! stdout 'fatal here'
197
198# Test fails with file containing wrong type
199! go test -run FuzzWrongType corpustesting/fuzz_testdata_corpus_test.go
200! stdout ^ok
201stdout FAIL
202
203-- noop_fuzz_test.go --
204package noop_fuzz
205
206import "testing"
207
208func Fuzz(f *testing.F) {}
209
210-- error_fuzz_test.go --
211package error_fuzz
212
213import "testing"
214
215func Fuzz(f *testing.F) {
216 f.Error("error in target")
217}
218
219-- fatal_fuzz_test.go --
220package fatal_fuzz
221
222import "testing"
223
224func Fuzz(f *testing.F) {
225 f.Fatal("fatal in target")
226}
227
228-- panic_fuzz_test.go --
229package panic_fuzz
230
231import "testing"
232
233func FuzzPanic(f *testing.F) {
234 panic(nil)
235}
236
237-- success_fuzz_test.go --
238package success_fuzz
239
240import "testing"
241
242func Fuzz(f *testing.F) {
243 f.Fuzz(func (*testing.T, []byte) {})
244}
245
246-- skipped_fuzz_test.go --
247package skipped_fuzz
248
249import "testing"
250
251func Fuzz(f *testing.F) {
252 f.Skip()
253}
254
255-- fatal_fuzz_fn_fuzz_test.go --
256package fatal_fuzz_fn_fuzz
257
258import "testing"
259
260func Fuzz(f *testing.F) {
261 f.Add([]byte("aa"))
262 f.Fuzz(func(t *testing.T, b []byte) {
263 f.Fatal("fatal here")
264 })
265}
266
267-- error_fuzz_fn_fuzz_test.go --
268package error_fuzz_fn_fuzz
269
270import "testing"
271
272func Fuzz(f *testing.F) {
273 f.Add([]byte("aa"))
274 f.Fuzz(func(t *testing.T, b []byte) {
275 f.Error("error here")
276 })
277}
278
279-- fail_fuzz_fn_fuzz_test.go --
280package skip_fuzz_fn_fuzz
281
282import "testing"
283
284func Fuzz(f *testing.F) {
285 f.Add([]byte("aa"))
286 f.Fuzz(func(t *testing.T, b []byte) {
287 f.Fail()
288 })
289}
290
291-- skip_fuzz_fn_fuzz_test.go --
292package skip_fuzz_fn_fuzz
293
294import "testing"
295
296func Fuzz(f *testing.F) {
297 f.Add([]byte("aa"))
298 f.Fuzz(func(t *testing.T, b []byte) {
299 f.Skip("skip here")
300 })
301}
302
303-- skipped_fuzz_fn_fuzz_test.go --
304package skipped_fuzz_fn_fuzz
305
306import "testing"
307
308func Fuzz(f *testing.F) {
309 f.Add([]byte("aa"))
310 f.Fuzz(func(t *testing.T, b []byte) {
311 t.Logf("t.Skipped is %t\n", t.Skipped())
312 t.Logf("f.Skipped is %t\n", f.Skipped())
313 })
314}
315
316-- goexit_fuzz_fn_fuzz_test.go --
317package goexit_fuzz_fn_fuzz
318
319import "testing"
320
321func Fuzz(f *testing.F) {
322 f.Add([]byte("aa"))
323 f.Fuzz(func(t *testing.T, b []byte) {
324 runtime.Goexit()
325 })
326}
327
328-- fatal_after_fuzz_func_fuzz_test.go --
329package fatal_after_fuzz_func_fuzz
330
331import "testing"
332
333func Fuzz(f *testing.F) {
334 f.Fuzz(func(t *testing.T, b []byte) {
335 // no-op
336 })
337 f.Fatal("this shouldn't be called")
338}
339
340-- incomplete_fuzz_call_fuzz_test.go --
341package incomplete_fuzz_call_fuzz
342
343import "testing"
344
345func Fuzz(f *testing.F) {
346 f.Fuzz(func(b []byte) {
347 // this is missing *testing.T as the first param, so should panic
348 })
349}
350
351-- cleanup_fuzz_test.go --
352package cleanup_fuzz_test
353
354import "testing"
355
356func Fuzz(f *testing.F) {
357 f.Cleanup(func() {
358 panic("failed some precondition")
359 })
360 f.Fuzz(func(t *testing.T, b []byte) {
361 // no-op
362 })
363}
364
365-- fuzz_add_test.go --
366package fuzz_add
367
368import "testing"
369
370func add(f *testing.F) {
371 f.Helper()
372 f.Add([]byte("123"))
373 f.Add([]byte("12345"))
374 f.Add([]byte(""))
375}
376
377func FuzzPass(f *testing.F) {
378 add(f)
379 f.Fuzz(func(t *testing.T, b []byte) {
380 if len(b) == -1 {
381 t.Fatal("fatal here") // will not be executed
382 }
383 })
384}
385
386func FuzzError(f *testing.F) {
387 add(f)
388 f.Fuzz(func(t *testing.T, b []byte) {
389 if len(b) == 3 {
390 t.Error("error here")
391 }
392 })
393}
394
395func FuzzFatal(f *testing.F) {
396 add(f)
397 f.Fuzz(func(t *testing.T, b []byte) {
398 if len(b) == 0 {
399 t.Fatal("fatal here")
400 }
401 })
402}
403
404func FuzzPanic(f *testing.F) {
405 add(f)
406 f.Fuzz(func(t *testing.T, b []byte) {
407 if len(b) == 5 {
408 panic("off by one error")
409 }
410 })
411}
412
413func FuzzNilPanic(f *testing.F) {
414 add(f)
415 f.Fuzz(func(t *testing.T, b []byte) {
416 if len(b) == 3 {
417 panic(nil)
418 }
419 })
420}
421
422func FuzzUnsupported(f *testing.F) {
423 m := make(map[string]bool)
424 f.Add(m)
425 f.Fuzz(func(*testing.T, []byte) {})
426}
427
428func FuzzAddDifferentNumber(f *testing.F) {
429 f.Add([]byte("a"))
430 f.Add([]byte("a"), []byte("b"))
431 f.Fuzz(func(*testing.T, []byte) {})
432}
433
434func FuzzAddDifferentType(f *testing.F) {
435 f.Add(false)
436 f.Add(1234)
437 f.Fuzz(func(*testing.T, []byte) {})
438}
439
440func FuzzWrongType(f *testing.F) {
441 f.Add("hello", 50)
442 f.Fuzz(func(*testing.T, []byte, int8) {})
443}
444
445-- corpustesting/fuzz_testdata_corpus_test.go --
446package fuzz_testdata_corpus
447
448import "testing"
449
450func fuzzFn(f *testing.F) {
451 f.Helper()
452 f.Fuzz(func(t *testing.T, b []byte) {
453 if string(b) == "12345" {
454 t.Fatal("fatal here")
455 }
456 })
457}
458
459func FuzzFail(f *testing.F) {
460 fuzzFn(f)
461}
462
463func FuzzPass(f *testing.F) {
464 fuzzFn(f)
465}
466
467func FuzzPassString(f *testing.F) {
468 f.Add("some seed corpus")
469 f.Fuzz(func(*testing.T, string) {})
470}
471
472func FuzzPanic(f *testing.F) {
473 f.Fuzz(func(t *testing.T, b []byte) {})
474}
475
476func FuzzInNestedDir(f *testing.F) {
477 f.Fuzz(func(t *testing.T, b []byte) {})
478}
479
480func FuzzWrongType(f *testing.F) {
481 f.Fuzz(func(t *testing.T, b []byte) {})
482}
483
484-- corpustesting/testdata/fuzz/FuzzFail/1 --
485go test fuzz v1
486[]byte("12345")
487-- corpustesting/testdata/fuzz/FuzzPass/1 --
488go test fuzz v1
489[]byte("00000")
490-- corpustesting/testdata/fuzz/FuzzPassString/1 --
491go test fuzz v1
492string("hello")
493-- corpustesting/testdata/fuzz/FuzzPanic/1 --
494malformed
495-- corpustesting/testdata/fuzz/FuzzInNestedDir/anotherdir/1 --
496go test fuzz v1
497[]byte("12345")
498-- corpustesting/testdata/fuzz/FuzzWrongType/1 --
499go test fuzz v1
500int("00000")
View as plain text