Skip to content

Commit

Permalink
Implemented timed assert definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Kalatozishvili committed Aug 8, 2024
1 parent e3d45ce commit 572d0c9
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/xdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,25 @@ typedef uint8_t xbool_t;
#define XLOCATION_LVL2(line) XLOCATION_LVL1(line)
#define __XLOCATION__ XLOCATION_LVL2(__LINE__)

#ifdef _ASSERT_TIMED
#include <time.h>
#define XTROW_LOCATION \
{ \
char timeStr[20]; \
time_t now = time(NULL); \
struct tm *tmInfo = localtime(&now); \
strftime(timeStr, sizeof(timeStr), \
"%H:%M:%S.%03d", tmInfo ); \
printf("%s %s<error>%s " \
"Assert failed: " \
"%s:%s():%s\n", \
XCLR_RED, XCLR_RES, \
timeStr, \
__FILE__, \
__FUNCTION__, \
__XLOCATION__); \
}
#else
#define XTROW_LOCATION \
printf("%s<error>%s " \
"Assert failed: " \
Expand All @@ -118,6 +137,7 @@ typedef uint8_t xbool_t;
__FILE__, \
__FUNCTION__, \
__XLOCATION__)
#endif

#define XASSERT_RET(condition, value) \
if (!condition) return value
Expand Down

0 comments on commit 572d0c9

Please sign in to comment.