Skip to content

Commit

Permalink
ipv4, ipv6: drop redundant skip checks based on GOOS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tklauser authored and gopherbot committed Apr 28, 2023
1 parent 938ff15 commit 0bfab66
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 55 deletions.
7 changes: 7 additions & 0 deletions ipv4/export_test.go
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion ipv4/helper_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
package ipv4_test

import (
"errors"
"os"
"syscall"

"golang.org/x/net/ipv4"
)

func protocolNotSupported(err error) bool {
Expand All @@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
}
}
}
return false
return errors.Is(err, ipv4.ErrNotImplemented)
}
8 changes: 0 additions & 8 deletions ipv4/multicast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down
8 changes: 0 additions & 8 deletions ipv4/multicastlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 0 additions & 4 deletions ipv4/multicastsockopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 0 additions & 8 deletions ipv4/unicast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 0 additions & 4 deletions ipv4/unicastsockopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions ipv6/export_test.go
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion ipv6/helper_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
package ipv6_test

import (
"errors"
"os"
"syscall"

"golang.org/x/net/ipv6"
)

func protocolNotSupported(err error) bool {
Expand All @@ -28,5 +31,5 @@ func protocolNotSupported(err error) bool {
}
}
}
return false
return errors.Is(err, ipv6.ErrNotImplemented)
}
10 changes: 5 additions & 5 deletions ipv6/icmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package ipv6_test

import (
"errors"
"net"
"reflect"
"runtime"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions ipv6/multicastlistener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
Expand Down
9 changes: 4 additions & 5 deletions ipv6/sockopt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package ipv6_test

import (
"errors"
"fmt"
"net"
"runtime"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down
9 changes: 4 additions & 5 deletions ipv6/unicast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ipv6_test

import (
"bytes"
"errors"
"net"
"os"
"runtime"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 0bfab66

Please sign in to comment.