Source file src/net/netip/inlining_test.go

     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  	"regexp"
    11  	"runtime"
    12  	"strings"
    13  	"testing"
    14  )
    15  
    16  func TestInlining(t *testing.T) {
    17  	testenv.MustHaveGoBuild(t)
    18  	t.Parallel()
    19  	out, err := exec.Command(
    20  		testenv.GoToolPath(t),
    21  		"build",
    22  		"--gcflags=-m",
    23  		"net/netip").CombinedOutput()
    24  	if err != nil {
    25  		t.Fatalf("go build: %v, %s", err, out)
    26  	}
    27  	got := map[string]bool{}
    28  	regexp.MustCompile(` can inline (\S+)`).ReplaceAllFunc(out, func(match []byte) []byte {
    29  		got[strings.TrimPrefix(string(match), " can inline ")] = true
    30  		return nil
    31  	})
    32  	wantInlinable := []string{
    33  		"(*uint128).halves",
    34  		"Addr.BitLen",
    35  		"Addr.hasZone",
    36  		"Addr.Is4",
    37  		"Addr.Is4In6",
    38  		"Addr.Is6",
    39  		"Addr.IsLoopback",
    40  		"Addr.IsMulticast",
    41  		"Addr.IsInterfaceLocalMulticast",
    42  		"Addr.IsValid",
    43  		"Addr.IsUnspecified",
    44  		"Addr.Less",
    45  		"Addr.lessOrEq",
    46  		"Addr.Unmap",
    47  		"Addr.Zone",
    48  		"Addr.v4",
    49  		"Addr.v6",
    50  		"Addr.v6u16",
    51  		"Addr.withoutZone",
    52  		"AddrPortFrom",
    53  		"AddrPort.Addr",
    54  		"AddrPort.Port",
    55  		"AddrPort.IsValid",
    56  		"Prefix.IsSingleIP",
    57  		"Prefix.Masked",
    58  		"Prefix.IsValid",
    59  		"PrefixFrom",
    60  		"Prefix.Addr",
    61  		"Prefix.Bits",
    62  		"AddrFrom4",
    63  		"IPv6LinkLocalAllNodes",
    64  		"IPv6Unspecified",
    65  		"MustParseAddr",
    66  		"MustParseAddrPort",
    67  		"MustParsePrefix",
    68  		"appendDecimal",
    69  		"appendHex",
    70  		"uint128.addOne",
    71  		"uint128.and",
    72  		"uint128.bitsClearedFrom",
    73  		"uint128.bitsSetFrom",
    74  		"uint128.isZero",
    75  		"uint128.not",
    76  		"uint128.or",
    77  		"uint128.subOne",
    78  		"uint128.xor",
    79  	}
    80  	switch runtime.GOARCH {
    81  	case "amd64", "arm64":
    82  		// These don't inline on 32-bit.
    83  		wantInlinable = append(wantInlinable,
    84  			"u64CommonPrefixLen",
    85  			"uint128.commonPrefixLen",
    86  			"Addr.Next",
    87  			"Addr.Prev",
    88  		)
    89  	}
    90  
    91  	for _, want := range wantInlinable {
    92  		if !got[want] {
    93  			t.Errorf("%q is no longer inlinable", want)
    94  			continue
    95  		}
    96  		delete(got, want)
    97  	}
    98  	for sym := range got {
    99  		if strings.Contains(sym, ".func") {
   100  			continue
   101  		}
   102  		t.Logf("not in expected set, but also inlinable: %q", sym)
   103  
   104  	}
   105  }
   106  

View as plain text