summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/tests
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-02-18 11:42:12 -0800
committergVisor bot <gvisor-bot@google.com>2021-02-18 11:46:00 -0800
commit26eada5dea1cce3e0911b1419d1257657378f494 (patch)
treeb449c93a0833769cb1938619a1d3ab5e9e9d5448 /test/packetimpact/tests
parentbb5db80448c268f4d3eed932a01e78fcab7fb5d1 (diff)
Use standard want/got syntax in test errors
Remove unused argument while I'm here and avoid returning syscall.Errno(0) which should rather be a nil error. PiperOrigin-RevId: 358227396
Diffstat (limited to 'test/packetimpact/tests')
-rw-r--r--test/packetimpact/tests/tcp_network_unreachable_test.go20
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
}