From 457325ec54ee68480feac97aac9ac7c454d3f602 Mon Sep 17 00:00:00 2001 From: haozheng Date: Wed, 1 May 2024 17:24:46 -0700 Subject: [PATCH] Print errno name for posix sockets Errno numbers are not consistent across platforms, and it makes it confusing when debugging errno tests across plaforms, for example ECONNRESET is 108 in Windows kit and 104 in Linux. b/321999529 Change-Id: Ie46505ea50979446b1ef128d34b6487a304e2d4b --- .../posix_compliance/posix_socket_send_test.cc | 14 ++++++++------ .../posix_compliance/posix_socket_sendto_test.cc | 14 ++++++++------ starboard/shared/win32/posix_emu/socket.cc | 5 +++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/starboard/nplb/posix_compliance/posix_socket_send_test.cc b/starboard/nplb/posix_compliance/posix_socket_send_test.cc index 85fc855806eb..561b72b2021c 100644 --- a/starboard/nplb/posix_compliance/posix_socket_send_test.cc +++ b/starboard/nplb/posix_compliance/posix_socket_send_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include "starboard/nplb/posix_compliance/posix_socket_helpers.h" #include "starboard/thread.h" @@ -78,7 +79,7 @@ TEST(PosixSocketSendTest, RainyDayUnconnectedSocket) { EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || errno == ENOTCONN); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); EXPECT_TRUE(close(socket_fd) == 0); } @@ -111,10 +112,11 @@ TEST(PosixSocketSendTest, RainyDaySendToClosedSocket) { EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0); EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || - errno == ENOTCONN || // errno on Windows - errno == EINPROGRESS // errno on Evergreen + errno == ENOTCONN || // errno on Windows + errno == EINPROGRESS || // errno on Evergreen + errno == ENETUNREACH // errno on raspi ); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); // Clean up the server socket. EXPECT_TRUE(close(server_socket_fd) == 0); @@ -149,7 +151,7 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketUntilBlocking) { // If we didn't get a socket, it should be pending. EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || errno == EWOULDBLOCK); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); break; } @@ -201,7 +203,7 @@ TEST(PosixSocketSendTest, RainyDaySendToSocketConnectionReset) { if (result < 0) { EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || errno == ECONNABORTED); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); break; } diff --git a/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc b/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc index 1414e78cbbac..5ff829f2239a 100644 --- a/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc +++ b/starboard/nplb/posix_compliance/posix_socket_sendto_test.cc @@ -17,6 +17,7 @@ #include #include +#include #include #include "starboard/nplb/posix_compliance/posix_socket_helpers.h" @@ -81,7 +82,7 @@ TEST(PosixSocketSendtoTest, RainyDayUnconnectedSocket) { EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || errno == ENOTCONN); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); EXPECT_TRUE(close(socket_fd) == 0); } @@ -114,10 +115,11 @@ TEST(PosixSocketSendtoTest, RainyDaySendToClosedSocket) { EXPECT_TRUE(pthread_join(send_thread, &thread_result) == 0); EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || - errno == ENOTCONN || // errno on Windows - errno == EINPROGRESS // errno on Evergreen + errno == ENOTCONN || // errno on Windows + errno == EINPROGRESS || // errno on Evergreen + errno == ENETUNREACH // errno on raspi ); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); // Clean up the server socket. EXPECT_TRUE(close(server_socket_fd) == 0); @@ -152,7 +154,7 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketUntilBlocking) { // If we didn't get a socket, it should be pending. EXPECT_TRUE(errno == EINPROGRESS || errno == EAGAIN || errno == EWOULDBLOCK); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); break; } @@ -200,7 +202,7 @@ TEST(PosixSocketSendtoTest, RainyDaySendToSocketConnectionReset) { if (result < 0) { EXPECT_TRUE(errno == ECONNRESET || errno == ENETRESET || errno == EPIPE || errno == ECONNABORTED); - SB_DLOG(INFO) << "Failed to send, errno = " << errno; + SB_DLOG(INFO) << "Failed to send, errno = " << strerror(errno); break; } diff --git a/starboard/shared/win32/posix_emu/socket.cc b/starboard/shared/win32/posix_emu/socket.cc index 526db5208c7c..01096f2f745d 100644 --- a/starboard/shared/win32/posix_emu/socket.cc +++ b/starboard/shared/win32/posix_emu/socket.cc @@ -15,7 +15,8 @@ // We specifically do not include since the define causes a loop #include -#include // Needed for file-specific `_close`. +#include // Needed for file-specific `_close`. +#include #include // Our version that declares generic `close`. #include #undef NO_ERROR // http://b/302733082#comment15 @@ -223,7 +224,7 @@ static void set_errno() { } _set_errno(sockError); - SB_DLOG(INFO) << "Encounter socket error: " << sockError; + SB_DLOG(INFO) << "Encounter socket error: " << strerror(sockError); } ///////////////////////////////////////////////////////////////////////////////