Skip to content

Commit

Permalink
Added Stream Communication Test with Send and Recv
Browse files Browse the repository at this point in the history
- Contains a short test for stream communications between
  server and client.
- Server sends a message to client and client receives the
  message and then a comparison is done to see if the messages
  match.
- There is a while loop which loops if the message for some reason
  was not completely sent. In that case, it is the users'
  responsibilities to resend the remaining message.

Issue: eclipse-omr#5069

Signed-off-by: Haley Cao <haleycao88@hotmail.com>
  • Loading branch information
Haley Cao committed Jun 19, 2020
1 parent 4ea689d commit 8c178bb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions fvtest/porttest/omrsockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,30 @@ TEST(PortSockTest, two_socket_stream_communication)
omrsock_socket_t connectedClientStreamSocket = NULL;
EXPECT_EQ(OMRPORTLIB->sock_accept(OMRPORTLIB, serverStreamSocket, &connectedClientStreamSockAddr, &connectedClientStreamSocket), 0);

const char *msg = "This is an omrsock test for 2 socket stream communications.";
int32_t bytesLeft = strlen(msg) + 1;
uint8_t *cursor = (uint8_t *)msg;
int32_t bytesSent = 0;
while (0 != bytesLeft) {
bytesSent = OMRPORTLIB->sock_send(OMRPORTLIB, connectedClientStreamSocket, cursor, bytesLeft, 0);
ASSERT_GE(bytesSent, 0);
bytesLeft -= bytesSent;
cursor += bytesSent;
}

char buf[100] = {0};
bytesLeft = strlen(msg) + 1;
cursor = (uint8_t *)buf;
int32_t bytesRecv = 0;
while (0 != bytesLeft) {
bytesRecv = OMRPORTLIB->sock_recv(OMRPORTLIB, clientStreamSocket, cursor, bytesLeft, 0);
ASSERT_GE(bytesRecv, 0);
bytesLeft -= bytesRecv;
cursor += bytesRecv;
}

EXPECT_STREQ(msg, buf);

EXPECT_EQ(OMRPORTLIB->sock_close(OMRPORTLIB, &connectedClientStreamSocket), 0);
EXPECT_EQ(OMRPORTLIB->sock_close(OMRPORTLIB, &clientStreamSocket), 0);
EXPECT_EQ(OMRPORTLIB->sock_close(OMRPORTLIB, &serverStreamSocket), 0);
Expand Down

0 comments on commit 8c178bb

Please sign in to comment.