all: use of nettest, remove internal/nettest
This change uses the nettest package where possible and removes the
internal/nettest package.
Change-Id: I5615a3ab7957183fecea6b5646df99dbb7c186e2
Reviewed-on: https://go-review.googlesource.com/c/net/+/123057
Run-TryBot: Mikio Hara <mikioh.public.networking@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matt Layher <mdlayher@gmail.com>
diff --git a/icmp/diag_test.go b/icmp/diag_test.go
index d2c1342..8437690 100644
--- a/icmp/diag_test.go
+++ b/icmp/diag_test.go
@@ -17,9 +17,9 @@
"golang.org/x/net/icmp"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
var testDiag = flag.Bool("diag", false, "whether to test ICMP message exchange with external network")
@@ -68,8 +68,8 @@
}
})
t.Run("Ping/Privileged", func(t *testing.T) {
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
for i, dt := range []diagTest{
{
@@ -100,8 +100,8 @@
}
})
t.Run("Probe/Privileged", func(t *testing.T) {
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
for i, dt := range []diagTest{
{
diff --git a/internal/nettest/helper_bsd.go b/internal/nettest/helper_bsd.go
deleted file mode 100644
index 4025bd2..0000000
--- a/internal/nettest/helper_bsd.go
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2016 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 netbsd openbsd
-
-package nettest
-
-import (
- "runtime"
-)
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- switch runtime.GOOS {
- case "freebsd":
- // See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
- // Even after the fix, it looks like the latest
- // kernels don't deliver link-local scoped multicast
- // packets correctly.
- return false
- default:
- return true
- }
-}
diff --git a/internal/nettest/helper_nobsd.go b/internal/nettest/helper_nobsd.go
deleted file mode 100644
index bfcaee9..0000000
--- a/internal/nettest/helper_nobsd.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2016 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 aix linux solaris
-
-package nettest
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return true
-}
diff --git a/internal/nettest/helper_stub.go b/internal/nettest/helper_stub.go
deleted file mode 100644
index 2eeeb35..0000000
--- a/internal/nettest/helper_stub.go
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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 js nacl plan9
-
-package nettest
-
-import (
- "fmt"
- "runtime"
-)
-
-func maxOpenFiles() int {
- return defaultMaxOpenFiles
-}
-
-func supportsRawIPSocket() (string, bool) {
- return fmt.Sprintf("not supported on %s", runtime.GOOS), false
-}
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return false
-}
-
-func protocolNotSupported(err error) bool {
- return false
-}
diff --git a/internal/nettest/helper_windows.go b/internal/nettest/helper_windows.go
deleted file mode 100644
index b0a6a30..0000000
--- a/internal/nettest/helper_windows.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// 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 nettest
-
-import (
- "fmt"
- "runtime"
- "syscall"
-)
-
-func maxOpenFiles() int {
- return 4 * defaultMaxOpenFiles /* actually it's 16581375 */
-}
-
-func supportsRawIPSocket() (string, bool) {
- // From http://msdn.microsoft.com/en-us/library/windows/desktop/ms740548.aspx:
- // Note: To use a socket of type SOCK_RAW requires administrative privileges.
- // Users running Winsock applications that use raw sockets must be a member of
- // the Administrators group on the local computer, otherwise raw socket calls
- // will fail with an error code of WSAEACCES. On Windows Vista and later, access
- // for raw sockets is enforced at socket creation. In earlier versions of Windows,
- // access for raw sockets is enforced during other socket operations.
- s, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, 0)
- if err == syscall.WSAEACCES {
- return fmt.Sprintf("no access to raw socket allowed on %s", runtime.GOOS), false
- }
- if err != nil {
- return err.Error(), false
- }
- syscall.Closesocket(s)
- return "", true
-}
-
-func supportsIPv6MulticastDeliveryOnLoopback() bool {
- return true
-}
diff --git a/internal/nettest/interface.go b/internal/nettest/interface.go
deleted file mode 100644
index 8e6333a..0000000
--- a/internal/nettest/interface.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright 2012 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 nettest
-
-import "net"
-
-// IsMulticastCapable reports whether ifi is an IP multicast-capable
-// network interface. Network must be "ip", "ip4" or "ip6".
-func IsMulticastCapable(network string, ifi *net.Interface) (net.IP, bool) {
- switch network {
- case "ip", "ip4", "ip6":
- default:
- return nil, false
- }
- if ifi == nil || ifi.Flags&net.FlagUp == 0 || ifi.Flags&net.FlagMulticast == 0 {
- return nil, false
- }
- return hasRoutableIP(network, ifi)
-}
-
-// RoutedInterface returns a network interface that can route IP
-// traffic and satisfies flags. It returns nil when an appropriate
-// network interface is not found. Network must be "ip", "ip4" or
-// "ip6".
-func RoutedInterface(network string, flags net.Flags) *net.Interface {
- switch network {
- case "ip", "ip4", "ip6":
- default:
- return nil
- }
- ift, err := net.Interfaces()
- if err != nil {
- return nil
- }
- for _, ifi := range ift {
- if ifi.Flags&flags != flags {
- continue
- }
- if _, ok := hasRoutableIP(network, &ifi); !ok {
- continue
- }
- return &ifi
- }
- return nil
-}
-
-func hasRoutableIP(network string, ifi *net.Interface) (net.IP, bool) {
- ifat, err := ifi.Addrs()
- if err != nil {
- return nil, false
- }
- for _, ifa := range ifat {
- switch ifa := ifa.(type) {
- case *net.IPAddr:
- if ip := routableIP(network, ifa.IP); ip != nil {
- return ip, true
- }
- case *net.IPNet:
- if ip := routableIP(network, ifa.IP); ip != nil {
- return ip, true
- }
- }
- }
- return nil, false
-}
-
-func routableIP(network string, ip net.IP) net.IP {
- if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsGlobalUnicast() {
- return nil
- }
- switch network {
- case "ip4":
- if ip := ip.To4(); ip != nil {
- return ip
- }
- case "ip6":
- if ip.IsLoopback() { // addressing scope of the loopback address depends on each implementation
- return nil
- }
- if ip := ip.To16(); ip != nil && ip.To4() == nil {
- return ip
- }
- default:
- if ip := ip.To4(); ip != nil {
- return ip
- }
- if ip := ip.To16(); ip != nil {
- return ip
- }
- }
- return nil
-}
diff --git a/internal/nettest/rlimit.go b/internal/nettest/rlimit.go
deleted file mode 100644
index bb34aec..0000000
--- a/internal/nettest/rlimit.go
+++ /dev/null
@@ -1,11 +0,0 @@
-// 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 nettest
-
-const defaultMaxOpenFiles = 256
-
-// MaxOpenFiles returns the maximum number of open files for the
-// caller's process.
-func MaxOpenFiles() int { return maxOpenFiles() }
diff --git a/internal/nettest/stack.go b/internal/nettest/stack.go
deleted file mode 100644
index 3b8a01e..0000000
--- a/internal/nettest/stack.go
+++ /dev/null
@@ -1,152 +0,0 @@
-// 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.
-
-// Package nettest provides utilities for network testing.
-package nettest // import "golang.org/x/net/internal/nettest"
-
-import (
- "fmt"
- "io/ioutil"
- "net"
- "os"
- "runtime"
-)
-
-var (
- supportsIPv4 bool
- supportsIPv6 bool
-)
-
-func init() {
- if ln, err := net.Listen("tcp4", "127.0.0.1:0"); err == nil {
- ln.Close()
- supportsIPv4 = true
- }
- if ln, err := net.Listen("tcp6", "[::1]:0"); err == nil {
- ln.Close()
- supportsIPv6 = true
- }
-}
-
-// SupportsIPv4 reports whether the platform supports IPv4 networking
-// functionality.
-func SupportsIPv4() bool { return supportsIPv4 }
-
-// SupportsIPv6 reports whether the platform supports IPv6 networking
-// functionality.
-func SupportsIPv6() bool { return supportsIPv6 }
-
-// SupportsRawIPSocket reports whether the platform supports raw IP
-// sockets.
-func SupportsRawIPSocket() (string, bool) {
- return supportsRawIPSocket()
-}
-
-// SupportsIPv6MulticastDeliveryOnLoopback reports whether the
-// platform supports IPv6 multicast packet delivery on software
-// loopback interface.
-func SupportsIPv6MulticastDeliveryOnLoopback() bool {
- return supportsIPv6MulticastDeliveryOnLoopback()
-}
-
-// ProtocolNotSupported reports whether err is a protocol not
-// supported error.
-func ProtocolNotSupported(err error) bool {
- return protocolNotSupported(err)
-}
-
-// TestableNetwork reports whether network is testable on the current
-// platform configuration.
-func TestableNetwork(network string) bool {
- // This is based on logic from standard library's
- // net/platform_test.go.
- switch network {
- case "unix", "unixgram":
- switch runtime.GOOS {
- case "android", "js", "nacl", "plan9", "windows":
- return false
- }
- if runtime.GOOS == "darwin" && (runtime.GOARCH == "arm" || runtime.GOARCH == "arm64") {
- return false
- }
- case "unixpacket":
- switch runtime.GOOS {
- case "aix", "android", "darwin", "freebsd", "js", "nacl", "plan9", "windows":
- return false
- case "netbsd":
- // It passes on amd64 at least. 386 fails (Issue 22927). arm is unknown.
- if runtime.GOARCH == "386" {
- return false
- }
- }
- }
- return true
-}
-
-// NewLocalListener returns a listener which listens to a loopback IP
-// address or local file system path.
-// Network must be "tcp", "tcp4", "tcp6", "unix" or "unixpacket".
-func NewLocalListener(network string) (net.Listener, error) {
- switch network {
- case "tcp":
- if supportsIPv4 {
- if ln, err := net.Listen("tcp4", "127.0.0.1:0"); err == nil {
- return ln, nil
- }
- }
- if supportsIPv6 {
- return net.Listen("tcp6", "[::1]:0")
- }
- case "tcp4":
- if supportsIPv4 {
- return net.Listen("tcp4", "127.0.0.1:0")
- }
- case "tcp6":
- if supportsIPv6 {
- return net.Listen("tcp6", "[::1]:0")
- }
- case "unix", "unixpacket":
- return net.Listen(network, localPath())
- }
- return nil, fmt.Errorf("%s is not supported", network)
-}
-
-// NewLocalPacketListener returns a packet listener which listens to a
-// loopback IP address or local file system path.
-// Network must be "udp", "udp4", "udp6" or "unixgram".
-func NewLocalPacketListener(network string) (net.PacketConn, error) {
- switch network {
- case "udp":
- if supportsIPv4 {
- if c, err := net.ListenPacket("udp4", "127.0.0.1:0"); err == nil {
- return c, nil
- }
- }
- if supportsIPv6 {
- return net.ListenPacket("udp6", "[::1]:0")
- }
- case "udp4":
- if supportsIPv4 {
- return net.ListenPacket("udp4", "127.0.0.1:0")
- }
- case "udp6":
- if supportsIPv6 {
- return net.ListenPacket("udp6", "[::1]:0")
- }
- case "unixgram":
- return net.ListenPacket(network, localPath())
- }
- return nil, fmt.Errorf("%s is not supported", network)
-}
-
-func localPath() string {
- f, err := ioutil.TempFile("", "nettest")
- if err != nil {
- panic(err)
- }
- path := f.Name()
- f.Close()
- os.Remove(path)
- return path
-}
diff --git a/internal/socket/socket_test.go b/internal/socket/socket_test.go
index 5de1b9f..3d9e77e 100644
--- a/internal/socket/socket_test.go
+++ b/internal/socket/socket_test.go
@@ -14,8 +14,8 @@
"syscall"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/internal/socket"
+ "golang.org/x/net/nettest"
)
func TestSocket(t *testing.T) {
diff --git a/internal/sockstest/server.go b/internal/sockstest/server.go
index 3c6e9e9..dc2fa67 100644
--- a/internal/sockstest/server.go
+++ b/internal/sockstest/server.go
@@ -10,8 +10,8 @@
"io"
"net"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/internal/socks"
+ "golang.org/x/net/nettest"
)
// An AuthRequest represents an authentication request.
diff --git a/internal/nettest/helper_posix.go b/ipv4/helper_posix_test.go
similarity index 96%
copy from internal/nettest/helper_posix.go
copy to ipv4/helper_posix_test.go
index efc67a8..ee66dd2 100644
--- a/internal/nettest/helper_posix.go
+++ b/ipv4/helper_posix_test.go
@@ -4,7 +4,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
-package nettest
+package ipv4_test
import (
"os"
diff --git a/ipv4/helper_stub_test.go b/ipv4/helper_stub_test.go
new file mode 100644
index 0000000..4ba0171
--- /dev/null
+++ b/ipv4/helper_stub_test.go
@@ -0,0 +1,11 @@
+// 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 !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
+
+package ipv4_test
+
+func protocolNotSupported(err error) bool {
+ return false
+}
diff --git a/ipv4/icmp_test.go b/ipv4/icmp_test.go
index 3324b54..d51acce 100644
--- a/ipv4/icmp_test.go
+++ b/ipv4/icmp_test.go
@@ -10,8 +10,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
var icmpStringTests = []struct {
@@ -66,8 +66,8 @@
default:
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket("ip4:icmp", "127.0.0.1")
diff --git a/ipv4/multicast_test.go b/ipv4/multicast_test.go
index fd9efe0..7271dd0 100644
--- a/ipv4/multicast_test.go
+++ b/ipv4/multicast_test.go
@@ -14,8 +14,8 @@
"golang.org/x/net/icmp"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
var packetConnReadWriteMulticastUDPTests = []struct {
@@ -32,8 +32,8 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "solaris", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -82,7 +82,7 @@
for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -120,11 +120,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "solaris", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -184,7 +184,7 @@
t.Fatal(err)
}
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -234,11 +234,11 @@
if testing.Short() {
t.Skip("to avoid external network")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -305,7 +305,7 @@
Dst: tt.grp.IP,
}
if err := r.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
diff --git a/ipv4/multicastlistener_test.go b/ipv4/multicastlistener_test.go
index 73e509d..591489e 100644
--- a/ipv4/multicastlistener_test.go
+++ b/ipv4/multicastlistener_test.go
@@ -9,8 +9,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
var udpMultipleGroupListenerTests = []net.Addr{
@@ -43,7 +43,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip4", &ifi); err != nil {
continue
}
if err := p.JoinGroup(&ifi, gaddr); err != nil {
@@ -94,7 +94,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip4", &ifi); err != nil {
continue
}
for _, p := range ps {
@@ -136,8 +136,8 @@
}
port := "0"
for i, ifi := range ift {
- ip, ok := nettest.IsMulticastCapable("ip4", &ifi)
- if !ok {
+ ip, err := nettest.MulticastSource("ip4", &ifi)
+ if err != nil {
continue
}
c, err := net.ListenPacket("udp4", net.JoinHostPort(ip.String(), port)) // unicast address with non-reusable port
@@ -178,8 +178,8 @@
if testing.Short() {
t.Skip("to avoid external network")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket("ip4:icmp", "0.0.0.0") // wildcard address
@@ -200,7 +200,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip4", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip4", &ifi); err != nil {
continue
}
if err := r.JoinGroup(&ifi, &gaddr); err != nil {
@@ -223,8 +223,8 @@
if testing.Short() {
t.Skip("to avoid external network")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
gaddr := net.IPAddr{IP: net.IPv4(224, 0, 0, 254)} // see RFC 4727
@@ -239,8 +239,8 @@
t.Fatal(err)
}
for i, ifi := range ift {
- ip, ok := nettest.IsMulticastCapable("ip4", &ifi)
- if !ok {
+ ip, err := nettest.MulticastSource("ip4", &ifi)
+ if err != nil {
continue
}
c, err := net.ListenPacket("ip4:253", ip.String()) // unicast address
diff --git a/ipv4/multicastsockopt_test.go b/ipv4/multicastsockopt_test.go
index fd783d0..e9f2c57 100644
--- a/ipv4/multicastsockopt_test.go
+++ b/ipv4/multicastsockopt_test.go
@@ -9,8 +9,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
var packetConnMulticastSocketOptionTests = []struct {
@@ -29,15 +29,15 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
- m, ok := nettest.SupportsRawIPSocket()
+ ok := nettest.SupportsRawSocket()
for _, tt := range packetConnMulticastSocketOptionTests {
if tt.net == "ip4" && !ok {
- t.Log(m)
+ t.Logf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
@@ -69,11 +69,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
diff --git a/ipv4/readwrite_test.go b/ipv4/readwrite_test.go
index acf87d1..5b8b9d3 100644
--- a/ipv4/readwrite_test.go
+++ b/ipv4/readwrite_test.go
@@ -14,8 +14,8 @@
"testing"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
func BenchmarkReadWriteUnicast(b *testing.B) {
@@ -50,7 +50,7 @@
b.Fatal(err)
}
cm := ipv4.ControlMessage{TTL: 1}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -91,7 +91,8 @@
cm := ipv4.ControlMessage{
Src: net.IPv4(127, 0, 0, 1),
}
- if ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); ifi != nil {
+ ifi, _ := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
+ if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -231,12 +232,12 @@
defer p.Close()
dst := c.LocalAddr()
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
cf := ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst | ipv4.FlagInterface
wb := []byte("HELLO-R-U-THERE")
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Skipf("not supported on %s", runtime.GOOS)
}
t.Fatal(err)
@@ -358,11 +359,11 @@
func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv4.PacketConn, data []byte, dst net.Addr, batch bool) {
t.Helper()
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
cf := ipv4.FlagTTL | ipv4.FlagSrc | ipv4.FlagDst | ipv4.FlagInterface
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Skipf("not supported on %s", runtime.GOOS)
}
t.Fatal(err)
diff --git a/ipv4/unicast_test.go b/ipv4/unicast_test.go
index a75f54e..a4ddfb7 100644
--- a/ipv4/unicast_test.go
+++ b/ipv4/unicast_test.go
@@ -14,8 +14,8 @@
"golang.org/x/net/icmp"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
@@ -23,8 +23,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -42,7 +41,7 @@
for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -74,11 +73,10 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -112,7 +110,7 @@
t.Fatal(err)
}
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -160,11 +158,10 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -206,7 +203,7 @@
Dst: dst.IP,
}
if err := r.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
diff --git a/ipv4/unicastsockopt_test.go b/ipv4/unicastsockopt_test.go
index 9a279b7..7ff9acc 100644
--- a/ipv4/unicastsockopt_test.go
+++ b/ipv4/unicastsockopt_test.go
@@ -10,8 +10,8 @@
"testing"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv4"
+ "golang.org/x/net/nettest"
)
func TestConnUnicastSocketOptions(t *testing.T) {
@@ -19,8 +19,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -65,15 +64,14 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
- m, ok := nettest.SupportsRawIPSocket()
+ ok := nettest.SupportsRawSocket()
for _, tt := range packetConnUnicastSocketOptionTests {
if tt.net == "ip4" && !ok {
- t.Log(m)
+ t.Logf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
@@ -91,11 +89,10 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
- ifi := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback)
- if ifi == nil {
+ if _, err := nettest.RoutedInterface("ip4", net.FlagUp|net.FlagLoopback); err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
diff --git a/ipv6/bpf_test.go b/ipv6/bpf_test.go
index 8253e1f..e249e1c 100644
--- a/ipv6/bpf_test.go
+++ b/ipv6/bpf_test.go
@@ -12,13 +12,14 @@
"golang.org/x/net/bpf"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
func TestBPF(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
diff --git a/internal/nettest/helper_posix.go b/ipv6/helper_posix_test.go
similarity index 96%
rename from internal/nettest/helper_posix.go
rename to ipv6/helper_posix_test.go
index efc67a8..cc85cea 100644
--- a/internal/nettest/helper_posix.go
+++ b/ipv6/helper_posix_test.go
@@ -4,7 +4,7 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris windows
-package nettest
+package ipv6_test
import (
"os"
diff --git a/ipv6/helper_stub_test.go b/ipv6/helper_stub_test.go
new file mode 100644
index 0000000..cc515d1
--- /dev/null
+++ b/ipv6/helper_stub_test.go
@@ -0,0 +1,20 @@
+// 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 !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
+
+package ipv6_test
+
+import (
+ "fmt"
+ "runtime"
+)
+
+func supportsIPv6MulticastDeliveryOnLoopback() (string, bool) {
+ return fmt.Sprintf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH), false
+}
+
+func protocolNotSupported(err error) bool {
+ return false
+}
diff --git a/ipv6/helper_unix_test.go b/ipv6/helper_unix_test.go
new file mode 100644
index 0000000..d94d912
--- /dev/null
+++ b/ipv6/helper_unix_test.go
@@ -0,0 +1,25 @@
+// 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.
+
+// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
+
+package ipv6_test
+
+import (
+ "fmt"
+ "runtime"
+)
+
+func supportsIPv6MulticastDeliveryOnLoopback() (string, bool) {
+ switch runtime.GOOS {
+ case "freebsd":
+ // See http://www.freebsd.org/cgi/query-pr.cgi?pr=180065.
+ // Even after the fix, it looks like the latest
+ // kernels don't deliver link-local scoped multicast
+ // packets correctly.
+ return fmt.Sprintf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH), false
+ default:
+ return "", true
+ }
+}
diff --git a/ipv6/helper_windows_test.go b/ipv6/helper_windows_test.go
new file mode 100644
index 0000000..329cfde
--- /dev/null
+++ b/ipv6/helper_windows_test.go
@@ -0,0 +1,9 @@
+// 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 ipv6_test
+
+func supportsIPv6MulticastDeliveryOnLoopback() (string, bool) {
+ return "", true
+}
diff --git a/ipv6/icmp_test.go b/ipv6/icmp_test.go
index 940a7aa..c4b5904 100644
--- a/ipv6/icmp_test.go
+++ b/ipv6/icmp_test.go
@@ -10,8 +10,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
var icmpStringTests = []struct {
@@ -64,11 +64,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
diff --git a/ipv6/multicast_test.go b/ipv6/multicast_test.go
index 6ca6fd1..8331e27 100644
--- a/ipv6/multicast_test.go
+++ b/ipv6/multicast_test.go
@@ -14,8 +14,8 @@
"golang.org/x/net/icmp"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
var packetConnReadWriteMulticastUDPTests = []struct {
@@ -32,14 +32,14 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if !nettest.SupportsIPv6MulticastDeliveryOnLoopback() {
- t.Skipf("multicast delivery doesn't work correctly on %s", runtime.GOOS)
+ if m, ok := supportsIPv6MulticastDeliveryOnLoopback(); !ok {
+ t.Skip(m)
}
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -94,7 +94,7 @@
for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -132,17 +132,17 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if !nettest.SupportsIPv6MulticastDeliveryOnLoopback() {
- t.Skipf("multicast delivery doesn't work correctly on %s", runtime.GOOS)
- }
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
+ if m, ok := supportsIPv6MulticastDeliveryOnLoopback(); !ok {
t.Skip(m)
}
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
+ }
+ ifi, err := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
@@ -229,7 +229,7 @@
t.Fatal(err)
}
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
diff --git a/ipv6/multicastlistener_test.go b/ipv6/multicastlistener_test.go
index 91d2b1d..9ca5359 100644
--- a/ipv6/multicastlistener_test.go
+++ b/ipv6/multicastlistener_test.go
@@ -9,8 +9,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
var udpMultipleGroupListenerTests = []net.Addr{
@@ -24,7 +24,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -43,7 +43,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip6", &ifi); err != nil {
continue
}
if err := p.JoinGroup(&ifi, gaddr); err != nil {
@@ -64,7 +64,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -94,7 +94,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip6", &ifi); err != nil {
continue
}
for _, p := range ps {
@@ -119,7 +119,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -136,8 +136,8 @@
}
port := "0"
for i, ifi := range ift {
- ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
- if !ok {
+ ip, err := nettest.MulticastSource("ip6", &ifi)
+ if err != nil {
continue
}
c, err := net.ListenPacket("udp6", net.JoinHostPort(ip.String()+"%"+ifi.Name, port)) // unicast address with non-reusable port
@@ -175,11 +175,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket("ip6:ipv6-icmp", "::") // wildcard address
@@ -197,7 +197,7 @@
t.Fatal(err)
}
for i, ifi := range ift {
- if _, ok := nettest.IsMulticastCapable("ip6", &ifi); !ok {
+ if _, err := nettest.MulticastSource("ip6", &ifi); err != nil {
continue
}
if err := p.JoinGroup(&ifi, &gaddr); err != nil {
@@ -219,11 +219,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
gaddr := net.IPAddr{IP: net.ParseIP("ff02::114")} // see RFC 4727
@@ -238,8 +238,8 @@
t.Fatal(err)
}
for i, ifi := range ift {
- ip, ok := nettest.IsMulticastCapable("ip6", &ifi)
- if !ok {
+ ip, err := nettest.MulticastSource("ip6", &ifi)
+ if err != nil {
continue
}
c, err := net.ListenPacket("ip6:ipv6-icmp", ip.String()+"%"+ifi.Name) // unicast address
diff --git a/ipv6/multicastsockopt_test.go b/ipv6/multicastsockopt_test.go
index 2cb2da2..a399945 100644
--- a/ipv6/multicastsockopt_test.go
+++ b/ipv6/multicastsockopt_test.go
@@ -9,8 +9,8 @@
"runtime"
"testing"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
var packetConnMulticastSocketOptionTests = []struct {
@@ -29,18 +29,18 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
- if ifi == nil {
+ ifi, err := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagMulticast|net.FlagLoopback)
+ if err != nil {
t.Skipf("not available on %s", runtime.GOOS)
}
- m, ok := nettest.SupportsRawIPSocket()
+ ok := nettest.SupportsRawSocket()
for _, tt := range packetConnMulticastSocketOptionTests {
if tt.net == "ip6" && !ok {
- t.Log(m)
+ t.Logf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
diff --git a/ipv6/readwrite_test.go b/ipv6/readwrite_test.go
index 18d5f9d..46bbf9d 100644
--- a/ipv6/readwrite_test.go
+++ b/ipv6/readwrite_test.go
@@ -14,8 +14,8 @@
"testing"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
func BenchmarkReadWriteUnicast(b *testing.B) {
@@ -53,7 +53,7 @@
TrafficClass: iana.DiffServAF11 | iana.CongestionExperienced,
HopLimit: 1,
}
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -91,7 +91,8 @@
HopLimit: 1,
Src: net.IPv6loopback,
}
- if ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback); ifi != nil {
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -221,7 +222,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -234,12 +235,12 @@
defer p.Close()
dst := c.LocalAddr()
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
wb := []byte("HELLO-R-U-THERE")
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Skipf("not supported on %s", runtime.GOOS)
}
t.Fatal(err)
@@ -357,11 +358,11 @@
func testPacketConnConcurrentReadWriteUnicast(t *testing.T, p *ipv6.PacketConn, data []byte, dst net.Addr, batch bool) {
t.Helper()
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
if err := p.SetControlMessage(cf, true); err != nil { // probe before test
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Skipf("not supported on %s", runtime.GOOS)
}
t.Fatal(err)
diff --git a/ipv6/sockopt_test.go b/ipv6/sockopt_test.go
index 0ff911d..a438c69 100644
--- a/ipv6/sockopt_test.go
+++ b/ipv6/sockopt_test.go
@@ -11,18 +11,16 @@
"testing"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
-var supportsIPv6 bool = nettest.SupportsIPv6()
-
func TestConnInitiatorPathMTU(t *testing.T) {
switch runtime.GOOS {
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -60,7 +58,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -98,11 +96,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket(fmt.Sprintf("ip6:%d", iana.ProtocolOSPFIGP), "::") // OSPF for IPv6
diff --git a/ipv6/unicast_test.go b/ipv6/unicast_test.go
index 25fb4eb..15831f9 100644
--- a/ipv6/unicast_test.go
+++ b/ipv6/unicast_test.go
@@ -14,8 +14,8 @@
"golang.org/x/net/icmp"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
@@ -23,7 +23,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -41,7 +41,7 @@
Src: net.IPv6loopback,
}
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -49,7 +49,7 @@
for i, toggle := range []bool{true, false, true} {
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
@@ -81,11 +81,11 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- if m, ok := nettest.SupportsRawIPSocket(); !ok {
- t.Skip(m)
+ if !nettest.SupportsRawSocket() {
+ t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
}
c, err := net.ListenPacket("ip6:ipv6-icmp", "::1")
@@ -107,7 +107,7 @@
Src: net.IPv6loopback,
}
cf := ipv6.FlagTrafficClass | ipv6.FlagHopLimit | ipv6.FlagSrc | ipv6.FlagDst | ipv6.FlagInterface | ipv6.FlagPathMTU
- ifi := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
+ ifi, _ := nettest.RoutedInterface("ip6", net.FlagUp|net.FlagLoopback)
if ifi != nil {
cm.IfIndex = ifi.Index
}
@@ -147,7 +147,7 @@
t.Fatal(err)
}
if err := p.SetControlMessage(cf, toggle); err != nil {
- if nettest.ProtocolNotSupported(err) {
+ if protocolNotSupported(err) {
t.Logf("not supported on %s", runtime.GOOS)
continue
}
diff --git a/ipv6/unicastsockopt_test.go b/ipv6/unicastsockopt_test.go
index 2f83373..84fdfd6 100644
--- a/ipv6/unicastsockopt_test.go
+++ b/ipv6/unicastsockopt_test.go
@@ -10,8 +10,8 @@
"testing"
"golang.org/x/net/internal/iana"
- "golang.org/x/net/internal/nettest"
"golang.org/x/net/ipv6"
+ "golang.org/x/net/nettest"
)
func TestConnUnicastSocketOptions(t *testing.T) {
@@ -19,7 +19,7 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
@@ -64,14 +64,14 @@
case "aix", "fuchsia", "hurd", "js", "nacl", "plan9", "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
- if !supportsIPv6 {
+ if !nettest.SupportsIPv6() {
t.Skip("ipv6 is not supported")
}
- m, ok := nettest.SupportsRawIPSocket()
+ ok := nettest.SupportsRawSocket()
for _, tt := range packetConnUnicastSocketOptionTests {
if tt.net == "ip6" && !ok {
- t.Log(m)
+ t.Logf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
continue
}
c, err := net.ListenPacket(tt.net+tt.proto, tt.addr)
diff --git a/netutil/helper_stub_test.go b/netutil/helper_stub_test.go
new file mode 100644
index 0000000..6034aac
--- /dev/null
+++ b/netutil/helper_stub_test.go
@@ -0,0 +1,11 @@
+// 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 !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris,!windows
+
+package netutil
+
+func maxOpenFiles() int {
+ return defaultMaxOpenFiles
+}
diff --git a/internal/nettest/helper_unix.go b/netutil/helper_unix_test.go
similarity index 64%
rename from internal/nettest/helper_unix.go
rename to netutil/helper_unix_test.go
index b6839dc..fd71243 100644
--- a/internal/nettest/helper_unix.go
+++ b/netutil/helper_unix_test.go
@@ -4,14 +4,9 @@
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
-package nettest
+package netutil
-import (
- "fmt"
- "os"
- "runtime"
- "syscall"
-)
+import "syscall"
func maxOpenFiles() int {
var rlim syscall.Rlimit
@@ -20,10 +15,3 @@
}
return int(rlim.Cur)
}
-
-func supportsRawIPSocket() (string, bool) {
- if os.Getuid() != 0 {
- return fmt.Sprintf("must be root on %s", runtime.GOOS), false
- }
- return "", true
-}
diff --git a/netutil/helper_windows_test.go b/netutil/helper_windows_test.go
new file mode 100644
index 0000000..8d5703d
--- /dev/null
+++ b/netutil/helper_windows_test.go
@@ -0,0 +1,9 @@
+// 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 netutil
+
+func maxOpenFiles() int {
+ return 4 * defaultMaxOpenFiles /* actually it's 16581375 */
+}
diff --git a/netutil/listen_test.go b/netutil/listen_test.go
index f40c9aa..e00433d 100644
--- a/netutil/listen_test.go
+++ b/netutil/listen_test.go
@@ -15,13 +15,13 @@
"sync/atomic"
"testing"
"time"
-
- "golang.org/x/net/internal/nettest"
)
+const defaultMaxOpenFiles = 256
+
func TestLimitListener(t *testing.T) {
const max = 5
- attempts := (nettest.MaxOpenFiles() - max) / 2
+ attempts := (maxOpenFiles() - max) / 2
if attempts > 256 { // maximum length of accept queue is 128 by default
attempts = 256
}