...

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

Documentation: cmd/go/testdata/script

     1# Test go build -pgo=auto flag.
     2
     3[short] skip 'compiles and links executables'
     4
     5# Set up fresh GOCACHE.
     6env GOCACHE=$WORK/gocache
     7mkdir $GOCACHE
     8
     9# use default.pgo for a single main package
    10go build -n -pgo=auto -o a1.exe ./a/a1
    11stderr 'preprofile.*-i.*default\.pgo'
    12stderr 'compile.*-pgoprofile=.*a1.go'
    13
    14# check that pgo applied to dependencies
    15stderr '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.
    20stderr '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
    26go build -n -pgo=auto ./a/...
    27stderr 'compile.*-pgoprofile=.*a1.go'
    28
    29# check that pgo appears in build info
    30stderr 'build\\t-pgo=.*default\.pgo'
    31
    32# build succeeds without PGO when default.pgo file is absent
    33go build -n -pgo=auto -o nopgo.exe ./nopgo
    34stderr '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
    41go install -a -n -pgo=auto ./a/a1
    42stderr 'compile.*-pgoprofile=.*a1.go'
    43
    44go run -a -n -pgo=auto ./a/a1
    45stderr 'compile.*-pgoprofile=.*a1.go'
    46
    47go test -a -n -pgo=auto ./a/a1
    48stderr 'compile.*-pgoprofile=.*a1.go.*a1_test.go'
    49stderr 'compile.*-pgoprofile=.*external_test.go'
    50
    51# go list commands should succeed as usual
    52go list -pgo=auto ./a/a1
    53
    54go list -test -pgo=auto ./a/a1
    55
    56go list -deps -pgo=auto ./a/a1
    57
    58# -pgo=auto is the default. Commands without explicit -pgo=auto
    59# should work as -pgo=auto.
    60go build -a -n -o a1.exe ./a/a1
    61stderr 'compile.*-pgoprofile=.*a1.go'
    62stderr 'compile.*-p test/dep.*-pgoprofile=.*'
    63
    64# check that pgo appears in build info
    65stderr 'build\\t-pgo=.*default\.pgo'
    66
    67go build -a -n -o nopgo.exe ./nopgo
    68stderr '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.
    75go build -a -n -pgo=off -o a1.exe ./a/a1
    76stderr '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 --
    83module test
    84go 1.20
    85-- a/a1/a1.go --
    86package main
    87import _ "test/dep"
    88func main() {}
    89-- a/a1/a1_test.go --
    90package main
    91import "testing"
    92func TestA(*testing.T) {}
    93-- a/a1/external_test.go --
    94package main_test
    95import "testing"
    96func TestExternal(*testing.T) {}
    97-- a/a1/default.pgo --
    98-- nopgo/nopgo.go --
    99package main
   100func main() {}
   101-- dep/dep.go --
   102package dep

View as plain text