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