Skip to content

Commit 0bfab66

Browse files
tklausergopherbot
authored andcommitted
ipv4, ipv6: drop redundant skip checks based on GOOS
All the dropped platforms either don't support raw sockets or the tests pass sucessfully (e.g. ipv4.TestPacketConnReadWriteMulticastICMP on solaris), so the tests can rely on being skipped due to !nettest.SupportsRawSocket(). Also check for errNotImplemented to cover cases where functionality is not available on windows. Change-Id: Ic9107a7ca16e9d9faed4991e1148b493c646ea7d Reviewed-on: https://go-review.googlesource.com/c/net/+/489155 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
1 parent 938ff15 commit 0bfab66

13 files changed

+35
-55
lines changed

ipv4/export_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 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.
4+
5+
package ipv4
6+
7+
var ErrNotImplemented = errNotImplemented

ipv4/helper_posix_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
package ipv4_test
99

1010
import (
11+
"errors"
1112
"os"
1213
"syscall"
14+
15+
"golang.org/x/net/ipv4"
1316
)
1417

1518
func protocolNotSupported(err error) bool {
@@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
2831
}
2932
}
3033
}
31-
return false
34+
return errors.Is(err, ipv4.ErrNotImplemented)
3235
}

ipv4/multicast_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,6 @@ var packetConnReadWriteMulticastICMPTests = []struct {
131131
}
132132

133133
func TestPacketConnReadWriteMulticastICMP(t *testing.T) {
134-
switch runtime.GOOS {
135-
case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows":
136-
t.Skipf("not supported on %s", runtime.GOOS)
137-
}
138134
if !nettest.SupportsRawSocket() {
139135
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
140136
}
@@ -261,10 +257,6 @@ var rawConnReadWriteMulticastICMPTests = []struct {
261257
}
262258

263259
func TestRawConnReadWriteMulticastICMP(t *testing.T) {
264-
switch runtime.GOOS {
265-
case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows":
266-
t.Skipf("not supported on %s", runtime.GOOS)
267-
}
268260
if testing.Short() {
269261
t.Skip("to avoid external network")
270262
}

ipv4/multicastlistener_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
171171
}
172172

173173
func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
174-
switch runtime.GOOS {
175-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
176-
t.Skipf("not supported on %s", runtime.GOOS)
177-
}
178174
if testing.Short() {
179175
t.Skip("to avoid external network")
180176
}
@@ -216,10 +212,6 @@ func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) {
216212
}
217213

218214
func TestIPPerInterfaceSingleRawConnWithSingleGroupListener(t *testing.T) {
219-
switch runtime.GOOS {
220-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
221-
t.Skipf("not supported on %s", runtime.GOOS)
222-
}
223215
if testing.Short() {
224216
t.Skip("to avoid external network")
225217
}

ipv4/multicastsockopt_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ var rawConnMulticastSocketOptionTests = []struct {
6565
}
6666

6767
func TestRawConnMulticastSocketOptions(t *testing.T) {
68-
switch runtime.GOOS {
69-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "zos":
70-
t.Skipf("not supported on %s", runtime.GOOS)
71-
}
7268
if !nettest.SupportsRawSocket() {
7369
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
7470
}

ipv4/unicast_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
8484
}
8585

8686
func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
87-
switch runtime.GOOS {
88-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
89-
t.Skipf("not supported on %s", runtime.GOOS)
90-
}
9187
if !nettest.SupportsRawSocket() {
9288
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
9389
}
@@ -179,10 +175,6 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
179175
}
180176

181177
func TestRawConnReadWriteUnicastICMP(t *testing.T) {
182-
switch runtime.GOOS {
183-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
184-
t.Skipf("not supported on %s", runtime.GOOS)
185-
}
186178
if !nettest.SupportsRawSocket() {
187179
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
188180
}

ipv4/unicastsockopt_test.go

-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ func TestPacketConnUnicastSocketOptions(t *testing.T) {
8585
}
8686

8787
func TestRawConnUnicastSocketOptions(t *testing.T) {
88-
switch runtime.GOOS {
89-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
90-
t.Skipf("not supported on %s", runtime.GOOS)
91-
}
9288
if !nettest.SupportsRawSocket() {
9389
t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH)
9490
}

ipv6/export_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2023 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.
4+
5+
package ipv6
6+
7+
var ErrNotImplemented = errNotImplemented

ipv6/helper_posix_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
package ipv6_test
99

1010
import (
11+
"errors"
1112
"os"
1213
"syscall"
14+
15+
"golang.org/x/net/ipv6"
1316
)
1417

1518
func protocolNotSupported(err error) bool {
@@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
2831
}
2932
}
3033
}
31-
return false
34+
return errors.Is(err, ipv6.ErrNotImplemented)
3235
}

