From 0b5564887d38a77137ed1af0e6acfa86ac3bd57c Mon Sep 17 00:00:00 2001 From: molingyu Date: Sun, 8 Sep 2024 02:39:28 +0800 Subject: [PATCH] fix: fix test get function error on linux CLK_TCK => clock_gettime --- test/unit_test.c | 2 +- test/unit_test.h | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unit_test.c b/test/unit_test.c index 92c68ea..07551e9 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -179,6 +179,6 @@ int _utest_test_closure_failed = 0; int _utest_test_closure_passed = 0; char* _utest_current_test_unit_name = ""; -clock_t _utest_test_start, _utest_test_end; +struct timespec _utest_test_start, _utest_test_end; int _utest_test_unit_return = 0; diff --git a/test/unit_test.h b/test/unit_test.h index 7a61cc9..11c93de 100644 --- a/test/unit_test.h +++ b/test/unit_test.h @@ -182,7 +182,7 @@ extern int _utest_test_closure_failed; extern int _utest_test_closure_passed; extern char* _utest_current_test_unit_name; -extern clock_t _utest_test_start, _utest_test_end; +extern struct timespec _utest_test_start, _utest_test_end; extern int _utest_test_unit_return; @@ -191,15 +191,16 @@ extern int _utest_test_unit_return; { \ printf( "Tarting %s unit tests\n", T ); \ printf( "\n" ); \ - _utest_test_start = clock(); \ + clock_gettime( CLOCK_MONOTONIC, &_utest_test_start ); \ BLOCK; \ - _utest_test_end = clock(); \ + clock_gettime( CLOCK_MONOTONIC, &_utest_test_end ); \ printf( "\n" ); \ printf( "Test Suites: \033[31m%d failed\033[0m, \033[32m%d passed\033[0m, %d total\n", _utest_test_suite_failed, \ _utest_test_suite_passed, _utest_test_suite_total ); \ printf( "Test: \033[31m%d failed\033[0m, \033[32m%d passed\033[0m, %d total\n", _utest_test_units_failed, \ _utest_test_units_passed, _utest_test_units_total ); \ - printf( "Time: %.4f s\n", (double)( _utest_test_end - _utest_test_start ) / CLK_TCK ); \ + printf( "Time: %.4f s\n", (double)( ( _utest_test_end.tv_sec - _utest_test_start.tv_sec ) + \ + ( _utest_test_end.tv_nsec - _utest_test_start.tv_nsec ) / 1e9 ) ); \ printf( "\nRan all test suites.\n" ); \ if ( _utest_test_units_failed == 0 ) \ { \