github.com/AESNooper/go/src@v0.0.0-20220218095104-b56a4ab1bbbb/net/netip/inlining_test.go (about) 1 // Copyright 2020 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package netip 6 7 import ( 8 "internal/testenv" 9 "os/exec" 10 "path/filepath" 11 "regexp" 12 "runtime" 13 "strings" 14 "testing" 15 ) 16 17 func TestInlining(t *testing.T) { 18 testenv.MustHaveGoBuild(t) 19 t.Parallel() 20 var exe string 21 if runtime.GOOS == "windows" { 22 exe = ".exe" 23 } 24 out, err := exec.Command( 25 filepath.Join(runtime.GOROOT(), "bin", "go"+exe), 26 "build", 27 "--gcflags=-m", 28 "net/netip").CombinedOutput() 29 if err != nil { 30 t.Fatalf("go build: %v, %s", err, out) 31 } 32 got := map[string]bool{} 33 regexp.MustCompile(` can inline (\S+)`).ReplaceAllFunc(out, func(match []byte) []byte { 34 got[strings.TrimPrefix(string(match), " can inline ")] = true 35 return nil 36 }) 37 wantInlinable := []string{ 38 "(*uint128).halves", 39 "Addr.BitLen", 40 "Addr.hasZone", 41 "Addr.Is4", 42 "Addr.Is4In6", 43 "Addr.Is6", 44 "Addr.IsLoopback", 45 "Addr.IsMulticast", 46 "Addr.IsInterfaceLocalMulticast", 47 "Addr.IsValid", 48 "Addr.IsUnspecified", 49 "Addr.Less", 50 "Addr.lessOrEq", 51 "Addr.Unmap", 52 "Addr.Zone", 53 "Addr.v4", 54 "Addr.v6", 55 "Addr.v6u16", 56 "Addr.withoutZone", 57 "AddrPortFrom", 58 "AddrPort.Addr", 59 "AddrPort.Port", 60 "AddrPort.IsValid", 61 "Prefix.IsSingleIP", 62 "Prefix.Masked", 63 "Prefix.IsValid", 64 "PrefixFrom", 65 "Prefix.Addr", 66 "Prefix.Bits", 67 "AddrFrom4", 68 "IPv6LinkLocalAllNodes", 69 "IPv6Unspecified", 70 "MustParseAddr", 71 "MustParseAddrPort", 72 "MustParsePrefix", 73 "appendDecimal", 74 "appendHex", 75 "uint128.addOne", 76 "uint128.and", 77 "uint128.bitsClearedFrom", 78 "uint128.bitsSetFrom", 79 "uint128.isZero", 80 "uint128.not", 81 "uint128.or", 82 "uint128.subOne", 83 "uint128.xor", 84 } 85 switch runtime.GOARCH { 86 case "amd64", "arm64": 87 // These don't inline on 32-bit. 88 wantInlinable = append(wantInlinable, 89 "u64CommonPrefixLen", 90 "uint128.commonPrefixLen", 91 "Addr.Next", 92 "Addr.Prev", 93 ) 94 } 95 96 for _, want := range wantInlinable { 97 if !got[want] { 98 t.Errorf("%q is no longer inlinable", want) 99 continue 100 } 101 delete(got, want) 102 } 103 for sym := range got { 104 if strings.Contains(sym, ".func") { 105 continue 106 } 107 t.Logf("not in expected set, but also inlinable: %q", sym) 108 109 } 110 }