ipv6/icmp_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package ipv6_test
66

77
import (
8+
"errors"
89
"net"
910
"reflect"
1011
"runtime"
@@ -60,10 +61,6 @@ func TestICMPFilter(t *testing.T) {
6061
}
6162

6263
func TestSetICMPFilter(t *testing.T) {
63-
switch runtime.GOOS {
64-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
65-
t.Skipf("not supported on %s", runtime.GOOS)
66-
}
6764
if !nettest.SupportsIPv6() {
6865
t.Skip("ipv6 is not supported")
6966
}
@@ -83,9 +80,12 @@ func TestSetICMPFilter(t *testing.T) {
8380
f.SetAll(true)
8481
f.Accept(ipv6.ICMPTypeEchoRequest)
8582
f.Accept(ipv6.ICMPTypeEchoReply)
86-
if err := p.SetICMPFilter(&f); err != nil {
83+
if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) {
84+
t.Skipf("setting ICMP filter not supported: %v", err)
85+
} else if err != nil {
8786
t.Fatal(err)
8887
}
88+
8989
kf, err := p.ICMPFilter()
9090
if err != nil {
9191
t.Fatal(err)

ipv6/multicastlistener_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,6 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
171171
}
172172

173173
func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) {
174-
switch runtime.GOOS {
175-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
176-
t.Skipf("not supported on %s", runtime.GOOS)
177-
}
178174
if !nettest.SupportsIPv6() {
179175
t.Skip("ipv6 is not supported")
180176
}
@@ -216,8 +212,6 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
216212
switch runtime.GOOS {
217213
case "darwin", "ios", "dragonfly", "openbsd": // platforms that return fe80::1%lo0: bind: can't assign requested address
218214
t.Skipf("not supported on %s", runtime.GOOS)
219-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
220-
t.Skipf("not supported on %s", runtime.GOOS)
221215
}
222216
if !nettest.SupportsIPv6() {
223217
t.Skip("ipv6 is not supported")

ipv6/sockopt_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package ipv6_test
66

77
import (
8+
"errors"
89
"fmt"
910
"net"
1011
"runtime"
@@ -83,10 +84,6 @@ func TestConnResponderPathMTU(t *testing.T) {
8384
}
8485

8586
func TestPacketConnChecksum(t *testing.T) {
86-
switch runtime.GOOS {
87-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows":
88-
t.Skipf("not supported on %s", runtime.GOOS)
89-
}
9087
if !nettest.SupportsIPv6() {
9188
t.Skip("ipv6 is not supported")
9289
}
@@ -104,7 +101,9 @@ func TestPacketConnChecksum(t *testing.T) {
104101
offset := 12 // see RFC 5340
105102

106103
for _, toggle := range []bool{false, true} {
107-
if err := p.SetChecksum(toggle, offset); err != nil {
104+
if err := p.SetChecksum(toggle, offset); errors.Is(err, ipv6.ErrNotImplemented) {
105+
t.Skipf("setting checksum not supported: %v", err)
106+
} else if err != nil {
108107
if toggle {
109108
t.Fatalf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err)
110109
} else {

ipv6/unicast_test.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package ipv6_test
66

77
import (
88
"bytes"
9+
"errors"
910
"net"
1011
"os"
1112
"runtime"
@@ -90,10 +91,6 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) {
9091
}
9192

9293
func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
93-
switch runtime.GOOS {
94-
case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos":
95-
t.Skipf("not supported on %s", runtime.GOOS)
96-
}
9794
if !nettest.SupportsIPv6() {
9895
t.Skip("ipv6 is not supported")
9996
}
@@ -128,7 +125,9 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) {
128125
var f ipv6.ICMPFilter
129126
f.SetAll(true)
130127
f.Accept(ipv6.ICMPTypeEchoReply)
131-
if err := p.SetICMPFilter(&f); err != nil {
128+
if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) {
129+
t.Skipf("setting ICMP filter not supported: %v", err)
130+
} else if err != nil {
132131
t.Fatal(err)
133132
}
134133

0 commit comments

Comments
 (0)