From 491a7ea03e0f37f35d370e489b175faf8e67f0ec Mon Sep 17 00:00:00 2001 From: Veijo Pesonen Date: Thu, 17 May 2018 12:52:46 +0300 Subject: [PATCH] Fixes findings from Greentea netsocket TCP test cases --- TESTS/netsocket/tcp/main.cpp | 13 ++++++------- TESTS/netsocket/tcp/tcp_tests.h | 2 +- TESTS/netsocket/tcp/tcpsocket_echotest.cpp | 5 +---- .../netsocket/tcp/tcpsocket_echotest_burst.cpp | 10 ++++++---- .../tcp/tcpsocket_open_close_repeat.cpp | 2 ++ TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp | 7 +++++-- TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp | 11 ++++++++--- .../tcp/tcpsocket_thread_per_socket_safety.cpp | 17 ++++++++++------- 8 files changed, 39 insertions(+), 28 deletions(-) diff --git a/TESTS/netsocket/tcp/main.cpp b/TESTS/netsocket/tcp/main.cpp index 27aee7a27a..2eaa4d0cd7 100644 --- a/TESTS/netsocket/tcp/main.cpp +++ b/TESTS/netsocket/tcp/main.cpp @@ -29,18 +29,17 @@ using namespace utest::v1; -#ifndef MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT -#define MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT 500 //[ms] -#endif - -static NetworkInterface* net; +namespace +{ + NetworkInterface* net; +} NetworkInterface* get_interface() { return net; } -void drop_bad_packets(TCPSocket& sock) { +void drop_bad_packets(TCPSocket& sock, int orig_timeout) { nsapi_error_t err; sock.set_timeout(0); while (true) { @@ -49,7 +48,7 @@ void drop_bad_packets(TCPSocket& sock) { break; } } - sock.set_timeout(MBED_CFG_TCP_CLIENT_ECHO_TIMEOUT); + sock.set_timeout(orig_timeout); } static void _ifup() { diff --git a/TESTS/netsocket/tcp/tcp_tests.h b/TESTS/netsocket/tcp/tcp_tests.h index fdff879902..f392ef7446 100644 --- a/TESTS/netsocket/tcp/tcp_tests.h +++ b/TESTS/netsocket/tcp/tcp_tests.h @@ -19,7 +19,7 @@ #define TCP_TESTS_H NetworkInterface* get_interface(); -void drop_bad_packets(TCPSocket& sock); +void drop_bad_packets(TCPSocket& sock, int orig_timeout); void fill_tx_buffer_ascii(char *buff, size_t len); void tcpsocket_connect_to_echo_srv(TCPSocket& sock); void tcpsocket_connect_to_discard_srv(TCPSocket& sock); diff --git a/TESTS/netsocket/tcp/tcpsocket_echotest.cpp b/TESTS/netsocket/tcp/tcpsocket_echotest.cpp index 467c46a55a..bcd83035f7 100644 --- a/TESTS/netsocket/tcp/tcpsocket_echotest.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_echotest.cpp @@ -65,10 +65,7 @@ void TCPSOCKET_ECHOTEST() int bytes2recv = sent; while (bytes2recv) { recvd = sock.recv(&(rx_buffer[sent-bytes2recv]), bytes2recv); - if (recvd == NSAPI_ERROR_WOULD_BLOCK) { - TEST_ASSERT_NOT_EQUAL(osEventTimeout, osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status); - continue; - } else if (recvd <= 0) { + if (recvd < 0) { printf("[Round#%02d] network error %d\n", x, recvd); TEST_FAIL(); } diff --git a/TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp b/TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp index 64bbcba110..adc3cdd0e8 100644 --- a/TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_echotest_burst.cpp @@ -23,11 +23,13 @@ #include "utest.h" #include "tcp_tests.h" -#define SIGNAL_SIGIO 0x1 -#define SIGIO_TIMEOUT 5000 //[ms] +using namespace utest::v1; namespace { + static const int SIGNAL_SIGIO = 0x1; + static const int SIGIO_TIMEOUT = 5000; //[ms] + static const int BURST_CNT = 100; static const int BURST_SIZE = 1220; char rx_buffer[BURST_SIZE] = {0}; @@ -77,7 +79,7 @@ void TCPSOCKET_ECHOTEST_BURST() } if (bt_left != 0) { - drop_bad_packets(sock); + drop_bad_packets(sock, 0); TEST_FAIL(); } @@ -134,7 +136,7 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK() if (bt_left != 0) { printf("network error %d, missing %d bytes from a burst\n", recvd, bt_left); - drop_bad_packets(sock); + drop_bad_packets(sock, -1); TEST_FAIL(); } diff --git a/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp index 6e0995bb94..b292fa2461 100644 --- a/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp @@ -23,6 +23,8 @@ #include "unity/unity.h" #include "utest.h" +using namespace utest::v1; + void TCPSOCKET_OPEN_CLOSE_REPEAT() { TCPSocket *sock = new TCPSocket; diff --git a/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp b/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp index 05cd9c5963..ba9e5ffa25 100644 --- a/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_recv_100k.cpp @@ -25,8 +25,11 @@ using namespace utest::v1; -#define SIGNAL_SIGIO 0x1 -#define SIGIO_TIMEOUT 20000 //[ms] +namespace +{ + static const int SIGNAL_SIGIO = 0x1; + static const int SIGIO_TIMEOUT = 20000; //[ms] +} static void _tcpsocket_connect_to_chargen_srv(TCPSocket& sock) { SocketAddress tcp_addr; diff --git a/TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp b/TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp index 73ec7ed0b9..c2ce6ccf81 100644 --- a/TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_recv_timeout.cpp @@ -23,8 +23,13 @@ #include "utest.h" #include "tcp_tests.h" -#define SIGNAL_SIGIO 0x1 -#define SIGIO_TIMEOUT 5000 //[ms] +using namespace utest::v1; + +namespace +{ + static const int SIGNAL_SIGIO = 0x1; + static const int SIGIO_TIMEOUT = 5000; //[ms] +} static void _sigio_handler(osThreadId id) { osSignalSet(id, SIGNAL_SIGIO); @@ -58,7 +63,7 @@ void TCPSOCKET_RECV_TIMEOUT() TEST_FAIL(); } printf("MBED: recv() took: %dms\n", timer.read_ms()); - TEST_ASSERT_INT_WITHIN(50, (100+200)/2, timer.read_ms()); + TEST_ASSERT_INT_WITHIN(50, 150, timer.read_ms()); continue; } else if (recvd < 0) { printf("[pkt#%02d] network error %d\n", i, recvd); diff --git a/TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp b/TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp index cd0c4ad833..aded7319fa 100644 --- a/TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_thread_per_socket_safety.cpp @@ -25,12 +25,15 @@ using namespace utest::v1; -#define SIGNAL_SIGIO1 0x1 -#define SIGNAL_SIGIO2 0x2 -#define SIGIO_TIMEOUT 5000 //[ms] +namespace +{ + static const int SIGNAL_SIGIO1 = 0x1; + static const int SIGNAL_SIGIO2 = 0x2; + static const int SIGIO_TIMEOUT = 5000; //[ms] -Thread thread; -static volatile bool running = true; + Thread thread; + volatile bool running = true; +} static void _sigio_handler1(osThreadId id) { osSignalSet(id, SIGNAL_SIGIO1); @@ -84,7 +87,7 @@ static void check_const_len_rand_sequence() } if (bytes2process != 0) { - drop_bad_packets(sock); + drop_bad_packets(sock, 0); TEST_FAIL(); } TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, BUFF_SIZE)); @@ -136,7 +139,7 @@ static void check_var_len_rand_sequence() } if (bytes2process != 0) { - drop_bad_packets(sock); + drop_bad_packets(sock, 0); TEST_FAIL(); } TEST_ASSERT_EQUAL(0, memcmp(tx_buff, rx_buff, i));