Merge pull request #9794 from michalpasztamobica/greentea_tcpsocket_sigio

Refactor tcpsocket tests to use sigio and not to wait
pull/9849/head
Martin Kojtal 2019-02-26 10:30:56 +01:00 committed by GitHub
commit b08ddaad8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 33 deletions

View File

@ -100,27 +100,26 @@ void tcpsocket_echotest_nonblock_receive()
int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv); int recvd = sock.recv(&(tcp_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) { if (tc_exec_time.read() >= time_allotted) {
TEST_FAIL(); TEST_FAIL_MESSAGE("time_allotted exceeded");
receive_error = true; receive_error = true;
tx_sem.release();
return;
} }
continue; return;
} else if (recvd < 0) { } else if (recvd < 0) {
printf("sock.recv returned an error %d", recvd);
TEST_FAIL(); TEST_FAIL();
receive_error = true; receive_error = true;
tx_sem.release(); } else {
return; bytes2recv -= recvd;
} }
bytes2recv -= recvd; if (bytes2recv == 0) {
if (!bytes2recv) {
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total)); TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, bytes2recv_total));
static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
tx_sem.release(); tx_sem.release();
break; } else if (receive_error || bytes2recv < 0) {
TEST_FAIL();
tx_sem.release();
} }
// else - no error, not all bytes were received yet.
} }
} }
@ -180,7 +179,6 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
} }
bytes2send -= sent; bytes2send -= sent;
} }
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats(); count = fetch_stats();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {

View File

@ -102,13 +102,17 @@ void TLSSOCKET_ECHOTEST()
void tlssocket_echotest_nonblock_receive() void tlssocket_echotest_nonblock_receive()
{ {
while (bytes2recv > 0) {
int recvd = sock->recv(&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv); int recvd = sock->recv(&(tls_global::rx_buffer[bytes2recv_total - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) { if (tc_exec_time.read() >= time_allotted) {
TEST_FAIL_MESSAGE("time_allotted exceeded");
receive_error = true; receive_error = true;
} }
return; return;
} else if (recvd < 0) { } else if (recvd < 0) {
printf("sock.recv returned an error %d", recvd);
TEST_FAIL();
receive_error = true; receive_error = true;
} else { } else {
bytes2recv -= recvd; bytes2recv -= recvd;
@ -116,15 +120,13 @@ void tlssocket_echotest_nonblock_receive()
if (bytes2recv == 0) { if (bytes2recv == 0) {
TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total)); TEST_ASSERT_EQUAL(0, memcmp(tls_global::tx_buffer, tls_global::rx_buffer, bytes2recv_total));
static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, bytes2recv_total);
tx_sem.release(); tx_sem.release();
} else if (receive_error || bytes2recv < 0) { } else if (receive_error || bytes2recv < 0) {
TEST_FAIL(); TEST_FAIL();
tx_sem.release(); tx_sem.release();
} }
// else - no error, not all bytes were received yet. // else - no error, not all bytes were received yet.
}
} }
void TLSSOCKET_ECHOTEST_NONBLOCK() void TLSSOCKET_ECHOTEST_NONBLOCK()
@ -177,13 +179,11 @@ void TLSSOCKET_ECHOTEST_NONBLOCK()
continue; continue;
} else if (sent <= 0) { } else if (sent <= 0) {
printf("[Sender#%02d] network error %d\n", s_idx, sent); printf("[Sender#%02d] network error %d\n", s_idx, sent);
TEST_FAIL(); TEST_FAIL();
goto END; goto END;
} }
bytes2send -= sent; bytes2send -= sent;
} }
printf("[Sender#%02d] bytes sent: %d\n", s_idx, pkt_s);
#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLE
count = fetch_stats(); count = fetch_stats();
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {