Text file src/cmd/go/testdata/script/test_fuzz.txt

     1  [!fuzz] skip
     2  [short] skip
     3  env 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
     9  stdout 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
    15  stdout 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
    20  stdout 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
    25  stdout FAIL
    26  
    27  # Test that successful test exits cleanly.
    28  go test success_fuzz_test.go
    29  stdout ^ok
    30  ! stdout FAIL
    31  
    32  # Test that successful fuzzing exits cleanly.
    33  go test -fuzz=Fuzz -fuzztime=1x success_fuzz_test.go
    34  stdout 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
    40  stdout FAIL
    41  
    42  # Test error with seed corpus in f.Fuzz
    43  ! go test -run FuzzError fuzz_add_test.go
    44  ! stdout ^ok
    45  stdout FAIL
    46  stdout '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
    53  stdout FAIL
    54  
    55  # Test that skipped test exits cleanly.
    56  go test skipped_fuzz_test.go
    57  stdout 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'
    64  stdout FAIL
    65  stdout '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'
    71  stdout FAIL
    72  stdout 'fuzz target'
    73  
    74  # Test that f.Fail within f.Fuzz panics
    75  ! go test fail_fuzz_fn_fuzz_test.go
    76  ! stdout ^ok
    77  stdout FAIL
    78  stdout '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'
    84  stdout FAIL
    85  stdout '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'
    91  stdout FAIL
    92  stdout 'fuzz target'
    93  stdout '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
    98  stdout 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
   103  stdout 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
   108  stdout FAIL
   109  
   110  # Test that a panic in the Cleanup func is executed.
   111  ! go test cleanup_fuzz_test.go
   112  ! stdout ^ok
   113  stdout FAIL
   114  stdout 'failed some precondition'
   115  
   116  # Test success with seed corpus in f.Fuzz
   117  go test -run FuzzPass fuzz_add_test.go
   118  stdout 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
   125  stdout FAIL
   126  stdout 'fatal here'
   127  
   128  # Test panic with seed corpus in f.Fuzz
   129  ! go test -run FuzzPanic fuzz_add_test.go
   130  ! stdout ^ok
   131  stdout FAIL
   132  stdout '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
   137  stdout FAIL
   138  
   139  # Test panic with unsupported seed corpus
   140  ! go test -run FuzzUnsupported fuzz_add_test.go
   141  ! stdout ^ok
   142  stdout 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
   147  stdout 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
   152  stdout 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
   157  stdout '\[string int\], want \[\[\]uint8 int8\]'
   158  stdout FAIL
   159  
   160  # Test fatal with testdata seed corpus
   161  ! go test -run FuzzFail corpustesting/fuzz_testdata_corpus_test.go
   162  ! stdout ^ok
   163  stdout FAIL
   164  stdout 'fatal here'
   165  
   166  # Test pass with testdata seed corpus
   167  go test -run FuzzPass corpustesting/fuzz_testdata_corpus_test.go
   168  stdout ok
   169  ! stdout FAIL
   170  ! stdout 'fatal here'
   171  
   172  # Test pass with testdata and f.Add seed corpus
   173  go test -run FuzzPassString corpustesting/fuzz_testdata_corpus_test.go
   174  stdout ok
   175  ! stdout FAIL
   176  
   177  # Fuzzing pass with testdata and f.Add seed corpus (skip running tests first)
   178  go test -run=None -fuzz=FuzzPassString corpustesting/fuzz_testdata_corpus_test.go -fuzztime=10x
   179  stdout ok
   180  ! stdout FAIL
   181  
   182  # Fuzzing pass with testdata and f.Add seed corpus
   183  go test -run=FuzzPassString -fuzz=FuzzPassString corpustesting/fuzz_testdata_corpus_test.go -fuzztime=10x
   184  stdout 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
   190  stdout FAIL
   191  
   192  # Test pass with file in other nested testdata directory
   193  go test -run FuzzInNestedDir corpustesting/fuzz_testdata_corpus_test.go
   194  stdout 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
   201  stdout FAIL
   202  
   203  -- noop_fuzz_test.go --
   204  package noop_fuzz
   205  
   206  import "testing"
   207  
   208  func Fuzz(f *testing.F) {}
   209  
   210  -- error_fuzz_test.go --
   211  package error_fuzz
   212  
   213  import "testing"
   214  
   215  func Fuzz(f *testing.F) {
   216      f.Error("error in target")
   217  }
   218  
   219  -- fatal_fuzz_test.go --
   220  package fatal_fuzz
   221  
   222  import "testing"
   223  
   224  func Fuzz(f *testing.F) {
   225      f.Fatal("fatal in target")
   226  }
   227  
   228  -- panic_fuzz_test.go --
   229  package panic_fuzz
   230  
   231  import "testing"
   232  
   233  func FuzzPanic(f *testing.F) {
   234      panic(nil)
   235  }
   236  
   237  -- success_fuzz_test.go --
   238  package success_fuzz
   239  
   240  import "testing"
   241  
   242  func Fuzz(f *testing.F) {
   243      f.Fuzz(func (*testing.T, []byte) {})
   244  }
   245  
   246  -- skipped_fuzz_test.go --
   247  package skipped_fuzz
   248  
   249  import "testing"
   250  
   251  func Fuzz(f *testing.F) {
   252      f.Skip()
   253  }
   254  
   255  -- fatal_fuzz_fn_fuzz_test.go --
   256  package fatal_fuzz_fn_fuzz
   257  
   258  import "testing"
   259  
   260  func 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 --
   268  package error_fuzz_fn_fuzz
   269  
   270  import "testing"
   271  
   272  func 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 --
   280  package skip_fuzz_fn_fuzz
   281  
   282  import "testing"
   283  
   284  func 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 --
   292  package skip_fuzz_fn_fuzz
   293  
   294  import "testing"
   295  
   296  func 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 --
   304  package skipped_fuzz_fn_fuzz
   305  
   306  import "testing"
   307  
   308  func 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 --
   317  package goexit_fuzz_fn_fuzz
   318  
   319  import "testing"
   320  
   321  func 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 --
   329  package fatal_after_fuzz_func_fuzz
   330  
   331  import "testing"
   332  
   333  func 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 --
   341  package incomplete_fuzz_call_fuzz
   342  
   343  import "testing"
   344  
   345  func 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 --
   352  package cleanup_fuzz_test
   353  
   354  import "testing"
   355  
   356  func 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 --
   366  package fuzz_add
   367  
   368  import "testing"
   369  
   370  func add(f *testing.F) {
   371      f.Helper()
   372      f.Add([]byte("123"))
   373      f.Add([]byte("12345"))
   374      f.Add([]byte(""))
   375  }
   376  
   377  func 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  
   386  func 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  
   395  func 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  
   404  func 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  
   413  func 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  
   422  func FuzzUnsupported(f *testing.F) {
   423      m := make(map[string]bool)
   424      f.Add(m)
   425      f.Fuzz(func(*testing.T, []byte) {})
   426  }
   427  
   428  func 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  
   434  func FuzzAddDifferentType(f *testing.F) {
   435      f.Add(false)
   436      f.Add(1234)
   437      f.Fuzz(func(*testing.T, []byte) {})
   438  }
   439  
   440  func 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 --
   446  package fuzz_testdata_corpus
   447  
   448  import "testing"
   449  
   450  func 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  
   459  func FuzzFail(f *testing.F) {
   460      fuzzFn(f)
   461  }
   462  
   463  func FuzzPass(f *testing.F) {
   464      fuzzFn(f)
   465  }
   466  
   467  func FuzzPassString(f *testing.F) {
   468      f.Add("some seed corpus")
   469      f.Fuzz(func(*testing.T, string) {})
   470  }
   471  
   472  func FuzzPanic(f *testing.F) {
   473      f.Fuzz(func(t *testing.T, b []byte) {})
   474  }
   475  
   476  func FuzzInNestedDir(f *testing.F) {
   477      f.Fuzz(func(t *testing.T, b []byte) {})
   478  }
   479  
   480  func FuzzWrongType(f *testing.F) {
   481      f.Fuzz(func(t *testing.T, b []byte) {})
   482  }
   483  
   484  -- corpustesting/testdata/fuzz/FuzzFail/1 --
   485  go test fuzz v1
   486  []byte("12345")
   487  -- corpustesting/testdata/fuzz/FuzzPass/1 --
   488  go test fuzz v1
   489  []byte("00000")
   490  -- corpustesting/testdata/fuzz/FuzzPassString/1 --
   491  go test fuzz v1
   492  string("hello")
   493  -- corpustesting/testdata/fuzz/FuzzPanic/1 --
   494  malformed
   495  -- corpustesting/testdata/fuzz/FuzzInNestedDir/anotherdir/1 --
   496  go test fuzz v1
   497  []byte("12345")
   498  -- corpustesting/testdata/fuzz/FuzzWrongType/1 --
   499  go test fuzz v1
   500  int("00000")
   501  

View as plain text