Skip to content

Commit b08ddaa

Browse files
authored
Merge pull request #9794 from michalpasztamobica/greentea_tcpsocket_sigio
Refactor tcpsocket tests to use sigio and not to wait
2 parents 126ba21 + 999273f commit b08ddaa

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

TESTS/netsocket/tcp/tcpsocket_echotest.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,27 +100,26 @@ void tcpsocket_echotest_nonblock_receive()
100100
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
101101
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
102102
if (tc_exec_time.read() >= time_allotted) {
103-
TEST_FAIL();
103+
TEST_FAIL_MESSAGE("time_allotted exceeded");
104104
receive_error = true;
105-
tx_sem.release();
106-
return;
107105
}
108-
continue;
106+
return;
109107
} else if (recvd < 0) {
108+
printf("sock.recv returned an error %d", recvd);
110109
TEST_FAIL();
111110
receive_error = true;
112-
tx_sem.release();
113-
return;
111+
} else {
112+
bytes2recv -= recvd;
114113
}
115114

116-
bytes2recv -= recvd;
117-
if (!bytes2recv) {
115+
if (bytes2recv == 0) {
118116
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
119-
static int round = 0;
120-
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
121117
tx_sem.release();
122-
break;
118+
} else if (receive_error || bytes2recv < 0) {
119+
TEST_FAIL();
120+
tx_sem.release();
123121
}
122+
// else - no error, not all bytes were received yet.
124123
}
125124
}
126125

@@ -180,7 +179,6 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
180179
}
181180
bytes2send -= sent;
182181
}
183-
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
184182
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
185183
count = fetch_stats();
186184
for (j = 0; j < count; j++) {

TESTS/netsocket/tls/tlssocket_echotest.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -102,29 +102,31 @@ void TLSSOCKET_ECHOTEST()
102102

103103
void tlssocket_echotest_nonblock_receive()
104104
{
105-
int recvd = sock->recv(&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
106-
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
107-
if (tc_exec_time.read() >= time_allotted) {
105+
while (bytes2recv > 0) {
106+
int recvd = sock->recv(&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
107+
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
108+
if (tc_exec_time.read() >= time_allotted) {
109+
TEST_FAIL_MESSAGE("time_allotted exceeded");
110+
receive_error = true;
111+
}
112+
return;
113+
} else if (recvd < 0) {
114+
printf("sock.recv returned an error %d", recvd);
115+
TEST_FAIL();
108116
receive_error = true;
117+
} else {
118+
bytes2recv -= recvd;
109119
}
110-
return;
111-
} else if (recvd < 0) {
112-
receive_error = true;
113-
} else {
114-
bytes2recv -= recvd;
115-
}
116120

117-
if (bytes2recv == 0) {
118-
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
119-
120-
static int round = 0;
121-
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
122-
tx_sem.release();
123-
} else if (receive_error || bytes2recv < 0) {
124-
TEST_FAIL();
125-
tx_sem.release();
121+
if (bytes2recv == 0) {
122+
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
123+
tx_sem.release();
124+
} else if (receive_error || bytes2recv < 0) {
125+
TEST_FAIL();
126+
tx_sem.release();
127+
}
128+
// else - no error, not all bytes were received yet.
126129
}
127-
// else - no error, not all bytes were received yet.
128130
}
129131

130132
void TLSSOCKET_ECHOTEST_NONBLOCK()
@@ -177,13 +179,11 @@ void TLSSOCKET_ECHOTEST_NONBLOCK()
177179
continue;
178180
} else if (sent <= 0) {
179181
printf("[Sender#%02d] network error %d\n", s_idx, sent);
180-
181182
TEST_FAIL();
182183
goto END;
183184
}
184185
bytes2send -= sent;
185186
}
186-
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
187187
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
188188
count = fetch_stats();
189189
for (j = 0; j < count; j++) {

0 commit comments

Comments
 (0)