From b4b1739783f0233b9a27cefcdc292b9305f4e892 Mon Sep 17 00:00:00 2001 From: Sean Parkinson Date: Mon, 12 Dec 2022 12:07:39 +1000 Subject: [PATCH] API test: Report time taken to perform test API test now displays timing taken to perform a test case to help identify ones that are doing too much work. --- tests/api.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index 4c0ca5843..67bbe0406 100644 --- a/tests/api.c +++ b/tests/api.c @@ -60429,10 +60429,23 @@ static const char* apitest_res_string(int res) return str; } +#ifndef WOLFSSL_UNIT_TEST_NO_TIMING +static double gettime_secs(void) +{ + struct timeval tv; + LIBCALL_CHECK_RET(gettimeofday(&tv, 0)); + + return (double)tv.tv_sec + (double)tv.tv_usec / 1000000; +} +#endif + void ApiTest(void) { int i; int ret; +#ifndef WOLFSSL_UNIT_TEST_NO_TIMING + double timeDiff; +#endif printf(" Begin API Tests\n"); fflush(stdout); @@ -60445,10 +60458,24 @@ void ApiTest(void) TestSetup(); - printf(" %3d: %-60s:", i + 1, testCases[i].name); + printf(" %3d: %-52s:", i + 1, testCases[i].name); fflush(stdout); + #ifndef WOLFSSL_UNIT_TEST_NO_TIMING + timeDiff = gettime_secs(); + #endif ret = testCases[i].func(); - printf(" %s\n", apitest_res_string(ret)); + #ifndef WOLFSSL_UNIT_TEST_NO_TIMING + timeDiff = gettime_secs() - timeDiff; + #endif + #ifndef WOLFSSL_UNIT_TEST_NO_TIMING + if (ret != TEST_SKIPPED) { + printf(" %s (%9.5lf)\n", apitest_res_string(ret), timeDiff); + } + else + #endif + { + printf(" %s\n", apitest_res_string(ret)); + } fflush(stdout); AssertIntNE(ret, TEST_FAIL);