github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/route/message_freebsd_test.go (about)

     1  // Copyright 2016 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 route
     6  
     7  import "testing"
     8  
     9  func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
    10  	for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
    11  		var lastErr error
    12  		var ms []Message
    13  		for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
    14  			rs, err := fetchAndParseRIB(af, typ)
    15  			if err != nil {
    16  				lastErr = err
    17  				continue
    18  			}
    19  			ms = append(ms, rs...)
    20  		}
    21  		if len(ms) == 0 && lastErr != nil {
    22  			t.Error(typ, lastErr)
    23  			continue
    24  		}
    25  		ss, err := msgs(ms).validate()
    26  		if err != nil {
    27  			t.Error(typ, err)
    28  			continue
    29  		}
    30  		for _, s := range ss {
    31  			t.Log(s)
    32  		}
    33  	}
    34  }
    35  
    36  func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
    37  	if _, err := FetchRIB(sysAF_UNSPEC, sysNET_RT_IFLISTL, 0); err != nil {
    38  		t.Skip("NET_RT_IFLISTL not supported")
    39  	}
    40  	if compatFreeBSD32 {
    41  		t.Skip("NET_RT_IFLIST vs. NET_RT_IFLISTL doesn't work for 386 emulation on amd64")
    42  	}
    43  
    44  	var tests = [2]struct {
    45  		typ  RIBType
    46  		b    []byte
    47  		msgs []Message
    48  		ss   []string
    49  	}{
    50  		{typ: sysNET_RT_IFLIST},
    51  		{typ: sysNET_RT_IFLISTL},
    52  	}
    53  	for i := range tests {
    54  		var lastErr error
    55  		for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
    56  			rs, err := fetchAndParseRIB(af, tests[i].typ)
    57  			if err != nil {
    58  				lastErr = err
    59  				continue
    60  			}
    61  			tests[i].msgs = append(tests[i].msgs, rs...)
    62  		}
    63  		if len(tests[i].msgs) == 0 && lastErr != nil {
    64  			t.Error(tests[i].typ, lastErr)
    65  			continue
    66  		}
    67  		tests[i].ss, lastErr = msgs(tests[i].msgs).validate()
    68  		if lastErr != nil {
    69  			t.Error(tests[i].typ, lastErr)
    70  			continue
    71  		}
    72  		for _, s := range tests[i].ss {
    73  			t.Log(s)
    74  		}
    75  	}
    76  	for i := len(tests) - 1; i > 0; i-- {
    77  		if len(tests[i].ss) != len(tests[i-1].ss) {
    78  			t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss)
    79  			continue
    80  		}
    81  		for j, s1 := range tests[i].ss {
    82  			s0 := tests[i-1].ss[j]
    83  			if s1 != s0 {
    84  				t.Errorf("got %s; want %s", s1, s0)
    85  			}
    86  		}
    87  	}
    88  }