Commit 7b2b45e5 authored by Mikio Hara's avatar Mikio Hara

net: simplify test helpers

This change consolidates test helpers that test platform capabilities.
testNetwork, testAddress and testListenArgs report whether given
ariguments are testable on the current platform configuration to
mitigate to receive weird test results.

Change-Id: Ie1ed568a1f9cc50f3155945ea01562904bc2c389
Reviewed-on: https://go-review.googlesource.com/8076Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 71756355
...@@ -9,7 +9,6 @@ package net ...@@ -9,7 +9,6 @@ package net
import ( import (
"os" "os"
"runtime"
"testing" "testing"
"time" "time"
) )
...@@ -30,23 +29,9 @@ const someTimeout = 10 * time.Second ...@@ -30,23 +29,9 @@ const someTimeout = 10 * time.Second
func TestConnAndListener(t *testing.T) { func TestConnAndListener(t *testing.T) {
for _, tt := range connTests { for _, tt := range connTests {
switch tt.net { if !testableNetwork(tt.net) {
case "unix": t.Logf("skipping %s test", tt.net)
switch runtime.GOOS { continue
case "nacl", "plan9", "windows":
continue
}
// iOS does not support unix domain sockets
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm" {
continue
}
case "unixpacket":
switch runtime.GOOS {
case "android", "darwin", "nacl", "openbsd", "plan9", "windows":
continue
case "freebsd": // FreeBSD 8 doesn't support unixpacket
continue
}
} }
ln, err := Listen(tt.net, tt.addr) ln, err := Listen(tt.net, tt.addr)
......
...@@ -27,10 +27,6 @@ type connFile interface { ...@@ -27,10 +27,6 @@ type connFile interface {
} }
func testFileListener(t *testing.T, net, laddr string) { func testFileListener(t *testing.T, net, laddr string) {
switch net {
case "tcp", "tcp4", "tcp6":
laddr += ":0" // any available port
}
l, err := Listen(net, laddr) l, err := Listen(net, laddr)
if err != nil { if err != nil {
t.Fatalf("Listen failed: %v", err) t.Fatalf("Listen failed: %v", err)
...@@ -59,32 +55,30 @@ func testFileListener(t *testing.T, net, laddr string) { ...@@ -59,32 +55,30 @@ func testFileListener(t *testing.T, net, laddr string) {
var fileListenerTests = []struct { var fileListenerTests = []struct {
net string net string
laddr string laddr string
ipv6 bool // test with underlying AF_INET6 socket
linux bool // test with abstract unix domain socket, a Linux-ism
}{ }{
{net: "tcp", laddr: ""}, {net: "tcp", laddr: ":0"},
{net: "tcp", laddr: "0.0.0.0"}, {net: "tcp", laddr: "0.0.0.0:0"},
{net: "tcp", laddr: "[::ffff:0.0.0.0]"}, {net: "tcp", laddr: "[::ffff:0.0.0.0]:0"},
{net: "tcp", laddr: "[::]", ipv6: true}, {net: "tcp", laddr: "[::]:0"},
{net: "tcp", laddr: "127.0.0.1"}, {net: "tcp", laddr: "127.0.0.1:0"},
{net: "tcp", laddr: "[::ffff:127.0.0.1]"}, {net: "tcp", laddr: "[::ffff:127.0.0.1]:0"},
{net: "tcp", laddr: "[::1]", ipv6: true}, {net: "tcp", laddr: "[::1]:0"},
{net: "tcp4", laddr: ""}, {net: "tcp4", laddr: ":0"},
{net: "tcp4", laddr: "0.0.0.0"}, {net: "tcp4", laddr: "0.0.0.0:0"},
{net: "tcp4", laddr: "[::ffff:0.0.0.0]"}, {net: "tcp4", laddr: "[::ffff:0.0.0.0]:0"},
{net: "tcp4", laddr: "127.0.0.1"}, {net: "tcp4", laddr: "127.0.0.1:0"},
{net: "tcp4", laddr: "[::ffff:127.0.0.1]"}, {net: "tcp4", laddr: "[::ffff:127.0.0.1]:0"},
{net: "tcp6", laddr: "", ipv6: true}, {net: "tcp6", laddr: ":0"},
{net: "tcp6", laddr: "[::]", ipv6: true}, {net: "tcp6", laddr: "[::]:0"},
{net: "tcp6", laddr: "[::1]", ipv6: true}, {net: "tcp6", laddr: "[::1]:0"},
{net: "unix", laddr: "@gotest/net", linux: true}, {net: "unix", laddr: "@gotest/net"},
{net: "unixpacket", laddr: "@gotest/net", linux: true}, {net: "unixpacket", laddr: "@gotest/net"},
} }
func TestFileListener(t *testing.T) { func TestFileListener(t *testing.T) {
...@@ -94,10 +88,8 @@ func TestFileListener(t *testing.T) { ...@@ -94,10 +88,8 @@ func TestFileListener(t *testing.T) {
} }
for _, tt := range fileListenerTests { for _, tt := range fileListenerTests {
if skipServerTest(tt.net, "unix", tt.laddr, tt.ipv6, false, tt.linux) { if !testableListenArgs(tt.net, tt.laddr, "") {
continue t.Logf("skipping %s test", tt.net+":"+tt.laddr+"->")
}
if skipServerTest(tt.net, "unixpacket", tt.laddr, tt.ipv6, false, tt.linux) {
continue continue
} }
testFileListener(t, tt.net, tt.laddr) testFileListener(t, tt.net, tt.laddr)
...@@ -130,10 +122,6 @@ func testFilePacketConn(t *testing.T, pcf packetConnFile, listen bool) { ...@@ -130,10 +122,6 @@ func testFilePacketConn(t *testing.T, pcf packetConnFile, listen bool) {
} }
func testFilePacketConnListen(t *testing.T, net, laddr string) { func testFilePacketConnListen(t *testing.T, net, laddr string) {
switch net {
case "udp", "udp4", "udp6":
laddr += ":0" // any available port
}
l, err := ListenPacket(net, laddr) l, err := ListenPacket(net, laddr)
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
...@@ -145,10 +133,6 @@ func testFilePacketConnListen(t *testing.T, net, laddr string) { ...@@ -145,10 +133,6 @@ func testFilePacketConnListen(t *testing.T, net, laddr string) {
} }
func testFilePacketConnDial(t *testing.T, net, raddr string) { func testFilePacketConnDial(t *testing.T, net, raddr string) {
switch net {
case "udp", "udp4", "udp6":
raddr += ":12345"
}
c, err := Dial(net, raddr) c, err := Dial(net, raddr)
if err != nil { if err != nil {
t.Fatalf("Dial failed: %v", err) t.Fatalf("Dial failed: %v", err)
...@@ -160,23 +144,21 @@ func testFilePacketConnDial(t *testing.T, net, raddr string) { ...@@ -160,23 +144,21 @@ func testFilePacketConnDial(t *testing.T, net, raddr string) {
} }
var filePacketConnTests = []struct { var filePacketConnTests = []struct {
net string net string
addr string addr string
ipv6 bool // test with underlying AF_INET6 socket
linux bool // test with abstract unix domain socket, a Linux-ism
}{ }{
{net: "udp", addr: "127.0.0.1"}, {net: "udp", addr: "127.0.0.1:0"},
{net: "udp", addr: "[::ffff:127.0.0.1]"}, {net: "udp", addr: "[::ffff:127.0.0.1]:0"},
{net: "udp", addr: "[::1]", ipv6: true}, {net: "udp", addr: "[::1]:0"},
{net: "udp4", addr: "127.0.0.1"}, {net: "udp4", addr: "127.0.0.1:0"},
{net: "udp4", addr: "[::ffff:127.0.0.1]"}, {net: "udp4", addr: "[::ffff:127.0.0.1]:0"},
{net: "udp6", addr: "[::1]", ipv6: true}, {net: "udp6", addr: "[::1]:0"},
{net: "ip4:icmp", addr: "127.0.0.1"}, {net: "ip4:icmp", addr: "127.0.0.1"},
{net: "unixgram", addr: "@gotest3/net", linux: true}, {net: "unixgram", addr: "@gotest3/net"},
} }
func TestFilePacketConn(t *testing.T) { func TestFilePacketConn(t *testing.T) {
...@@ -186,7 +168,8 @@ func TestFilePacketConn(t *testing.T) { ...@@ -186,7 +168,8 @@ func TestFilePacketConn(t *testing.T) {
} }
for _, tt := range filePacketConnTests { for _, tt := range filePacketConnTests {
if skipServerTest(tt.net, "unixgram", tt.addr, tt.ipv6, false, tt.linux) { if !testableListenArgs(tt.net, tt.addr, "") {
t.Logf("skipping %s test", tt.net+":"+tt.addr+"->")
continue continue
} }
if os.Getuid() != 0 && tt.net == "ip4:icmp" { if os.Getuid() != 0 && tt.net == "ip4:icmp" {
...@@ -194,12 +177,16 @@ func TestFilePacketConn(t *testing.T) { ...@@ -194,12 +177,16 @@ func TestFilePacketConn(t *testing.T) {
continue continue
} }
testFilePacketConnListen(t, tt.net, tt.addr) testFilePacketConnListen(t, tt.net, tt.addr)
switch tt.addr { switch tt.net {
case "", "0.0.0.0", "[::ffff:0.0.0.0]", "[::]": case "udp", "udp4", "udp6":
default: host, _, err := SplitHostPort(tt.addr)
if tt.net != "unixgram" { if err != nil {
testFilePacketConnDial(t, tt.net, tt.addr) t.Error(err)
continue
} }
testFilePacketConnDial(t, tt.net, JoinHostPort(host, "12345"))
case "ip4:icmp":
testFilePacketConnDial(t, tt.net, tt.addr)
} }
} }
} }
...@@ -6,9 +6,7 @@ package net ...@@ -6,9 +6,7 @@ package net
import ( import (
"fmt" "fmt"
"os"
"reflect" "reflect"
"runtime"
"testing" "testing"
) )
...@@ -64,9 +62,8 @@ func init() { ...@@ -64,9 +62,8 @@ func init() {
} }
func TestResolveIPAddr(t *testing.T) { func TestResolveIPAddr(t *testing.T) {
switch runtime.GOOS { if !testableNetwork("ip+nopriv") {
case "nacl": t.Skip("ip+nopriv test")
t.Skipf("skipping test on %q", runtime.GOOS)
} }
for _, tt := range resolveIPAddrTests { for _, tt := range resolveIPAddrTests {
...@@ -89,16 +86,11 @@ var ipConnLocalNameTests = []struct { ...@@ -89,16 +86,11 @@ var ipConnLocalNameTests = []struct {
} }
func TestIPConnLocalName(t *testing.T) { func TestIPConnLocalName(t *testing.T) {
switch runtime.GOOS {
case "nacl", "plan9", "windows":
t.Skipf("skipping test on %q", runtime.GOOS)
default:
if os.Getuid() != 0 {
t.Skip("skipping test; must be root")
}
}
for _, tt := range ipConnLocalNameTests { for _, tt := range ipConnLocalNameTests {
if !testableNetwork(tt.net) {
t.Logf("skipping %s test", tt.net)
continue
}
c, err := ListenIP(tt.net, tt.laddr) c, err := ListenIP(tt.net, tt.laddr)
if err != nil { if err != nil {
t.Fatalf("ListenIP failed: %v", err) t.Fatalf("ListenIP failed: %v", err)
...@@ -111,13 +103,8 @@ func TestIPConnLocalName(t *testing.T) { ...@@ -111,13 +103,8 @@ func TestIPConnLocalName(t *testing.T) {
} }
func TestIPConnRemoteName(t *testing.T) { func TestIPConnRemoteName(t *testing.T) {
switch runtime.GOOS { if !testableNetwork("ip:tcp") {
case "plan9", "windows": t.Skip("ip:tcp test")
t.Skipf("skipping test on %q", runtime.GOOS)
default:
if os.Getuid() != 0 {
t.Skip("skipping test; must be root")
}
} }
raddr := &IPAddr{IP: IPv4(127, 0, 0, 1).To4()} raddr := &IPAddr{IP: IPv4(127, 0, 0, 1).To4()}
......
...@@ -23,6 +23,13 @@ func (a *IPAddr) String() string { ...@@ -23,6 +23,13 @@ func (a *IPAddr) String() string {
return a.IP.String() return a.IP.String()
} }
func (a *IPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *IPAddr) toAddr() Addr { func (a *IPAddr) toAddr() Addr {
if a == nil { if a == nil {
return nil return nil
......
...@@ -43,13 +43,6 @@ func (a *IPAddr) family() int { ...@@ -43,13 +43,6 @@ func (a *IPAddr) family() int {
return syscall.AF_INET6 return syscall.AF_INET6
} }
func (a *IPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *IPAddr) sockaddr(family int) (syscall.Sockaddr, error) { func (a *IPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
if a == nil { if a == nil {
return nil, nil return nil, nil
......
...@@ -63,14 +63,10 @@ func TestShutdown(t *testing.T) { ...@@ -63,14 +63,10 @@ func TestShutdown(t *testing.T) {
} }
func TestShutdownUnix(t *testing.T) { func TestShutdownUnix(t *testing.T) {
switch runtime.GOOS { if !testableNetwork("unix") {
case "nacl", "plan9", "windows": t.Skip("unix test")
t.Skipf("skipping test on %q", runtime.GOOS)
case "darwin":
if runtime.GOARCH == "arm" {
t.Skipf("skipping test on %s/%s", runtime.GOOS, runtime.GOARCH)
}
} }
f, err := ioutil.TempFile("", "go_net_unixtest") f, err := ioutil.TempFile("", "go_net_unixtest")
if err != nil { if err != nil {
t.Fatalf("TempFile: %s", err) t.Fatalf("TempFile: %s", err)
......
...@@ -9,8 +9,6 @@ package net ...@@ -9,8 +9,6 @@ package net
import ( import (
"os" "os"
"runtime"
"strings"
"testing" "testing"
"time" "time"
) )
...@@ -21,24 +19,11 @@ import ( ...@@ -21,24 +19,11 @@ import (
// golang.org/x/net/ipv6 // golang.org/x/net/ipv6
// golang.org/x/net/icmp // golang.org/x/net/icmp
func packetConnTestData(t *testing.T, net string, i int) ([]byte, func()) { func packetConnTestData(t *testing.T, network string) ([]byte, func()) {
switch net { if !testableNetwork(network) {
case "udp": return nil, func() { t.Logf("skipping %s test", network) }
return []byte("UDP PACKETCONN TEST"), nil
case "unixgram":
switch runtime.GOOS {
case "nacl", "plan9", "windows":
return nil, func() {
t.Logf("skipping %q test on %q", net, runtime.GOOS)
}
default:
return []byte("UNIXGRAM PACKETCONN TEST"), nil
}
default:
return nil, func() {
t.Logf("skipping %q test", net)
}
} }
return []byte("PACKETCONN TEST"), nil
} }
var packetConnTests = []struct { var packetConnTests = []struct {
...@@ -51,9 +36,6 @@ var packetConnTests = []struct { ...@@ -51,9 +36,6 @@ var packetConnTests = []struct {
} }
func TestPacketConn(t *testing.T) { func TestPacketConn(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm" {
t.Skip("skipping test on darwin/arm")
}
closer := func(c PacketConn, net, addr1, addr2 string) { closer := func(c PacketConn, net, addr1, addr2 string) {
c.Close() c.Close()
switch net { switch net {
...@@ -63,9 +45,8 @@ func TestPacketConn(t *testing.T) { ...@@ -63,9 +45,8 @@ func TestPacketConn(t *testing.T) {
} }
} }
for i, tt := range packetConnTests { for _, tt := range packetConnTests {
netstr := strings.Split(tt.net, ":") wb, skipOrFatalFn := packetConnTestData(t, tt.net)
wb, skipOrFatalFn := packetConnTestData(t, netstr[0], i)
if skipOrFatalFn != nil { if skipOrFatalFn != nil {
skipOrFatalFn() skipOrFatalFn()
continue continue
...@@ -75,7 +56,7 @@ func TestPacketConn(t *testing.T) { ...@@ -75,7 +56,7 @@ func TestPacketConn(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c1, netstr[0], tt.addr1, tt.addr2) defer closer(c1, tt.net, tt.addr1, tt.addr2)
c1.LocalAddr() c1.LocalAddr()
c1.SetDeadline(time.Now().Add(500 * time.Millisecond)) c1.SetDeadline(time.Now().Add(500 * time.Millisecond))
c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
...@@ -85,7 +66,7 @@ func TestPacketConn(t *testing.T) { ...@@ -85,7 +66,7 @@ func TestPacketConn(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c2, netstr[0], tt.addr1, tt.addr2) defer closer(c2, tt.net, tt.addr1, tt.addr2)
c2.LocalAddr() c2.LocalAddr()
c2.SetDeadline(time.Now().Add(500 * time.Millisecond)) c2.SetDeadline(time.Now().Add(500 * time.Millisecond))
c2.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) c2.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
...@@ -109,9 +90,6 @@ func TestPacketConn(t *testing.T) { ...@@ -109,9 +90,6 @@ func TestPacketConn(t *testing.T) {
} }
func TestConnAndPacketConn(t *testing.T) { func TestConnAndPacketConn(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm" {
t.Skip("skipping test on darwin/arm")
}
closer := func(c PacketConn, net, addr1, addr2 string) { closer := func(c PacketConn, net, addr1, addr2 string) {
c.Close() c.Close()
switch net { switch net {
...@@ -121,10 +99,9 @@ func TestConnAndPacketConn(t *testing.T) { ...@@ -121,10 +99,9 @@ func TestConnAndPacketConn(t *testing.T) {
} }
} }
for i, tt := range packetConnTests { for _, tt := range packetConnTests {
var wb []byte var wb []byte
netstr := strings.Split(tt.net, ":") wb, skipOrFatalFn := packetConnTestData(t, tt.net)
wb, skipOrFatalFn := packetConnTestData(t, netstr[0], i)
if skipOrFatalFn != nil { if skipOrFatalFn != nil {
skipOrFatalFn() skipOrFatalFn()
continue continue
...@@ -134,7 +111,7 @@ func TestConnAndPacketConn(t *testing.T) { ...@@ -134,7 +111,7 @@ func TestConnAndPacketConn(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("ListenPacket failed: %v", err) t.Fatalf("ListenPacket failed: %v", err)
} }
defer closer(c1, netstr[0], tt.addr1, tt.addr2) defer closer(c1, tt.net, tt.addr1, tt.addr2)
c1.LocalAddr() c1.LocalAddr()
c1.SetDeadline(time.Now().Add(500 * time.Millisecond)) c1.SetDeadline(time.Now().Add(500 * time.Millisecond))
c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond)) c1.SetReadDeadline(time.Now().Add(500 * time.Millisecond))
...@@ -159,9 +136,7 @@ func TestConnAndPacketConn(t *testing.T) { ...@@ -159,9 +136,7 @@ func TestConnAndPacketConn(t *testing.T) {
t.Fatalf("PacketConn.ReadFrom failed: %v", err) t.Fatalf("PacketConn.ReadFrom failed: %v", err)
} }
var dst Addr var dst Addr
switch netstr[0] { switch tt.net {
case "ip":
dst = &IPAddr{IP: IPv4(127, 0, 0, 1)}
case "unixgram": case "unixgram":
continue continue
default: default:
......
// Copyright 2015 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.
package net
import (
"os"
"runtime"
"strings"
"testing"
)
// testableNetwork reports whether network is testable on the current
// platform configuration.
func testableNetwork(network string) bool {
switch ss := strings.Split(network, ":"); ss[0] {
case "ip+nopriv":
switch runtime.GOOS {
case "nacl":
return false
}
case "ip", "ip4", "ip6":
switch runtime.GOOS {
case "nacl", "plan9":
return false
default:
if os.Getuid() != 0 {
return false
}
}
case "unix", "unixgram":
switch runtime.GOOS {
case "nacl", "plan9", "windows":
return false
}
// iOS does not support unix, unixgram.
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
return false
}
case "unixpacket":
switch runtime.GOOS {
case "android", "darwin", "nacl", "openbsd", "plan9", "windows":
fallthrough
case "freebsd": // FreeBSD 8 and below don't support unixpacket
return false
}
}
return true
}
// testableAddress reports whether address of network is testable on
// the current platform configuration.
func testableAddress(network, address string) bool {
switch ss := strings.Split(network, ":"); ss[0] {
case "unix", "unixgram", "unixpacket":
// Abstract unix domain sockets, a Linux-ism.
if address[0] == '@' && runtime.GOOS != "linux" {
return false
}
}
return true
}
// testableListenArgs reports whether arguments are testable on the
// current platform configuration.
func testableListenArgs(network, address, client string) bool {
if !testableNetwork(network) || !testableAddress(network, address) {
return false
}
var err error
var addr Addr
switch ss := strings.Split(network, ":"); ss[0] {
case "tcp", "tcp4", "tcp6":
addr, err = ResolveTCPAddr("tcp", address)
case "udp", "udp4", "udp6":
addr, err = ResolveUDPAddr("udp", address)
case "ip", "ip4", "ip6":
addr, err = ResolveIPAddr("ip", address)
default:
return true
}
if err != nil {
return false
}
var ip IP
var wildcard bool
switch addr := addr.(type) {
case *TCPAddr:
ip = addr.IP
wildcard = addr.isWildcard()
case *UDPAddr:
ip = addr.IP
wildcard = addr.isWildcard()
case *IPAddr:
ip = addr.IP
wildcard = addr.isWildcard()
}
// Test wildcard IP addresses.
if wildcard && (testing.Short() || !*testExternal) {
return false
}
// Test functionality of IPv6 communication using AF_INET6
// sockets.
if !supportsIPv6 && ip.To16() != nil && ip.To4() == nil {
return false
}
// Test functionality of IPv4 communication using AF_INET6
// sockets.
cip := ParseIP(client)
if !supportsIPv4map && (network == "tcp" || network == "udp" || network == "ip") && wildcard {
// At this point, we prefer IPv4 when ip is nil.
// See favoriteAddrFamily for further information.
if ip.To16() != nil && ip.To4() == nil && cip.To4() != nil { // a pair of IPv6 server and IPv4 client
return false
}
if (ip.To4() != nil || ip == nil) && cip.To16() != nil && cip.To4() == nil { // a pair of IPv4 server and IPv6 client
return false
}
}
return true
}
var condFatalf = func() func(*testing.T, string, ...interface{}) {
// A few APIs, File, Read/WriteMsg{UDP,IP}, are not
// implemented yet on both Plan 9 and Windows.
switch runtime.GOOS {
case "plan9", "windows":
return (*testing.T).Logf
}
return (*testing.T).Fatalf
}()
...@@ -35,15 +35,6 @@ func testUnixAddr() string { ...@@ -35,15 +35,6 @@ func testUnixAddr() string {
return addr return addr
} }
var condFatalf = func() func(*testing.T, string, ...interface{}) {
// A few APIs are not implemented yet on both Plan 9 and Windows.
switch runtime.GOOS {
case "plan9", "windows":
return (*testing.T).Logf
}
return (*testing.T).Fatalf
}()
func TestTCPListenerSpecificMethods(t *testing.T) { func TestTCPListenerSpecificMethods(t *testing.T) {
switch runtime.GOOS { switch runtime.GOOS {
case "plan9": case "plan9":
...@@ -218,13 +209,8 @@ func TestIPConnSpecificMethods(t *testing.T) { ...@@ -218,13 +209,8 @@ func TestIPConnSpecificMethods(t *testing.T) {
} }
func TestUnixListenerSpecificMethods(t *testing.T) { func TestUnixListenerSpecificMethods(t *testing.T) {
switch runtime.GOOS { if !testableNetwork("unix") {
case "nacl", "plan9", "windows": t.Skip("unix test")
t.Skipf("skipping test on %q", runtime.GOOS)
case "darwin":
if runtime.GOARCH == "arm" {
t.Skipf("skipping test on %s/%s", runtime.GOOS, runtime.GOARCH)
}
} }
addr := testUnixAddr() addr := testUnixAddr()
...@@ -264,13 +250,8 @@ func TestUnixListenerSpecificMethods(t *testing.T) { ...@@ -264,13 +250,8 @@ func TestUnixListenerSpecificMethods(t *testing.T) {
} }
func TestUnixConnSpecificMethods(t *testing.T) { func TestUnixConnSpecificMethods(t *testing.T) {
switch runtime.GOOS { if !testableNetwork("unixgram") {
case "nacl", "plan9", "windows": t.Skip("unixgram test")
t.Skipf("skipping test on %q", runtime.GOOS)
case "darwin":
if runtime.GOARCH == "arm" {
t.Skipf("skipping test on %s/%s", runtime.GOOS, runtime.GOARCH)
}
} }
addr1, addr2, addr3 := testUnixAddr(), testUnixAddr(), testUnixAddr() addr1, addr2, addr3 := testUnixAddr(), testUnixAddr(), testUnixAddr()
......
This diff is collapsed.
...@@ -25,6 +25,13 @@ func (a *TCPAddr) String() string { ...@@ -25,6 +25,13 @@ func (a *TCPAddr) String() string {
return JoinHostPort(ip, itoa(a.Port)) return JoinHostPort(ip, itoa(a.Port))
} }
func (a *TCPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *TCPAddr) toAddr() Addr { func (a *TCPAddr) toAddr() Addr {
if a == nil { if a == nil {
return nil return nil
......
...@@ -38,13 +38,6 @@ func (a *TCPAddr) family() int { ...@@ -38,13 +38,6 @@ func (a *TCPAddr) family() int {
return syscall.AF_INET6 return syscall.AF_INET6
} }
func (a *TCPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *TCPAddr) sockaddr(family int) (syscall.Sockaddr, error) { func (a *TCPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
if a == nil { if a == nil {
return nil, nil return nil, nil
......
...@@ -25,6 +25,13 @@ func (a *UDPAddr) String() string { ...@@ -25,6 +25,13 @@ func (a *UDPAddr) String() string {
return JoinHostPort(ip, itoa(a.Port)) return JoinHostPort(ip, itoa(a.Port))
} }
func (a *UDPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *UDPAddr) toAddr() Addr { func (a *UDPAddr) toAddr() Addr {
if a == nil { if a == nil {
return nil return nil
......
...@@ -31,13 +31,6 @@ func (a *UDPAddr) family() int { ...@@ -31,13 +31,6 @@ func (a *UDPAddr) family() int {
return syscall.AF_INET6 return syscall.AF_INET6
} }
func (a *UDPAddr) isWildcard() bool {
if a == nil || a.IP == nil {
return true
}
return a.IP.IsUnspecified()
}
func (a *UDPAddr) sockaddr(family int) (syscall.Sockaddr, error) { func (a *UDPAddr) sockaddr(family int) (syscall.Sockaddr, error) {
if a == nil { if a == nil {
return nil, nil return nil, nil
......
...@@ -17,9 +17,10 @@ import ( ...@@ -17,9 +17,10 @@ import (
) )
func TestReadUnixgramWithUnnamedSocket(t *testing.T) { func TestReadUnixgramWithUnnamedSocket(t *testing.T) {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { if !testableNetwork("unixgram") {
t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH) t.Skip("unixgram test")
} }
addr := testUnixAddr() addr := testUnixAddr()
la, err := ResolveUnixAddr("unixgram", addr) la, err := ResolveUnixAddr("unixgram", addr)
if err != nil { if err != nil {
...@@ -67,8 +68,8 @@ func TestReadUnixgramWithUnnamedSocket(t *testing.T) { ...@@ -67,8 +68,8 @@ func TestReadUnixgramWithUnnamedSocket(t *testing.T) {
} }
func TestReadUnixgramWithZeroBytesBuffer(t *testing.T) { func TestReadUnixgramWithZeroBytesBuffer(t *testing.T) {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { if !testableNetwork("unixgram") {
t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH) t.Skip("unixgram test")
} }
// issue 4352: Recvfrom failed with "address family not // issue 4352: Recvfrom failed with "address family not
// supported by protocol family" if zero-length buffer provided // supported by protocol family" if zero-length buffer provided
...@@ -149,6 +150,7 @@ func TestUnixAutobindClose(t *testing.T) { ...@@ -149,6 +150,7 @@ func TestUnixAutobindClose(t *testing.T) {
if runtime.GOOS != "linux" { if runtime.GOOS != "linux" {
t.Skip("skipping: autobind is linux only") t.Skip("skipping: autobind is linux only")
} }
laddr := &UnixAddr{Name: "", Net: "unix"} laddr := &UnixAddr{Name: "", Net: "unix"}
ln, err := ListenUnix("unix", laddr) ln, err := ListenUnix("unix", laddr)
if err != nil { if err != nil {
...@@ -158,9 +160,10 @@ func TestUnixAutobindClose(t *testing.T) { ...@@ -158,9 +160,10 @@ func TestUnixAutobindClose(t *testing.T) {
} }
func TestUnixgramWrite(t *testing.T) { func TestUnixgramWrite(t *testing.T) {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { if !testableNetwork("unixgram") {
t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH) t.Skip("unixgram test")
} }
addr := testUnixAddr() addr := testUnixAddr()
laddr, err := ResolveUnixAddr("unixgram", addr) laddr, err := ResolveUnixAddr("unixgram", addr)
if err != nil { if err != nil {
...@@ -228,9 +231,10 @@ func testUnixgramWritePacketConn(t *testing.T, raddr *UnixAddr) { ...@@ -228,9 +231,10 @@ func testUnixgramWritePacketConn(t *testing.T, raddr *UnixAddr) {
} }
func TestUnixConnLocalAndRemoteNames(t *testing.T) { func TestUnixConnLocalAndRemoteNames(t *testing.T) {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { if !testableNetwork("unix") {
t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH) t.Skip("unix test")
} }
for _, laddr := range []string{"", testUnixAddr()} { for _, laddr := range []string{"", testUnixAddr()} {
laddr := laddr laddr := laddr
taddr := testUnixAddr() taddr := testUnixAddr()
...@@ -290,9 +294,10 @@ func TestUnixConnLocalAndRemoteNames(t *testing.T) { ...@@ -290,9 +294,10 @@ func TestUnixConnLocalAndRemoteNames(t *testing.T) {
} }
func TestUnixgramConnLocalAndRemoteNames(t *testing.T) { func TestUnixgramConnLocalAndRemoteNames(t *testing.T) {
if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") { if !testableNetwork("unixgram") {
t.Skipf("skipping unixgram test on %s/%s", runtime.GOOS, runtime.GOARCH) t.Skip("unixgram test")
} }
for _, laddr := range []string{"", testUnixAddr()} { for _, laddr := range []string{"", testUnixAddr()} {
laddr := laddr laddr := laddr
taddr := testUnixAddr() taddr := testUnixAddr()
......
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