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
This commit is contained in:
Tamir Duberstein 2021-02-18 11:42:12 -08:00 committed by gVisor bot
parent bb5db80448
commit 26eada5dea
1 changed files with 11 additions and 9 deletions

View File

@ -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
}