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

     1  # Test go build -pgo=auto flag.
     2  
     3  [short] skip 'compiles and links executables'
     4  
     5  # Set up fresh GOCACHE.
     6  env GOCACHE=$WORK/gocache
     7  mkdir $GOCACHE
     8  
     9  # use default.pgo for a single main package
    10  go build -n -pgo=auto -o a1.exe ./a/a1
    11  stderr 'preprofile.*-i.*default\.pgo'
    12  stderr 'compile.*-pgoprofile=.*a1.go'
    13  
    14  # check that pgo applied to dependencies
    15  stderr 'compile.*-p test/dep.*-pgoprofile=.*'
    16  
    17  # check that pgo appears in build info
    18  # N.B. we can't start the stdout check with -pgo because the script assumes that
    19  # if the first arg starts with - it is a grep flag.
    20  stderr 'build\\t-pgo=.*default\.pgo'
    21  
    22  # check also that -pgo appears with the other flags, before non-flag settings
    23  ! stderr 'build\\t[A-Za-z].*build\\t-pgo'
    24  
    25  # use default.pgo for ... with a single main package
    26  go build -n -pgo=auto ./a/...
    27  stderr 'compile.*-pgoprofile=.*a1.go'
    28  
    29  # check that pgo appears in build info
    30  stderr 'build\\t-pgo=.*default\.pgo'
    31  
    32  # build succeeds without PGO when default.pgo file is absent
    33  go build -n -pgo=auto -o nopgo.exe ./nopgo
    34  stderr 'compile.*nopgo.go'
    35  ! stderr 'compile.*-pgoprofile'
    36  
    37  # check that pgo doesn't appear in build info
    38  ! stderr 'build\\t-pgo='
    39  
    40  # other build-related commands
    41  go install -a -n -pgo=auto ./a/a1
    42  stderr 'compile.*-pgoprofile=.*a1.go'
    43  
    44  go run -a -n -pgo=auto ./a/a1
    45  stderr 'compile.*-pgoprofile=.*a1.go'
    46  
    47  go test -a -n -pgo=auto ./a/a1
    48  stderr 'compile.*-pgoprofile=.*a1.go.*a1_test.go'
    49  stderr 'compile.*-pgoprofile=.*external_test.go'
    50  
    51  # go list commands should succeed as usual
    52  go list -pgo=auto ./a/a1
    53  
    54  go list -test -pgo=auto ./a/a1
    55  
    56  go list -deps -pgo=auto ./a/a1
    57  
    58  # -pgo=auto is the default. Commands without explicit -pgo=auto
    59  # should work as -pgo=auto.
    60  go build -a -n -o a1.exe ./a/a1
    61  stderr 'compile.*-pgoprofile=.*a1.go'
    62  stderr 'compile.*-p test/dep.*-pgoprofile=.*'
    63  
    64  # check that pgo appears in build info
    65  stderr 'build\\t-pgo=.*default\.pgo'
    66  
    67  go build -a -n -o nopgo.exe ./nopgo
    68  stderr 'compile.*nopgo.go'
    69  ! stderr 'compile.*-pgoprofile'
    70  
    71  # check that pgo doesn't appear in build info
    72  ! stderr 'build\\t-pgo='
    73  
    74  # -pgo=off should turn off PGO.
    75  go build -a -n -pgo=off -o a1.exe ./a/a1
    76  stderr 'compile.*a1.go'
    77  ! stderr 'compile.*-pgoprofile'
    78  
    79  # check that pgo doesn't appear in build info
    80  ! stderr 'build\\t-pgo='
    81  
    82  -- go.mod --
    83  module test
    84  go 1.20
    85  -- a/a1/a1.go --
    86  package main
    87  import _ "test/dep"
    88  func main() {}
    89  -- a/a1/a1_test.go --
    90  package main
    91  import "testing"
    92  func TestA(*testing.T) {}
    93  -- a/a1/external_test.go --
    94  package main_test
    95  import "testing"
    96  func TestExternal(*testing.T) {}
    97  -- a/a1/default.pgo --
    98  -- nopgo/nopgo.go --
    99  package main
   100  func main() {}
   101  -- dep/dep.go --
   102  package dep
   103  

View as plain text