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