Skip to content

Commit

Permalink
Debug failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
madhurajayaraman committed Oct 10, 2024
1 parent ee175cf commit 3de5e67
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions starboard/nplb/posix_compliance/posix_socket_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ int PosixSocketCreateAndConnect(int server_domain,
if (*listen_socket_fd < 0) {
return -1;
}
SB_DLOG(INFO) << "Socket was created";
// set socket reuseable
const int on = 1;
result =
Expand All @@ -46,32 +47,38 @@ int PosixSocketCreateAndConnect(int server_domain,
close(*listen_socket_fd);
return -1;
}
SB_DLOG(INFO) << "Socket option reuse address set";

// bind socket with local address
sockaddr_in6 address = {};
EXPECT_TRUE(
PosixGetLocalAddressIPv4(reinterpret_cast<sockaddr*>(&address)) == 0 ||
PosixGetLocalAddressIPv6(reinterpret_cast<sockaddr*>(&address)) == 0);
address.sin6_port = htons(PosixGetPortNumberForTests());
SB_DLOG(INFO) << "About to bind";

result = bind(*listen_socket_fd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(struct sockaddr_in));
if (result != 0) {
close(*listen_socket_fd);
return -1;
}
SB_DLOG(INFO) << "Socket was bound";

result = listen(*listen_socket_fd, kMaxConn);
if (result != 0) {
close(*listen_socket_fd);
return -1;
}
SB_DLOG(INFO) << "Socket is listening";

// create client socket and connect to localhost:<port>
*client_socket_fd = socket(client_domain, SOCK_STREAM, IPPROTO_TCP);
if (*client_socket_fd < 0) {
close(*listen_socket_fd);
return -1;
}
SB_DLOG(INFO) << "Socket was created pt 2";

result =
setsockopt(*client_socket_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
Expand All @@ -80,11 +87,13 @@ int PosixSocketCreateAndConnect(int server_domain,
close(*client_socket_fd);
return -1;
}
SB_DLOG(INFO) << "Client Socket was set reuse address";

result =
connect(*client_socket_fd, reinterpret_cast<struct sockaddr*>(&address),
sizeof(struct sockaddr));
if (result != 0) {
SB_DLOG(INFO) << "result of connection is not 0";
close(*listen_socket_fd);
close(*client_socket_fd);
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TEST(PosixSocketJoinMulticastGroupTest, RainyDayInvalidSocket) {

EXPECT_EQ(-1,
setsockopt(-1, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)));
EXPECT_TRUE(errno == EBADF || errno == ECONNREFUSED);
EXPECT_TRUE(errno == EBADF || errno == ECONNREFUSED || errno == EINVAL);
}

TEST(PosixSocketJoinMulticastGroupTest, RainyDayInvalidAddress) {
Expand Down

0 comments on commit 3de5e67

Please sign in to comment.