Commit 405a8afa authored by Mikio Hara's avatar Mikio Hara

x/net/ipv4: make use of nettest.ProtocolNotSupported

LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/164640043
parent 5f6a5012
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
package ipv4_test
import (
"os"
"syscall"
)
func protocolNotSupported(err error) bool {
switch err := err.(type) {
case syscall.Errno:
switch err {
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
return true
}
case *os.SyscallError:
switch err := err.Err.(type) {
case syscall.Errno:
switch err {
case syscall.EPROTONOSUPPORT, syscall.ENOPROTOOPT:
return true
}
}
}
return false
}
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build nacl plan9
package ipv4_test
func protocolNotSupported(err error) bool {
return false
}
...@@ -63,7 +63,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestPacketConnReadWriteMulticastUDP(t *testing.T) {
for i, toggle := range []bool{true, false, true} { for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
...@@ -139,7 +139,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) { ...@@ -139,7 +139,7 @@ func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
t.Fatalf("icmp.Message.Marshal failed: %v", err) t.Fatalf("icmp.Message.Marshal failed: %v", err)
} }
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
...@@ -235,7 +235,7 @@ func TestRawConnReadWriteMulticastICMP(t *testing.T) { ...@@ -235,7 +235,7 @@ func TestRawConnReadWriteMulticastICMP(t *testing.T) {
Dst: dst.IP, Dst: dst.IP,
} }
if err := r.SetControlMessage(cf, toggle); err != nil { if err := r.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err)
......
...@@ -114,7 +114,7 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { ...@@ -114,7 +114,7 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
for i, toggle := range []bool{true, false, true} { for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
...@@ -177,7 +177,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { ...@@ -177,7 +177,7 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
t.Fatalf("icmp.Message.Marshal failed: %v", err) t.Fatalf("icmp.Message.Marshal failed: %v", err)
} }
if err := p.SetControlMessage(cf, toggle); err != nil { if err := p.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.PacketConn.SetControlMessage failed: %v", err)
...@@ -264,7 +264,7 @@ func TestRawConnReadWriteUnicastICMP(t *testing.T) { ...@@ -264,7 +264,7 @@ func TestRawConnReadWriteUnicastICMP(t *testing.T) {
Dst: dst.IP, Dst: dst.IP,
} }
if err := r.SetControlMessage(cf, toggle); err != nil { if err := r.SetControlMessage(cf, toggle); err != nil {
if protocolNotSupported(err) { if nettest.ProtocolNotSupported(err) {
t.Skipf("not supported on %q", runtime.GOOS) t.Skipf("not supported on %q", runtime.GOOS)
} }
t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err) t.Fatalf("ipv4.RawConn.SetControlMessage failed: %v", err)
......
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