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

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

View as plain text