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.Unmap",
    46  		"Addr.Zone",
    47  		"Addr.v4",
    48  		"Addr.v6",
    49  		"Addr.v6u16",
    50  		"Addr.withoutZone",
    51  		"AddrPortFrom",
    52  		"AddrPort.Addr",
    53  		"AddrPort.Port",
    54  		"AddrPort.IsValid",
    55  		"Prefix.IsSingleIP",
    56  		"Prefix.Masked",
    57  		"Prefix.IsValid",
    58  		"PrefixFrom",
    59  		"Prefix.Addr",
    60  		"Prefix.Bits",
    61  		"AddrFrom4",
    62  		"IPv6LinkLocalAllNodes",
    63  		"IPv6Unspecified",
    64  		"MustParseAddr",
    65  		"MustParseAddrPort",
    66  		"MustParsePrefix",
    67  		"appendDecimal",
    68  		"appendHex",
    69  		"uint128.addOne",
    70  		"uint128.and",
    71  		"uint128.bitsClearedFrom",
    72  		"uint128.bitsSetFrom",
    73  		"uint128.isZero",
    74  		"uint128.not",
    75  		"uint128.or",
    76  		"uint128.subOne",
    77  		"uint128.xor",
    78  	}
    79  	switch runtime.GOARCH {
    80  	case "amd64", "arm64":
    81  		// These don't inline on 32-bit.
    82  		wantInlinable = append(wantInlinable,
    83  			"Addr.Next",
    84  			"Addr.Prev",
    85  		)
    86  	}
    87  
    88  	for _, want := range wantInlinable {
    89  		if !got[want] {
    90  			t.Errorf("%q is no longer inlinable", want)
    91  			continue
    92  		}
    93  		delete(got, want)
    94  	}
    95  	for sym := range got {
    96  		if strings.Contains(sym, ".func") {
    97  			continue
    98  		}
    99  		t.Logf("not in expected set, but also inlinable: %q", sym)
   100  
   101  	}
   102  }
   103  

View as plain text