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

     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 and b/default.pgo are both preprocessed
     6  stderr 'preprofile.*-i.*a(/|\\\\)default\.pgo'
     7  stderr '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.
    13  stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)a\.go'
    14  stderr -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).
    23  stderr -count=3 'compile.*dep(/|\\\\)dep.go'
    24  stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go'
    25  
    26  stderr -count=3 'compile.*dep2(/|\\\\)dep2.go'
    27  stderr -count=2 'compile.*-pgoprofile=.*dep2(/|\\\\)dep2\.go'
    28  
    29  stderr -count=3 'compile.*dep3(/|\\\\)dep3.go'
    30  stderr -count=2 'compile.*-pgoprofile=.*dep3(/|\\\\)dep3\.go'
    31  
    32  # check that pgo appears or not in build info as expected
    33  stderr 'path\\ttest/a\\n.*build\\t-pgo=.*a(/|\\\\)default\.pgo'
    34  stderr '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
    38  go test -a -n -pgo=auto ./a ./b ./nopgo
    39  stderr -count=1 'compile.*-pgoprofile=.*a(/|\\\\)a_test\.go'
    40  stderr -count=1 'compile.*-pgoprofile=.*b(/|\\\\)b_test\.go'
    41  stderr -count=2 'compile.*-pgoprofile=.*dep(/|\\\\)dep\.go'
    42  ! stderr 'compile.*-pgoprofile=.*nopgo(/|\\\\)nopgo_test\.go'
    43  
    44  # test-only dependencies also have profiles attached
    45  stderr -count=2 'compile.*-pgoprofile=.*testdep(/|\\\\)testdep\.go'
    46  stderr -count=2 'compile.*-pgoprofile=.*testdep2(/|\\\\)testdep2\.go'
    47  
    48  # go list -deps prints packages built multiple times.
    49  go list -pgo=auto -deps ./a ./b ./nopgo
    50  stdout 'test/dep \[test/a\]'
    51  stdout 'test/dep \[test/b\]'
    52  stdout '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 --
    59  module test
    60  go 1.20
    61  -- a/a.go --
    62  package main
    63  import _ "test/dep"
    64  import _ "test/dep2"
    65  func main() {}
    66  -- a/a_test.go --
    67  package main
    68  import "testing"
    69  import _ "test/testdep"
    70  func TestA(*testing.T) {}
    71  -- a/default.pgo --
    72  -- b/b.go --
    73  package main
    74  import _ "test/dep"
    75  import _ "test/dep2"
    76  func main() {}
    77  -- b/b_test.go --
    78  package main
    79  import "testing"
    80  import _ "test/testdep"
    81  func TestB(*testing.T) {}
    82  -- b/default.pgo --
    83  -- nopgo/nopgo.go --
    84  package main
    85  import _ "test/dep"
    86  import _ "test/dep2"
    87  func main() {}
    88  -- nopgo/nopgo_test.go --
    89  package main
    90  import "testing"
    91  func TestNopgo(*testing.T) {}
    92  -- dep/dep.go --
    93  package dep
    94  import _ "test/dep3"
    95  -- dep2/dep2.go --
    96  package dep2
    97  -- dep3/dep3.go --
    98  package dep3
    99  -- testdep/testdep.go --
   100  package testdep
   101  import _ "test/testdep2"
   102  -- testdep2/testdep2.go --
   103  package testdep2
   104  

View as plain text