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 May 3, 2020
1 parent 44927d4 commit 4a681a6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions fvtest/porttest/omrsockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,41 @@ TEST(PortSockTest, two_socket_stream_communication)
omrsock_socket_t connectedClientStreamSocket = NULL;
EXPECT_EQ(OMRPORTLIB->sock_accept(OMRPORTLIB, serverStreamSocket, &connectedClientStreamSockAddr, &connectedClientStreamSocket), 0);

char msg[100] = "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(1){
bytesSent = OMRPORTLIB->sock_send(OMRPORTLIB, connectedClientStreamSocket, cursor, bytesLeft, 0);
if (bytesSent < 0) {
FAIL();
break;
}
bytesLeft -= bytesSent;
cursor += bytesSent;
if(0 == bytesLeft) {
break;
}
}

char buf[100] = "";
bytesLeft = strlen(msg) + 1;
cursor = (uint8_t *)buf;
int32_t bytesRecv = 0;
while(1) {
bytesRecv = OMRPORTLIB->sock_recv(OMRPORTLIB, clientStreamSocket, cursor, bytesLeft, 0);
if (bytesRecv < 0) {
FAIL();
break;
}
bytesLeft -= bytesRecv;
cursor += bytesRecv;
if (0 == bytesLeft) {
break;
}
}
EXPECT_EQ(strcmp(msg, buf), 0);

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 4a681a6

Please sign in to comment.