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

     1  [!fuzz] skip
     2  [short] skip
     3  env GOCACHE=$WORK/cache
     4  
     5  # Warm up the build cache with GOMAXPROCS unrestricted.
     6  go test -c -o $devnull
     7  
     8  # For the fuzzing phase, we reduce GOMAXPROCS to avoid consuming too many
     9  # resources during the test. Ideally this would just free up resources to run
    10  # other parallel tests more quickly, but unfortunately it is actually necessary
    11  # in some 32-bit environments to prevent the fuzzing engine from running out of
    12  # address space (see https://go.dev/issue/65434).
    13  env GOMAXPROCS=2
    14  
    15  # The fuzz function should be able to detect whether -timeout
    16  # was set with T.Deadline. Note there is no F.Deadline, and
    17  # there is no timeout while fuzzing, even if -fuzztime is set.
    18  go test -run=FuzzDeadline -wantdeadline=true # -timeout defaults to 10m
    19  go test -run=FuzzDeadline -timeout=0 -wantdeadline=false
    20  ! go test -run=FuzzDeadline -timeout=1s -wantdeadline=false
    21  go test -run=FuzzDeadline -timeout=1s -wantdeadline=true
    22  go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=1s -wantdeadline=false
    23  go test -fuzz=FuzzDeadline -timeout=0 -fuzztime=100x -wantdeadline=false
    24  
    25  -- go.mod --
    26  module fuzz
    27  
    28  go 1.16
    29  -- fuzz_deadline_test.go --
    30  package fuzz_test
    31  
    32  import (
    33  	"flag"
    34  	"testing"
    35  )
    36  
    37  var wantDeadline = flag.Bool("wantdeadline", false, "whether the test should have a deadline")
    38  
    39  func FuzzDeadline(f *testing.F) {
    40  	f.Add("run once")
    41  	f.Fuzz(func (t *testing.T, _ string) {
    42  		if _, hasDeadline := t.Deadline(); hasDeadline != *wantDeadline {
    43  			t.Fatalf("function got %v; want %v", hasDeadline, *wantDeadline)
    44  		}
    45  	})
    46  }
    47  

View as plain text