Commit da118f7b authored by Mikio Hara's avatar Mikio Hara

route: don't fail test when at least one version of INET protocols is available

This is not perfect but is enough for during the dual IP stack era.

Fixes golang/go#19298.

Change-Id: I5f16b10fda5ddfe470edb021d9a6d7e2a642d267
Reviewed-on: https://go-review.googlesource.com/41515
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent a25ba901
...@@ -7,21 +7,28 @@ package route ...@@ -7,21 +7,28 @@ package route
import "testing" import "testing"
func TestFetchAndParseRIBOnDarwin(t *testing.T) { func TestFetchAndParseRIBOnDarwin(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
for _, typ := range []RIBType{sysNET_RT_FLAGS, sysNET_RT_DUMP2, sysNET_RT_IFLIST2} { for _, typ := range []RIBType{sysNET_RT_FLAGS, sysNET_RT_DUMP2, sysNET_RT_IFLIST2} {
ms, err := fetchAndParseRIB(af, typ) var lastErr error
var ms []Message
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, typ)
if err != nil { if err != nil {
t.Error(err) lastErr = err
continue
}
ms = append(ms, rs...)
}
if len(ms) == 0 && lastErr != nil {
t.Error(typ, lastErr)
continue continue
} }
ss, err := msgs(ms).validate() ss, err := msgs(ms).validate()
if err != nil { if err != nil {
t.Errorf("%v %d %v", addrFamily(af), typ, err) t.Error(typ, err)
continue continue
} }
for _, s := range ss { for _, s := range ss {
t.Log(s) t.Log(s)
} }
} }
}
} }
...@@ -6,28 +6,34 @@ package route ...@@ -6,28 +6,34 @@ package route
import ( import (
"testing" "testing"
"time"
"unsafe" "unsafe"
) )
func TestFetchAndParseRIBOnFreeBSD(t *testing.T) { func TestFetchAndParseRIBOnFreeBSD(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
for _, typ := range []RIBType{sysNET_RT_IFMALIST} { for _, typ := range []RIBType{sysNET_RT_IFMALIST} {
ms, err := fetchAndParseRIB(af, typ) var lastErr error
var ms []Message
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, typ)
if err != nil { if err != nil {
t.Error(err) lastErr = err
continue
}
ms = append(ms, rs...)
}
if len(ms) == 0 && lastErr != nil {
t.Error(typ, lastErr)
continue continue
} }
ss, err := msgs(ms).validate() ss, err := msgs(ms).validate()
if err != nil { if err != nil {
t.Errorf("%v %d %v", addrFamily(af), typ, err) t.Error(typ, err)
continue continue
} }
for _, s := range ss { for _, s := range ss {
t.Log(s) t.Log(s)
} }
} }
}
} }
func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) { func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
...@@ -48,48 +54,29 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) { ...@@ -48,48 +54,29 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
{typ: sysNET_RT_IFLIST}, {typ: sysNET_RT_IFLIST},
{typ: sysNET_RT_IFLISTL}, {typ: sysNET_RT_IFLISTL},
} }
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} { for i := range tests {
var lastErr error var lastErr error
for i := 0; i < 3; i++ { for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
for j := range tests { rs, err := fetchAndParseRIB(af, tests[i].typ)
var err error if err != nil {
if tests[j].b, err = FetchRIB(af, tests[j].typ, 0); err != nil {
lastErr = err lastErr = err
time.Sleep(10 * time.Millisecond)
}
}
if lastErr == nil {
break
}
}
if lastErr != nil {
t.Error(af, lastErr)
continue continue
} }
for i := range tests { tests[i].msgs = append(tests[i].msgs, rs...)
var err error
if tests[i].msgs, err = ParseRIB(tests[i].typ, tests[i].b); err != nil {
lastErr = err
t.Error(af, err)
} }
if len(tests[i].msgs) == 0 && lastErr != nil {
t.Error(tests[i].typ, lastErr)
continue
} }
tests[i].ss, lastErr = msgs(tests[i].msgs).validate()
if lastErr != nil { if lastErr != nil {
t.Error(tests[i].typ, lastErr)
continue continue
} }
for i := range tests {
var err error
tests[i].ss, err = msgs(tests[i].msgs).validate()
if err != nil {
lastErr = err
t.Error(af, err)
}
for _, s := range tests[i].ss { for _, s := range tests[i].ss {
t.Log(s) t.Log(s)
} }
} }
if lastErr != nil {
continue
}
for i := len(tests) - 1; i > 0; i-- { for i := len(tests) - 1; i > 0; i-- {
if len(tests[i].ss) != len(tests[i-1].ss) { if len(tests[i].ss) != len(tests[i-1].ss) {
t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss) t.Errorf("got %v; want %v", tests[i].ss, tests[i-1].ss)
...@@ -102,5 +89,4 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) { ...@@ -102,5 +89,4 @@ func TestFetchAndParseRIBOnFreeBSD10AndAbove(t *testing.T) {
} }
} }
} }
}
} }
...@@ -14,21 +14,28 @@ import ( ...@@ -14,21 +14,28 @@ import (
) )
func TestFetchAndParseRIB(t *testing.T) { func TestFetchAndParseRIB(t *testing.T) {
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
for _, typ := range []RIBType{sysNET_RT_DUMP, sysNET_RT_IFLIST} { for _, typ := range []RIBType{sysNET_RT_DUMP, sysNET_RT_IFLIST} {
ms, err := fetchAndParseRIB(af, typ) var lastErr error
var ms []Message
for _, af := range []int{sysAF_UNSPEC, sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, typ)
if err != nil { if err != nil {
t.Error(err) lastErr = err
continue
}
ms = append(ms, rs...)
}
if len(ms) == 0 && lastErr != nil {
t.Error(typ, lastErr)
continue continue
} }
ss, err := msgs(ms).validate() ss, err := msgs(ms).validate()
if err != nil { if err != nil {
t.Errorf("%v %d %v", addrFamily(af), typ, err) t.Error(typ, err)
continue continue
} }
for _, s := range ss { for _, s := range ss {
t.Log(s) t.Log(typ, s)
}
} }
} }
} }
...@@ -145,8 +152,8 @@ func TestRouteMessage(t *testing.T) { ...@@ -145,8 +152,8 @@ func TestRouteMessage(t *testing.T) {
var ms []RouteMessage var ms []RouteMessage
for _, af := range []int{sysAF_INET, sysAF_INET6} { for _, af := range []int{sysAF_INET, sysAF_INET6} {
rs, err := fetchAndParseRIB(af, sysNET_RT_DUMP) if _, err := fetchAndParseRIB(af, sysNET_RT_DUMP); err != nil {
if err != nil || len(rs) == 0 { t.Log(err)
continue continue
} }
switch af { switch af {
...@@ -228,6 +235,5 @@ func TestRouteMessage(t *testing.T) { ...@@ -228,6 +235,5 @@ func TestRouteMessage(t *testing.T) {
for _, s := range ss { for _, s := range ss {
t.Log(s) t.Log(s)
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment