diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/packetimpact/tests/tcp_network_unreachable_test.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/test/packetimpact/tests/tcp_network_unreachable_test.go b/test/packetimpact/tests/tcp_network_unreachable_test.go index 4eb11f7a1..b1690aaaf 100644 --- a/test/packetimpact/tests/tcp_network_unreachable_test.go +++ b/test/packetimpact/tests/tcp_network_unreachable_test.go @@ -47,7 +47,7 @@ func TestTCPSynSentUnreachable(t *testing.T) { sa := unix.SockaddrInet4{Port: int(port)} copy(sa.Addr[:], dut.Net.LocalIPv4) if _, err := dut.ConnectWithErrno(ctx, t, clientFD, &sa); err != syscall.Errno(unix.EINPROGRESS) { - t.Errorf("expected connect to fail with EINPROGRESS, but got %v", err) + t.Errorf("got connect() = %v, want EINPROGRESS", err) } // Get the SYN. @@ -78,8 +78,8 @@ func TestTCPSynSentUnreachable(t *testing.T) { layers = append(layers, &icmpv4, ip, tcp) rawConn.SendFrameStateless(t, layers) - if err := getConnectError(ctx, t, &dut, clientFD); err != unix.EHOSTUNREACH { - t.Errorf("Expected connect to fail with EHOSTUNREACH, but got %s", err) + if err := getConnectError(t, &dut, clientFD); err != unix.EHOSTUNREACH { + t.Errorf("got connect() = %v, want EHOSTUNREACH", err) } } @@ -102,7 +102,7 @@ func TestTCPSynSentUnreachable6(t *testing.T) { } copy(sa.Addr[:], dut.Net.LocalIPv6) if _, err := dut.ConnectWithErrno(ctx, t, clientFD, &sa); err != syscall.Errno(unix.EINPROGRESS) { - t.Errorf("expected connect to fail with EINPROGRESS, but got %v", err) + t.Errorf("got connect() = %v, want EINPROGRESS", err) } // Get the SYN. @@ -134,15 +134,15 @@ func TestTCPSynSentUnreachable6(t *testing.T) { layers = append(layers, &icmpv6, ip, tcp) rawConn.SendFrameStateless(t, layers) - if err := getConnectError(ctx, t, &dut, clientFD); err != unix.ENETUNREACH { - t.Errorf("Expected connect to fail with ENETUNREACH, but got %s", err) + if err := getConnectError(t, &dut, clientFD); err != unix.ENETUNREACH { + t.Errorf("got connect() = %v, want EHOSTUNREACH", err) } } // getConnectError gets the errno generated by the on-going connect attempt on // fd. fd must be non-blocking and there must be a connect call to fd which // returned EINPROGRESS before. These conditions are guaranteed in this test. -func getConnectError(ctx context.Context, t *testing.T, dut *testbench.DUT, fd int32) error { +func getConnectError(t *testing.T, dut *testbench.DUT, fd int32) error { t.Helper() // We previously got EINPROGRESS form the connect call. We can // handle it as explained by connect(2): @@ -157,6 +157,8 @@ func getConnectError(ctx context.Context, t *testing.T, dut *testbench.DUT, fd i // error codes listed here, explaining the reason for the // failure). dut.PollOne(t, fd, unix.POLLOUT, 10*time.Second) - errno := dut.GetSockOptInt(t, fd, unix.SOL_SOCKET, unix.SO_ERROR) - return syscall.Errno(errno) + if errno := dut.GetSockOptInt(t, fd, unix.SOL_SOCKET, unix.SO_ERROR); errno != 0 { + return syscall.Errno(errno) + } + return nil } |