1 // Copyright 2015 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.
15 // testableNetwork reports whether network is testable on the current
16 // platform configuration.
17 func testableNetwork(network
string) bool {
18 ss
:= strings
.Split(network
, ":")
25 case "ip", "ip4", "ip6":
34 case "unix", "unixgram":
36 case "android", "nacl", "plan9", "windows":
39 // iOS does not support unix, unixgram.
40 if runtime
.GOOS
== "darwin" && (runtime
.GOARCH
== "arm" || runtime
.GOARCH
== "arm64") {
45 case "android", "darwin", "nacl", "plan9", "windows":
48 // It passes on amd64 at least. 386 fails (Issue 22927). arm is unknown.
49 if runtime
.GOARCH
== "386" {
55 case "tcp4", "udp4", "ip4":
59 case "tcp6", "udp6", "ip6":
67 // testableAddress reports whether address of network is testable on
68 // the current platform configuration.
69 func testableAddress(network
, address
string) bool {
70 switch ss
:= strings
.Split(network
, ":"); ss
[0] {
71 case "unix", "unixgram", "unixpacket":
72 // Abstract unix domain sockets, a Linux-ism.
73 if address
[0] == '@' && runtime
.GOOS
!= "linux" {
80 // testableListenArgs reports whether arguments are testable on the
81 // current platform configuration.
82 func testableListenArgs(network
, address
, client
string) bool {
83 if !testableNetwork(network
) ||
!testableAddress(network
, address
) {
89 switch ss
:= strings
.Split(network
, ":"); ss
[0] {
90 case "tcp", "tcp4", "tcp6":
91 addr
, err
= ResolveTCPAddr("tcp", address
)
92 case "udp", "udp4", "udp6":
93 addr
, err
= ResolveUDPAddr("udp", address
)
94 case "ip", "ip4", "ip6":
95 addr
, err
= ResolveIPAddr("ip", address
)
104 switch addr
:= addr
.(type) {
107 wildcard
= addr
.isWildcard()
110 wildcard
= addr
.isWildcard()
113 wildcard
= addr
.isWildcard()
116 // Test wildcard IP addresses.
117 if wildcard
&& !testenv
.HasExternalNetwork() {
121 // Test functionality of IPv4 communication using AF_INET and
122 // IPv6 communication using AF_INET6 sockets.
123 if !supportsIPv4() && ip
.To4() != nil {
126 if !supportsIPv6() && ip
.To16() != nil && ip
.To4() == nil {
129 cip
:= ParseIP(client
)
131 if !supportsIPv4() && cip
.To4() != nil {
134 if !supportsIPv6() && cip
.To16() != nil && cip
.To4() == nil {
139 // Test functionality of IPv4 communication using AF_INET6
141 if !supportsIPv4map() && supportsIPv4() && (network
== "tcp" || network
== "udp" || network
== "ip") && wildcard
{
142 // At this point, we prefer IPv4 when ip is nil.
143 // See favoriteAddrFamily for further information.
144 if ip
.To16() != nil && ip
.To4() == nil && cip
.To4() != nil { // a pair of IPv6 server and IPv4 client
147 if (ip
.To4() != nil || ip
== nil) && cip
.To16() != nil && cip
.To4() == nil { // a pair of IPv4 server and IPv6 client
155 func condFatalf(t
*testing
.T
, network
string, format
string, args
...interface{}) {
157 // A few APIs like File and Read/WriteMsg{UDP,IP} are not
158 // fully implemented yet on Plan 9 and Windows.
159 switch runtime
.GOOS
{
161 if network
== "file+net" {
162 t
.Logf(format
, args
...)
166 t
.Logf(format
, args
...)
169 t
.Fatalf(format
, args
...)