diff --git a/TESTS/netsocket/tcp/main.cpp b/TESTS/netsocket/tcp/main.cpp index 7185b577875..5e149e300ef 100644 --- a/TESTS/netsocket/tcp/main.cpp +++ b/TESTS/netsocket/tcp/main.cpp @@ -149,6 +149,38 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t return greentea_test_teardown_handler(passed, failed, failure); } +utest::v1::status_t greentea_case_setup_handler_tcp(const Case *const source, const size_t index_of_case) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); + } +#endif + return greentea_case_setup_handler(source, index_of_case); +} + +utest::v1::status_t greentea_case_teardown_handler_tcp(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); + } +#endif + return greentea_case_teardown_handler(source, passed, failed, failure); +} + +static void test_failure_handler(const failure_t failure) +{ + UTEST_LOG_FUNCTION(); + if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { + verbose_test_failure_handler(failure); + GREENTEA_TESTSUITE_RESULT(false); + while (1) ; + } +} + Case cases[] = { Case("TCPSOCKET_ECHOTEST", TCPSOCKET_ECHOTEST), @@ -178,7 +210,16 @@ Case cases[] = { Case("TCPSOCKET_ENDPOINT_CLOSE", TCPSOCKET_ENDPOINT_CLOSE), }; -Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers); +handlers_t tcp_test_case_handlers = { + default_greentea_test_setup_handler, + greentea_test_teardown_handler, + test_failure_handler, + greentea_case_setup_handler_tcp, + greentea_case_teardown_handler_tcp, + greentea_case_failure_continue_handler +}; + +Specification specification(greentea_setup, cases, greentea_teardown, tcp_test_case_handlers); int main() { diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp index 5dcc8b03bcb..4ded50108e3 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_address.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_ADDRESS() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -48,11 +41,4 @@ void TCPSOCKET_BIND_ADDRESS() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp index f02bd4d9816..c309f2805b8 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_address_invalid.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_ADDRESS_INVALID() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -54,11 +47,4 @@ void TCPSOCKET_BIND_ADDRESS_INVALID() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_address_null.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_address_null.cpp index 5621bb073b0..93651030ac0 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_address_null.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_address_null.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_ADDRESS_NULL() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -47,11 +40,4 @@ void TCPSOCKET_BIND_ADDRESS_NULL() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_address_port.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_address_port.cpp index 96b343254da..6d5befce695 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_address_port.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_address_port.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_ADDRESS_PORT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -47,11 +40,4 @@ void TCPSOCKET_BIND_ADDRESS_PORT() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp index f459528e0af..53d2d74524c 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_port.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_PORT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -47,11 +40,4 @@ void TCPSOCKET_BIND_PORT() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp index 2dfd615242a..b2ace515173 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_port_fail.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_PORT_FAIL() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -57,11 +50,4 @@ void TCPSOCKET_BIND_PORT_FAIL() delete sock; delete sock2; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_unopened.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_unopened.cpp index df777441ce1..8be2f934c62 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_unopened.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_unopened.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_UNOPENED() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -46,11 +39,4 @@ void TCPSOCKET_BIND_UNOPENED() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp b/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp index 3671d1fcf11..9f4296e91b7 100644 --- a/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_bind_wrong_type.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_BIND_WRONG_TYPE() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -56,11 +49,4 @@ void TCPSOCKET_BIND_WRONG_TYPE() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_echotest.cpp b/TESTS/netsocket/tcp/tcpsocket_echotest.cpp index 8d9fee09aab..0ceddd3a155 100644 --- a/TESTS/netsocket/tcp/tcpsocket_echotest.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_echotest.cpp @@ -125,13 +125,6 @@ void tcpsocket_echotest_nonblock_receive() void TCPSOCKET_ECHOTEST_NONBLOCK() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int j = 0; - int count = fetch_stats(); - for (; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif tc_exec_time.start(); time_allotted = split2half_rmng_tcp_test_time(); // [s] @@ -180,7 +173,8 @@ void TCPSOCKET_ECHOTEST_NONBLOCK() bytes2send -= sent; } #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); + int count = fetch_stats(); + int j; for (j = 0; j < count; j++) { if ((tcp_stats[j].state == SOCK_OPEN) && (tcp_stats[j].proto == NSAPI_TCP)) { break; diff --git a/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp index 88a4b2791f9..264bcb8edfb 100644 --- a/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_open_close_repeat.cpp @@ -26,12 +26,6 @@ using namespace utest::v1; void TCPSOCKET_OPEN_CLOSE_REPEAT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -42,10 +36,4 @@ void TCPSOCKET_OPEN_CLOSE_REPEAT() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); } delete sock; -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp b/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp index 9545e85cb56..d8b92e21998 100644 --- a/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_open_destruct.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void TCPSOCKET_OPEN_DESTRUCT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif - for (int i = 0; i < 100; i++) { TCPSocket *sock = new TCPSocket; if (!sock) { @@ -41,10 +34,4 @@ void TCPSOCKET_OPEN_DESTRUCT() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); delete sock; } -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp b/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp index 3673d4fbb01..67bbf1ea152 100644 --- a/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp +++ b/TESTS/netsocket/tcp/tcpsocket_open_twice.cpp @@ -26,12 +26,6 @@ using namespace utest::v1; void TCPSOCKET_OPEN_TWICE() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif TCPSocket *sock = new TCPSocket; if (!sock) { TEST_FAIL(); @@ -41,10 +35,4 @@ void TCPSOCKET_OPEN_TWICE() TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); delete sock; -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tcp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/tls/main.cpp b/TESTS/netsocket/tls/main.cpp index ff66affd58b..d1a77233f36 100644 --- a/TESTS/netsocket/tls/main.cpp +++ b/TESTS/netsocket/tls/main.cpp @@ -177,6 +177,38 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t return greentea_test_teardown_handler(passed, failed, failure); } +utest::v1::status_t greentea_case_setup_handler_tls(const Case *const source, const size_t index_of_case) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); + } +#endif + return greentea_case_setup_handler(source, index_of_case); +} + +utest::v1::status_t greentea_case_teardown_handler_tls(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); + } +#endif + return greentea_case_teardown_handler(source, passed, failed, failure); +} + +static void test_failure_handler(const failure_t failure) +{ + UTEST_LOG_FUNCTION(); + if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { + verbose_test_failure_handler(failure); + GREENTEA_TESTSUITE_RESULT(false); + while (1) ; + } +} + Case cases[] = { Case("TLSSOCKET_ECHOTEST", TLSSOCKET_ECHOTEST), @@ -203,7 +235,16 @@ Case cases[] = { // Case("TLSSOCKET_SIMULTANEOUS", TLSSOCKET_SIMULTANEOUS) }; -Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers); +const handlers_t tls_test_case_handlers = { + default_greentea_test_setup_handler, + greentea_test_teardown_handler, + test_failure_handler, + greentea_case_setup_handler_tls, + greentea_case_teardown_handler_tls, + greentea_case_failure_continue_handler +}; + +Specification specification(greentea_setup, cases, greentea_teardown, tls_test_case_handlers); int retval; void run_test(void) diff --git a/TESTS/netsocket/tls/tlssocket_echotest.cpp b/TESTS/netsocket/tls/tlssocket_echotest.cpp index 15449d1a671..bcfcf14e22a 100644 --- a/TESTS/netsocket/tls/tlssocket_echotest.cpp +++ b/TESTS/netsocket/tls/tlssocket_echotest.cpp @@ -131,13 +131,6 @@ void tlssocket_echotest_nonblock_receive() void TLSSOCKET_ECHOTEST_NONBLOCK() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int j = 0; - int count = fetch_stats(); - for (; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); - } -#endif sock = new TLSSocket; tc_exec_time.start(); time_allotted = split2half_rmng_tls_test_time(); // [s] @@ -185,9 +178,10 @@ void TLSSOCKET_ECHOTEST_NONBLOCK() bytes2send -= sent; } #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (j = 0; j < count; j++) { - if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TLS)) { + int count = fetch_stats(); + int j = 0; + for (; j < count; j++) { + if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TCP)) { break; } } diff --git a/TESTS/netsocket/tls/tlssocket_open_destruct.cpp b/TESTS/netsocket/tls/tlssocket_open_destruct.cpp index c7ee62efa15..114fb97c4a9 100644 --- a/TESTS/netsocket/tls/tlssocket_open_destruct.cpp +++ b/TESTS/netsocket/tls/tlssocket_open_destruct.cpp @@ -28,13 +28,6 @@ using namespace utest::v1; void TLSSOCKET_OPEN_DESTRUCT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); - } -#endif - for (int i = 0; i < 100; i++) { TLSSocket *sock = new TLSSocket; if (!sock) { @@ -43,12 +36,6 @@ void TLSSOCKET_OPEN_DESTRUCT() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); delete sock; } -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); - } -#endif } #endif // defined(MBEDTLS_SSL_CLI_C) diff --git a/TESTS/netsocket/tls/tlssocket_open_limit.cpp b/TESTS/netsocket/tls/tlssocket_open_limit.cpp index 350e23accb9..a9918e575f6 100644 --- a/TESTS/netsocket/tls/tlssocket_open_limit.cpp +++ b/TESTS/netsocket/tls/tlssocket_open_limit.cpp @@ -76,7 +76,7 @@ void TLSSOCKET_OPEN_LIMIT() int count = fetch_stats(); int open_count = 0; for (int j = 0; j < count; j++) { - if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TLS)) { + if ((tls_stats[j].state == SOCK_OPEN) && (tls_stats[j].proto == NSAPI_TCP)) { open_count++; } } diff --git a/TESTS/netsocket/tls/tlssocket_open_twice.cpp b/TESTS/netsocket/tls/tlssocket_open_twice.cpp index 214ec0dfc0f..e78255d0063 100644 --- a/TESTS/netsocket/tls/tlssocket_open_twice.cpp +++ b/TESTS/netsocket/tls/tlssocket_open_twice.cpp @@ -28,12 +28,6 @@ using namespace utest::v1; void TLSSOCKET_OPEN_TWICE() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); - } -#endif TLSSocket *sock = new TLSSocket; if (!sock) { TEST_FAIL(); @@ -43,12 +37,6 @@ void TLSSOCKET_OPEN_TWICE() TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); delete sock; -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, tls_stats[j].state); - } -#endif } #endif // defined(MBEDTLS_SSL_CLI_C) diff --git a/TESTS/netsocket/udp/main.cpp b/TESTS/netsocket/udp/main.cpp index 613d2af850c..c3c8c9d49cc 100644 --- a/TESTS/netsocket/udp/main.cpp +++ b/TESTS/netsocket/udp/main.cpp @@ -112,6 +112,38 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t return greentea_test_teardown_handler(passed, failed, failure); } +utest::v1::status_t greentea_case_setup_handler_udp(const Case *const source, const size_t index_of_case) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); + } +#endif + return greentea_case_setup_handler(source, index_of_case); +} + +utest::v1::status_t greentea_case_teardown_handler_udp(const Case *const source, const size_t passed, const size_t failed, const failure_t failure) +{ +#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED + int count = fetch_stats(); + for (int j = 0; j < count; j++) { + TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); + } +#endif + return greentea_case_teardown_handler(source, passed, failed, failure); +} + +static void test_failure_handler(const failure_t failure) +{ + UTEST_LOG_FUNCTION(); + if (failure.location == LOCATION_TEST_SETUP || failure.location == LOCATION_TEST_TEARDOWN) { + verbose_test_failure_handler(failure); + GREENTEA_TESTSUITE_RESULT(false); + while (1) ; + } +} + Case cases[] = { Case("UDPSOCKET_OPEN_CLOSE_REPEAT", UDPSOCKET_OPEN_CLOSE_REPEAT), Case("UDPSOCKET_OPEN_LIMIT", UDPSOCKET_OPEN_LIMIT), @@ -135,7 +167,16 @@ Case cases[] = { Case("UDPSOCKET_ECHOTEST_BURST", UDPSOCKET_ECHOTEST_BURST), }; -Specification specification(greentea_setup, cases, greentea_teardown, greentea_continue_handlers); +handlers_t udp_test_case_handlers = { + default_greentea_test_setup_handler, + greentea_test_teardown_handler, + test_failure_handler, + greentea_case_setup_handler_udp, + greentea_case_teardown_handler_udp, + greentea_case_failure_continue_handler +}; + +Specification specification(greentea_setup, cases, greentea_teardown, udp_test_case_handlers); int main() { diff --git a/TESTS/netsocket/udp/udpsocket_bind_address.cpp b/TESTS/netsocket/udp/udpsocket_bind_address.cpp index 2e2bffa6f95..2ce75802120 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_address.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_address.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_ADDRESS() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -47,11 +40,4 @@ void UDPSOCKET_BIND_ADDRESS() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp b/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp index 2a8d66ac1a1..f80fd2e3cb8 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_address_invalid.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_ADDRESS_INVALID() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -55,11 +48,4 @@ void UDPSOCKET_BIND_ADDRESS_INVALID() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp b/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp index 09525491788..1f68c66b0a6 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_address_null.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_ADDRESS_NULL() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -46,11 +39,4 @@ void UDPSOCKET_BIND_ADDRESS_NULL() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_address_port.cpp b/TESTS/netsocket/udp/udpsocket_bind_address_port.cpp index c3917dea2cc..f86ef9d36a0 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_address_port.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_address_port.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_ADDRESS_PORT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -46,11 +39,4 @@ void UDPSOCKET_BIND_ADDRESS_PORT() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_port.cpp b/TESTS/netsocket/udp/udpsocket_bind_port.cpp index 3ad36fd94c4..ec8dfb6fbc2 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_port.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_port.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_PORT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -46,11 +39,4 @@ void UDPSOCKET_BIND_PORT() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp b/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp index 14f052a7aef..90973fd0308 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_port_fail.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_PORT_FAIL() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -56,11 +49,4 @@ void UDPSOCKET_BIND_PORT_FAIL() delete sock; delete sock2; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp b/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp index a422fa35c03..cbe1e27fa57 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_unopened.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_UNOPENED() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -45,11 +38,4 @@ void UDPSOCKET_BIND_UNOPENED() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp b/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp index e2e3b2f9167..1b5887ae6b8 100644 --- a/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp +++ b/TESTS/netsocket/udp/udpsocket_bind_wrong_type.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_BIND_WRONG_TYPE() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -55,11 +48,4 @@ void UDPSOCKET_BIND_WRONG_TYPE() } delete sock; - -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_echotest.cpp b/TESTS/netsocket/udp/udpsocket_echotest.cpp index 928164cfdfe..d93cd431f07 100644 --- a/TESTS/netsocket/udp/udpsocket_echotest.cpp +++ b/TESTS/netsocket/udp/udpsocket_echotest.cpp @@ -133,13 +133,6 @@ void udpsocket_echotest_nonblock_receiver(void *receive_bytes) void UDPSOCKET_ECHOTEST_NONBLOCK() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int j = 0; - int count = fetch_stats(); - for (; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif tc_exec_time.start(); time_allotted = split2half_rmng_udp_test_time(); // [s] @@ -205,8 +198,9 @@ void UDPSOCKET_ECHOTEST_NONBLOCK() TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); #if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (j = 0; j < count; j++) { + int count = fetch_stats(); + int j = 0; + for (; j < count; j++) { if ((NSAPI_UDP == udp_stats[j].proto) && (SOCK_OPEN == udp_stats[j].state)) { TEST_ASSERT(udp_stats[j].sent_bytes != 0); TEST_ASSERT(udp_stats[j].recv_bytes != 0); diff --git a/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp b/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp index 90ca0031f55..de83bcbef85 100644 --- a/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp +++ b/TESTS/netsocket/udp/udpsocket_open_close_repeat.cpp @@ -26,12 +26,6 @@ using namespace utest::v1; void UDPSOCKET_OPEN_CLOSE_REPEAT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -42,10 +36,4 @@ void UDPSOCKET_OPEN_CLOSE_REPEAT() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->close()); } delete sock; -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_open_destruct.cpp b/TESTS/netsocket/udp/udpsocket_open_destruct.cpp index a3e4f80a340..adeb47e91b0 100644 --- a/TESTS/netsocket/udp/udpsocket_open_destruct.cpp +++ b/TESTS/netsocket/udp/udpsocket_open_destruct.cpp @@ -26,13 +26,6 @@ using namespace utest::v1; void UDPSOCKET_OPEN_DESTRUCT() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif - for (int i = 0; i < 100; i++) { UDPSocket *sock = new UDPSocket; if (!sock) { @@ -41,10 +34,4 @@ void UDPSOCKET_OPEN_DESTRUCT() TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock->open(NetworkInterface::get_default_instance())); delete sock; } -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif } diff --git a/TESTS/netsocket/udp/udpsocket_open_twice.cpp b/TESTS/netsocket/udp/udpsocket_open_twice.cpp index 3965d35d223..670757c9110 100644 --- a/TESTS/netsocket/udp/udpsocket_open_twice.cpp +++ b/TESTS/netsocket/udp/udpsocket_open_twice.cpp @@ -26,12 +26,6 @@ using namespace utest::v1; void UDPSOCKET_OPEN_TWICE() { -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - int count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif UDPSocket *sock = new UDPSocket; if (!sock) { TEST_FAIL(); @@ -41,10 +35,4 @@ void UDPSOCKET_OPEN_TWICE() TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, sock->open(NetworkInterface::get_default_instance())); delete sock; -#if MBED_CONF_NSAPI_SOCKET_STATS_ENABLED - count = fetch_stats(); - for (int j = 0; j < count; j++) { - TEST_ASSERT_EQUAL(SOCK_CLOSED, udp_stats[j].state); - } -#endif }