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.
17 var unixEnabledOnAIX bool
20 if runtime.GOOS == "aix" {
21 // Unix network isn't properly working on AIX 7.2 with
22 // Technical Level < 2.
23 // The information is retrieved only once in this init()
24 // instead of everytime testableNetwork is called.
25 out, _ := exec.Command("oslevel", "-s").Output()
26 if len(out) >= len("7200-XX-ZZ-YYMM") { // AIX 7.2, Tech Level XX, Service Pack ZZ, date YYMM
27 aixVer := string(out[:4])
28 tl, _ := strconv.Atoi(string(out[5:7]))
29 unixEnabledOnAIX = aixVer > "7200" || (aixVer == "7200" && tl >= 2)
34 // testableNetwork reports whether network is testable on the current
35 // platform configuration.
36 func testableNetwork(network string) bool {
37 net, _, _ := strings.Cut(network, ":")
40 case "ip", "ip4", "ip6":
49 case "unix", "unixgram":
51 case "android", "ios", "plan9", "windows":
54 return unixEnabledOnAIX
58 case "aix", "android", "darwin", "ios", "plan9", "windows":
63 case "tcp4", "udp4", "ip4":
67 case "tcp6", "udp6", "ip6":
75 // testableAddress reports whether address of network is testable on
76 // the current platform configuration.
77 func testableAddress(network, address string) bool {
78 switch net, _, _ := strings.Cut(network, ":"); net {
79 case "unix", "unixgram", "unixpacket":
80 // Abstract unix domain sockets, a Linux-ism.
81 if address[0] == '@' && runtime.GOOS != "linux" {
88 // testableListenArgs reports whether arguments are testable on the
89 // current platform configuration.
90 func testableListenArgs(network, address, client string) bool {
91 if !testableNetwork(network) || !testableAddress(network, address) {
97 switch net, _, _ := strings.Cut(network, ":"); net {
98 case "tcp", "tcp4", "tcp6":
99 addr, err = ResolveTCPAddr("tcp", address)
100 case "udp", "udp4", "udp6":
101 addr, err = ResolveUDPAddr("udp", address)
102 case "ip", "ip4", "ip6":
103 addr, err = ResolveIPAddr("ip", address)
112 switch addr := addr.(type) {
115 wildcard = addr.isWildcard()
118 wildcard = addr.isWildcard()
121 wildcard = addr.isWildcard()
124 // Test wildcard IP addresses.
125 if wildcard && !testenv.HasExternalNetwork() {
129 // Test functionality of IPv4 communication using AF_INET and
130 // IPv6 communication using AF_INET6 sockets.
131 if !supportsIPv4() && ip.To4() != nil {
134 if !supportsIPv6() && ip.To16() != nil && ip.To4() == nil {
137 cip := ParseIP(client)
139 if !supportsIPv4() && cip.To4() != nil {
142 if !supportsIPv6() && cip.To16() != nil && cip.To4() == nil {
147 // Test functionality of IPv4 communication using AF_INET6
149 if !supportsIPv4map() && supportsIPv4() && (network == "tcp" || network == "udp" || network == "ip") && wildcard {
150 // At this point, we prefer IPv4 when ip is nil.
151 // See favoriteAddrFamily for further information.
152 if ip.To16() != nil && ip.To4() == nil && cip.To4() != nil { // a pair of IPv6 server and IPv4 client
155 if (ip.To4() != nil || ip == nil) && cip.To16() != nil && cip.To4() == nil { // a pair of IPv4 server and IPv6 client
163 func condFatalf(t *testing.T, network string, format string, args ...any) {
165 // A few APIs like File and Read/WriteMsg{UDP,IP} are not
166 // fully implemented yet on Plan 9 and Windows.
167 switch runtime.GOOS {
168 case "windows", "js", "wasip1":
169 if network == "file+net" {
170 t.Logf(format, args...)
174 t.Logf(format, args...)
177 t.Fatalf(format, args...)