Source file src/cmd/cgo/internal/testsanitizers/testdata/asan_fuzz_test.go
1 package main 2 3 import ( 4 "slices" 5 "testing" 6 ) 7 8 func Reverse(s string) string { 9 runes := []rune(s) 10 slices.Reverse(runes) 11 return string(runes) 12 } 13 14 // This fuzz test should quickly fail, because Reverse doesn't 15 // work for strings that are not valid UTF-8. 16 // What we are testing for is whether we see a failure from ASAN; 17 // we should see a fuzzing failure, not an ASAN failure. 18 19 func FuzzReverse(f *testing.F) { 20 f.Add("Go") 21 f.Add("Gopher") 22 f.Add("Hello, 世界") 23 f.Fuzz(func(t *testing.T, s string) { 24 r1 := Reverse(s) 25 r2 := Reverse(r1) 26 if s != r2 { 27 t.Errorf("got %q want %q", r2, s) 28 } 29 }) 30 } 31