From fe08f23a50767efff70680d8fb7699e31e06c43e Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 22 Jul 2020 13:08:57 -0700 Subject: [PATCH] Improved test sleep. Cleanup `sleep` calls. --- examples/benchmark/tls_bench.c | 4 +-- examples/client/client.c | 59 +++++++--------------------------- wolfssl/test.h | 16 +++++++-- 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/examples/benchmark/tls_bench.c b/examples/benchmark/tls_bench.c index be11be362..f130f28d1 100644 --- a/examples/benchmark/tls_bench.c +++ b/examples/benchmark/tls_bench.c @@ -1285,7 +1285,7 @@ static int bench_tls_server(info_t* info) ret = SocketWaitClient(info); #ifdef BENCH_USE_NONBLOCK if (ret == -2) { - sleep(0); + XSLEEP_MS(0); continue; } #endif @@ -1831,7 +1831,7 @@ int bench_tls(void* args) info = &theadInfo[i]; if (!info->to_client.done || !info->to_server.done) { doShutdown = 0; - sleep(1); /* Allow other threads to run */ + XSLEEP_MS(1000); /* Allow other threads to run */ } } diff --git a/examples/client/client.c b/examples/client/client.c index a8225f8b5..826615996 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -65,12 +65,14 @@ #define OCSP_STAPLINGV2_MULTI 3 #define OCSP_STAPLING_OPT_MAX OCSP_STAPLINGV2_MULTI -#define WXSLEEP(x,y) do { \ - struct timeval tv = {(x),(y)}; \ - select(0, NULL, NULL, NULL, &tv); \ -} while (0) -#define WUSLEEP(x) WXSLEEP(0,x) -#define WSLEEP(x) WXSLEEP(x,0) +#if defined(XUSLEEP) && defined(NO_MAIN_DRIVER) + /* This is to force the server's thread to get a chance to + * execute before continuing the resume in non-blocking + * DTLS test cases. */ + #define TEST_DELAY() XSLEEP_US(10000) +#else + #define TEST_DELAY() XSLEEP_MS(1000) +#endif /* Note on using port 0: the client standalone example doesn't utilize the * port 0 port sharing; that is used by (1) the server in external control @@ -3142,20 +3144,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) /* allow some time for exporting the session */ #ifdef WOLFSSL_SESSION_EXPORT_DEBUG -#ifdef USE_WINDOWS_API - Sleep(500); -#elif defined(WOLFSSL_TIRTOS) - Task_sleep(1); -#else - /* This is to force the server's thread to get a chance to - * execute before continuing the resume in non-blocking - * DTLS test cases. */ -#ifdef NO_MAIN_DRIVER - WUSLEEP(10000); -#else - WSLEEP(1); -#endif -#endif + TEST_DELAY(); #endif /* WOLFSSL_SESSION_EXPORT_DEBUG */ #ifdef WOLFSSL_TLS13 @@ -3254,20 +3243,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) #endif if (dtlsUDP) { -#ifdef USE_WINDOWS_API - Sleep(500); -#elif defined(WOLFSSL_TIRTOS) - Task_sleep(1); -#else - /* This is to force the server's thread to get a chance to - * execute before continuing the resume in non-blocking - * DTLS test cases. */ - #ifdef NO_MAIN_DRIVER - WUSLEEP(10000); - #else - WSLEEP(1); - #endif -#endif + TEST_DELAY(); } tcp_connect(&sockfd, host, port, dtlsUDP, dtlsSCTP, sslResume); if (wolfSSL_set_fd(sslResume, sockfd) != WOLFSSL_SUCCESS) { @@ -3389,20 +3365,7 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) /* allow some time for exporting the session */ #ifdef WOLFSSL_SESSION_EXPORT_DEBUG - #ifdef USE_WINDOWS_API - Sleep(500); - #elif defined(WOLFSSL_TIRTOS) - Task_sleep(1); - #else - /* This is to force the server's thread to get a chance to - * execute before continuing the resume in non-blocking - * DTLS test cases. */ - #ifdef NO_MAIN_DRIVER - WUSLEEP(10000); - #else - WSLEEP(1); - #endif - #endif + TEST_DELAY(); #endif /* WOLFSSL_SESSION_EXPORT_DEBUG */ #ifdef HAVE_SECURE_RENEGOTIATION diff --git a/wolfssl/test.h b/wolfssl/test.h index 385a3be21..3c2f4ada9 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -55,6 +55,7 @@ #endif #define SOCKET_T SOCKET #define SNPRINTF _snprintf + #define XSLEEP_MS(t) Sleep(t) #elif defined(WOLFSSL_MDK_ARM) || defined(WOLFSSL_KEIL_TCP_NET) #include #include "rl_net.h" @@ -69,9 +70,9 @@ return(ret) ; } #if defined(HAVE_KEIL_RTX) - #define sleep(t) os_dly_wait(t/1000+1); + #define XSLEEP_MS(t) os_dly_wait(t) #elif defined(WOLFSSL_CMSIS_RTOS) || defined(WOLFSSL_CMSIS_RTOSv2) - #define sleep(t) osDelay(t/1000+1); + #define XSLEEP_MS(t) osDelay(t) #endif #elif defined(WOLFSSL_TIRTOS) #include @@ -88,6 +89,7 @@ char **h_addr_list; /* list of addresses from name server */ }; #define SOCKET_T int + #define XSLEEP_MS(t) Task_sleep(t/1000) #elif defined(WOLFSSL_VXWORKS) #include #include @@ -148,8 +150,18 @@ #include /* ignore SIGPIPE */ #endif #define SNPRINTF snprintf + + #define XSELECT_WAIT(x,y) do { \ + struct timeval tv = {(x),(y)}; \ + select(0, NULL, NULL, NULL, &tv); \ + } while (0) + #define XSLEEP_US(u) XSELECT_WAIT(0,u) #endif /* USE_WINDOWS_API */ +#ifndef XSLEEP_MS + #define XSLEEP_MS(t) sleep(t/1000) +#endif + #ifdef WOLFSSL_ASYNC_CRYPT #include #endif