From 0bfab66a03570232c7aaea77dcdd2355ae6e9db8 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 28 Apr 2023 17:33:01 +0200 Subject: [PATCH] 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 Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Reviewed-by: Dmitri Shuralyov Auto-Submit: Tobias Klauser --- ipv4/export_test.go | 7 +++++++ ipv4/helper_posix_test.go | 5 ++++- ipv4/multicast_test.go | 8 -------- ipv4/multicastlistener_test.go | 8 -------- ipv4/multicastsockopt_test.go | 4 ---- ipv4/unicast_test.go | 8 -------- ipv4/unicastsockopt_test.go | 4 ---- ipv6/export_test.go | 7 +++++++ ipv6/helper_posix_test.go | 5 ++++- ipv6/icmp_test.go | 10 +++++----- ipv6/multicastlistener_test.go | 6 ------ ipv6/sockopt_test.go | 9 ++++----- ipv6/unicast_test.go | 9 ++++----- 13 files changed, 35 insertions(+), 55 deletions(-) create mode 100644 ipv4/export_test.go create mode 100644 ipv6/export_test.go diff --git a/ipv4/export_test.go b/ipv4/export_test.go new file mode 100644 index 000000000..c2229e732 --- /dev/null +++ b/ipv4/export_test.go @@ -0,0 +1,7 @@ +// Copyright 2023 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 ipv4 + +var ErrNotImplemented = errNotImplemented diff --git a/ipv4/helper_posix_test.go b/ipv4/helper_posix_test.go index 40f432c51..4f6ecc0fd 100644 --- a/ipv4/helper_posix_test.go +++ b/ipv4/helper_posix_test.go @@ -8,8 +8,11 @@ package ipv4_test import ( + "errors" "os" "syscall" + + "golang.org/x/net/ipv4" ) func protocolNotSupported(err error) bool { @@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool { } } } - return false + return errors.Is(err, ipv4.ErrNotImplemented) } diff --git a/ipv4/multicast_test.go b/ipv4/multicast_test.go index fd086580d..d056ff6de 100644 --- a/ipv4/multicast_test.go +++ b/ipv4/multicast_test.go @@ -131,10 +131,6 @@ var packetConnReadWriteMulticastICMPTests = []struct { } func TestPacketConnReadWriteMulticastICMP(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsRawSocket() { t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } @@ -261,10 +257,6 @@ var rawConnReadWriteMulticastICMPTests = []struct { } func TestRawConnReadWriteMulticastICMP(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "illumos", "js", "nacl", "plan9", "solaris", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if testing.Short() { t.Skip("to avoid external network") } diff --git a/ipv4/multicastlistener_test.go b/ipv4/multicastlistener_test.go index 0035c26f6..906964682 100644 --- a/ipv4/multicastlistener_test.go +++ b/ipv4/multicastlistener_test.go @@ -171,10 +171,6 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { } func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos": - t.Skipf("not supported on %s", runtime.GOOS) - } if testing.Short() { t.Skip("to avoid external network") } @@ -216,10 +212,6 @@ func TestIPSingleRawConnWithSingleGroupListener(t *testing.T) { } func TestIPPerInterfaceSingleRawConnWithSingleGroupListener(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos": - t.Skipf("not supported on %s", runtime.GOOS) - } if testing.Short() { t.Skip("to avoid external network") } diff --git a/ipv4/multicastsockopt_test.go b/ipv4/multicastsockopt_test.go index 9339e8901..ddf9e6023 100644 --- a/ipv4/multicastsockopt_test.go +++ b/ipv4/multicastsockopt_test.go @@ -65,10 +65,6 @@ var rawConnMulticastSocketOptionTests = []struct { } func TestRawConnMulticastSocketOptions(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "zos": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsRawSocket() { t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } diff --git a/ipv4/unicast_test.go b/ipv4/unicast_test.go index 879f2fc05..a68f4cc02 100644 --- a/ipv4/unicast_test.go +++ b/ipv4/unicast_test.go @@ -84,10 +84,6 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { } func TestPacketConnReadWriteUnicastICMP(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsRawSocket() { t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } @@ -179,10 +175,6 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { } func TestRawConnReadWriteUnicastICMP(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsRawSocket() { t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } diff --git a/ipv4/unicastsockopt_test.go b/ipv4/unicastsockopt_test.go index 0cd403da2..837baba74 100644 --- a/ipv4/unicastsockopt_test.go +++ b/ipv4/unicastsockopt_test.go @@ -85,10 +85,6 @@ func TestPacketConnUnicastSocketOptions(t *testing.T) { } func TestRawConnUnicastSocketOptions(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsRawSocket() { t.Skipf("not supported on %s/%s", runtime.GOOS, runtime.GOARCH) } diff --git a/ipv6/export_test.go b/ipv6/export_test.go new file mode 100644 index 000000000..a506cb38d --- /dev/null +++ b/ipv6/export_test.go @@ -0,0 +1,7 @@ +// Copyright 2023 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 + +var ErrNotImplemented = errNotImplemented diff --git a/ipv6/helper_posix_test.go b/ipv6/helper_posix_test.go index ab561f34f..8ca6a3c3c 100644 --- a/ipv6/helper_posix_test.go +++ b/ipv6/helper_posix_test.go @@ -8,8 +8,11 @@ package ipv6_test import ( + "errors" "os" "syscall" + + "golang.org/x/net/ipv6" ) func protocolNotSupported(err error) bool { @@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool { } } } - return false + return errors.Is(err, ipv6.ErrNotImplemented) } diff --git a/ipv6/icmp_test.go b/ipv6/icmp_test.go index 3fe9ef4fd..9d8d68127 100644 --- a/ipv6/icmp_test.go +++ b/ipv6/icmp_test.go @@ -5,6 +5,7 @@ package ipv6_test import ( + "errors" "net" "reflect" "runtime" @@ -60,10 +61,6 @@ func TestICMPFilter(t *testing.T) { } func TestSetICMPFilter(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsIPv6() { t.Skip("ipv6 is not supported") } @@ -83,9 +80,12 @@ func TestSetICMPFilter(t *testing.T) { f.SetAll(true) f.Accept(ipv6.ICMPTypeEchoRequest) f.Accept(ipv6.ICMPTypeEchoReply) - if err := p.SetICMPFilter(&f); err != nil { + if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) { + t.Skipf("setting ICMP filter not supported: %v", err) + } else if err != nil { t.Fatal(err) } + kf, err := p.ICMPFilter() if err != nil { t.Fatal(err) diff --git a/ipv6/multicastlistener_test.go b/ipv6/multicastlistener_test.go index 386b38791..3daa19838 100644 --- a/ipv6/multicastlistener_test.go +++ b/ipv6/multicastlistener_test.go @@ -171,10 +171,6 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { } func TestIPSinglePacketConnWithSingleGroupListener(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsIPv6() { t.Skip("ipv6 is not supported") } @@ -216,8 +212,6 @@ func TestIPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { switch runtime.GOOS { case "darwin", "ios", "dragonfly", "openbsd": // platforms that return fe80::1%lo0: bind: can't assign requested address t.Skipf("not supported on %s", runtime.GOOS) - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) } if !nettest.SupportsIPv6() { t.Skip("ipv6 is not supported") diff --git a/ipv6/sockopt_test.go b/ipv6/sockopt_test.go index ad6cb46d2..3dc42c139 100644 --- a/ipv6/sockopt_test.go +++ b/ipv6/sockopt_test.go @@ -5,6 +5,7 @@ package ipv6_test import ( + "errors" "fmt" "net" "runtime" @@ -83,10 +84,6 @@ func TestConnResponderPathMTU(t *testing.T) { } func TestPacketConnChecksum(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsIPv6() { t.Skip("ipv6 is not supported") } @@ -104,7 +101,9 @@ func TestPacketConnChecksum(t *testing.T) { offset := 12 // see RFC 5340 for _, toggle := range []bool{false, true} { - if err := p.SetChecksum(toggle, offset); err != nil { + if err := p.SetChecksum(toggle, offset); errors.Is(err, ipv6.ErrNotImplemented) { + t.Skipf("setting checksum not supported: %v", err) + } else if err != nil { if toggle { t.Fatalf("ipv6.PacketConn.SetChecksum(%v, %v) failed: %v", toggle, offset, err) } else { diff --git a/ipv6/unicast_test.go b/ipv6/unicast_test.go index d5ec85eab..04e5b06fa 100644 --- a/ipv6/unicast_test.go +++ b/ipv6/unicast_test.go @@ -6,6 +6,7 @@ package ipv6_test import ( "bytes" + "errors" "net" "os" "runtime" @@ -90,10 +91,6 @@ func TestPacketConnReadWriteUnicastUDP(t *testing.T) { } func TestPacketConnReadWriteUnicastICMP(t *testing.T) { - switch runtime.GOOS { - case "fuchsia", "hurd", "js", "nacl", "plan9", "wasip1", "windows", "zos": - t.Skipf("not supported on %s", runtime.GOOS) - } if !nettest.SupportsIPv6() { t.Skip("ipv6 is not supported") } @@ -128,7 +125,9 @@ func TestPacketConnReadWriteUnicastICMP(t *testing.T) { var f ipv6.ICMPFilter f.SetAll(true) f.Accept(ipv6.ICMPTypeEchoReply) - if err := p.SetICMPFilter(&f); err != nil { + if err := p.SetICMPFilter(&f); errors.Is(err, ipv6.ErrNotImplemented) { + t.Skipf("setting ICMP filter not supported: %v", err) + } else if err != nil { t.Fatal(err) }