Skip to content

Commit

Permalink
ci: fix gh action error(time)
Browse files Browse the repository at this point in the history
  • Loading branch information
molingyu committed Sep 7, 2024
1 parent 762c5f6 commit 2dd9d5c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
4 changes: 0 additions & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ set_target_properties(test PROPERTIES
C_EXTENSIONS NO
)

if (UNIX)
target_link_libraries(test PRIVATE rt)
endif ()

# Special access to i18n-format internals for testing
target_include_directories(test PRIVATE ${CMAKE_SOURCE_DIR}/src)

Expand Down
5 changes: 4 additions & 1 deletion test/unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ int _utest_test_closure_failed = 0;
int _utest_test_closure_passed = 0;

char* _utest_current_test_unit_name = "";
#ifdef __linux__
struct timeval _utest_test_start, _utest_test_end;
#else
struct timespec _utest_test_start, _utest_test_end;

#endif
int _utest_test_unit_return = 0;
28 changes: 22 additions & 6 deletions test/unit_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@

#pragma once

#define _POSIX_C_SOURCE 199309L
#ifdef __linux__
#include <sys/time.h>
#endif

#include <stdio.h>
#include <time.h>

Expand All @@ -183,25 +186,38 @@ extern int _utest_test_closure_failed;
extern int _utest_test_closure_passed;

extern char* _utest_current_test_unit_name;
extern struct timespec _utest_test_start, _utest_test_end;

extern int _utest_test_unit_return;

#ifdef __linux__
extern struct timeval _utest_test_start, _utest_test_end;
#define CURRENT_TIME( A ) gettimeofday( &A, NULL );
#define ELAPSED \
(double)( ( 1000000 * ( _utest_test_end.tv_sec - _utest_test_start.tv_sec ) + \
( _utest_test_end.tv_usec - _utest_test_start.tv_usec ) ) / \
1000000.0 )
#else
extern struct timespec _utest_test_start, _utest_test_end;
#define CURRENT_TIME( A ) clock_gettime( CLOCK_MONOTONIC, &A );
#define ELAPSED \
(double)( ( _utest_test_end.tv_sec - _utest_test_start.tv_sec ) + \
( _utest_test_end.tv_nsec - _utest_test_start.tv_nsec ) / 1e9 )
#endif

#define TEST_START( T, BLOCK ) \
do \
{ \
printf( "Tarting %s unit tests\n", T ); \
printf( "\n" ); \
clock_gettime( CLOCK_MONOTONIC, &_utest_test_start ); \
CURRENT_TIME( _utest_test_start ); \
BLOCK; \
clock_gettime( CLOCK_MONOTONIC, &_utest_test_end ); \
CURRENT_TIME( _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.tv_sec - _utest_test_start.tv_sec ) + \
( _utest_test_end.tv_nsec - _utest_test_start.tv_nsec ) / 1e9 ) ); \
printf( "Time: %.4f s\n", ELAPSED ); \
printf( "\nRan all test suites.\n" ); \
if ( _utest_test_units_failed == 0 ) \
{ \
Expand Down

0 comments on commit 2dd9d5c

Please sign in to comment.