...

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

Documentation: cmd/go/testdata/script

     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 applies to package a and (transitive)
     6# dependencies.
     7stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*a(/|\\\\)a\.go'
     8stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
     9stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep2(/|\\\\)dep2\.go'
    10stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep3(/|\\\\)dep3\.go'
    11
    12# b/default.pgo applies to package b and (transitive)
    13# dependencies.
    14stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*b(/|\\\\)b\.go'
    15stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
    16stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*dep2(/|\\\\)dep2\.go'
    17stderr -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).
    26stderr -count=3 'compile.*dep(/|\\\\)dep.go'
    27stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go'
    28
    29stderr -count=3 'compile.*dep2(/|\\\\)dep2.go'
    30stderr -count=2 'compile.*-pgoprofile=.*dep2(/|\\\\)dep2\.go'
    31
    32stderr -count=3 'compile.*dep3(/|\\\\)dep3.go'
    33stderr -count=2 'compile.*-pgoprofile=.*dep3(/|\\\\)dep3\.go'
    34
    35# check that pgo appears or not in build info as expected
    36stderr 'path\\ttest/a\\n.*build\\t-pgo=.*a(/|\\\\)default\.pgo'
    37stderr '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
    41go test -a -n -pgo=auto ./a ./b ./nopgo
    42stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*a(/|\\\\)a_test\.go'
    43stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*dep(/|\\\\)dep\.go'
    44stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*b(/|\\\\)b_test\.go'
    45stderr '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
    49stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*testdep(/|\\\\)testdep\.go'
    50stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*testdep(/|\\\\)testdep\.go'
    51stderr 'compile.*-pgoprofile=.*a(/|\\\\)default\.pgo.*testdep2(/|\\\\)testdep2\.go'
    52stderr 'compile.*-pgoprofile=.*b(/|\\\\)default\.pgo.*testdep2(/|\\\\)testdep2\.go'
    53
    54# go list -deps prints packages built multiple times.
    55go list -pgo=auto -deps ./a ./b ./nopgo
    56stdout 'test/dep \[test/a\]'
    57stdout 'test/dep \[test/b\]'
    58stdout '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 --
    65module test
    66go 1.20
    67-- a/a.go --
    68package main
    69import _ "test/dep"
    70import _ "test/dep2"
    71func main() {}
    72-- a/a_test.go --
    73package main
    74import "testing"
    75import _ "test/testdep"
    76func TestA(*testing.T) {}
    77-- a/default.pgo --
    78-- b/b.go --
    79package main
    80import _ "test/dep"
    81import _ "test/dep2"
    82func main() {}
    83-- b/b_test.go --
    84package main
    85import "testing"
    86import _ "test/testdep"
    87func TestB(*testing.T) {}
    88-- b/default.pgo --
    89-- nopgo/nopgo.go --
    90package main
    91import _ "test/dep"
    92import _ "test/dep2"
    93func main() {}
    94-- nopgo/nopgo_test.go --
    95package main
    96import "testing"
    97func TestNopgo(*testing.T) {}
    98-- dep/dep.go --
    99package dep
   100import _ "test/dep3"
   101-- dep2/dep2.go --
   102package dep2
   103-- dep3/dep3.go --
   104package dep3
   105-- testdep/testdep.go --
   106package testdep
   107import _ "test/testdep2"
   108-- testdep2/testdep2.go --
   109package testdep2

View as plain text