1 # Test go build -pgo=auto flag with multiple main packages.
2
3 go install -a -n -pgo=auto ./a ./b ./nopgo
4
5 # a/default.pgo applies to package a and (transitive)
6 # dependencies.
7 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*a(/|\\\\)a\.go'
8 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
9 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep2(/|\\\\)dep2\.go'
10 stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep3(/|\\\\)dep3\.go'
11
12 # b/default.pgo applies to package b and (transitive)
13 # dependencies.
14 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*b(/|\\\\)b\.go'
15 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
16 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep2(/|\\\\)dep2\.go'
17 stderr -count=1 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep3(/|\\\\)dep3\.go'
18
19 # nopgo should be built without PGO.
20 ! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo\.go'
21
22 # Dependencies should also be built without PGO.
23 # Here we want to match a compile action without -pgoprofile,
24 # by matching 3 occurrences of "compile dep.go", among which
25 # 2 of them have -pgoprofile (therefore one without).
26 stderr -count=3 'compile.*dep(/|\\\\)dep.go'
27 stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go'
28
29 stderr -count=3 'compile.*dep2(/|\\\\)dep2.go'
30 stderr -count=2 'compile.*-pgoprofile=.*dep2(/|\\\\)dep2\.go'
31
32 stderr -count=3 'compile.*dep3(/|\\\\)dep3.go'
33 stderr -count=2 'compile.*-pgoprofile=.*dep3(/|\\\\)dep3\.go'
34
35 # check that pgo appears or not in build info as expected
36 stderr 'path\\ttest/a\\n.*build\\t-pgo=.*a(/|\\\\)default\.pgo'
37 stderr 'path\\ttest/b\\n.*build\\t-pgo=.*b(/|\\\\)default\.pgo'
38 ! stderr 'path\\ttest/nopgo\\n.*build\\t-pgo='
39
40 # go test works the same way
41 go test -a -n -pgo=auto ./a ./b ./nopgo
42 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*a(/|\\\\)a_test\.go'
43 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
44 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*b(/|\\\\)b_test\.go'
45 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
46 ! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo_test\.go'
47
48 # test-only dependencies also have profiles attached
49 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*testdep(/|\\\\)testdep\.go'
50 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*testdep(/|\\\\)testdep\.go'
51 stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*testdep2(/|\\\\)testdep2\.go'
52 stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*testdep2(/|\\\\)testdep2\.go'
53
54 # go list -deps prints packages built multiple times.
55 go list -pgo=auto -deps ./a ./b ./nopgo
56 stdout 'test/dep \[test/a\]'
57 stdout 'test/dep \[test/b\]'
58 stdout 'test/dep$'
59
60 # Here we have 3 main packages, a, b, and nopgo, where a and b each has
61 # its own default.pgo profile, and nopgo has none.
62 # All 3 main packages import dep and dep2, both of which then import dep3
63 # (a diamond-shape import graph).
64 -- go.mod --
65 module test
66 go 1.20
67 -- a/a.go --
68 package main
69 import _ "test/dep"
70 import _ "test/dep2"
71 func main() {}
72 -- a/a_test.go --
73 package main
74 import "testing"
75 import _ "test/testdep"
76 func TestA(*testing.T) {}
77 -- a/default.pgo --
78 -- b/b.go --
79 package main
80 import _ "test/dep"
81 import _ "test/dep2"
82 func main() {}
83 -- b/b_test.go --
84 package main
85 import "testing"
86 import _ "test/testdep"
87 func TestB(*testing.T) {}
88 -- b/default.pgo --
89 -- nopgo/nopgo.go --
90 package main
91 import _ "test/dep"
92 import _ "test/dep2"
93 func main() {}
94 -- nopgo/nopgo_test.go --
95 package main
96 import "testing"
97 func TestNopgo(*testing.T) {}
98 -- dep/dep.go --
99 package dep
100 import _ "test/dep3"
101 -- dep2/dep2.go --
102 package dep2
103 -- dep3/dep3.go --
104 package dep3
105 -- testdep/testdep.go --
106 package testdep
107 import _ "test/testdep2"
108 -- testdep2/testdep2.go --
109 package testdep2
110
View as plain text