From 614ba3506021628c5bff7934f479390b2c70baf1 Mon Sep 17 00:00:00 2001 From: Sandro Kalatozishvili Date: Fri, 9 Aug 2024 03:09:00 +0400 Subject: [PATCH] Implemented timed assert definition --- Makefile | 2 +- misc/Makefile.tmp | 2 +- misc/smake.tmp | 2 +- smake.json | 2 +- src/xdef.h | 20 ++++++++++++++++++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 399a0b1..87b1fc5 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # https://github.com/kala13x/smake # #################################### -CFLAGS = -D_XUTILS_USE_SSL -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU +CFLAGS = -D_XUTILS_USE_SSL -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED CFLAGS += -I./src/crypt -I./src/data -I./src/net -I./src/sys -I./src LIBS = -lssl -lcrypto -lpthread NAME = libxutils.a diff --git a/misc/Makefile.tmp b/misc/Makefile.tmp index 2a05709..4137d24 100644 --- a/misc/Makefile.tmp +++ b/misc/Makefile.tmp @@ -3,7 +3,7 @@ # https://github.com/kala13x/smake # #################################### -CFLAGS = _SSL_FLAGS_ -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU +CFLAGS = _SSL_FLAGS_ -g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED CFLAGS += -I./src/crypt -I./src/data -I./src/net -I./src/sys -I./src LIBS = _SSL_LIBS_ -lpthread NAME = libxutils.a diff --git a/misc/smake.tmp b/misc/smake.tmp index 9dc7cc1..ce7a7b8 100644 --- a/misc/smake.tmp +++ b/misc/smake.tmp @@ -2,7 +2,7 @@ "build": { "name": "libxutils.a", "outputDir": "./build", - "flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU", + "flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED", "libs": "-lpthread", "overwrite": true, "verbose": 2, diff --git a/smake.json b/smake.json index 407096b..e26fd2c 100644 --- a/smake.json +++ b/smake.json @@ -2,7 +2,7 @@ "build": { "name": "libxutils.a", "outputDir": "./build", - "flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU", + "flags": "-g -O2 -Wall -D_XUTILS_DEBUG -D_XUTILS_USE_GNU -D_ASSERT_TIMED", "libs": "-lpthread", "overwrite": true, "verbose": 2, diff --git a/src/xdef.h b/src/xdef.h index 3ef8c85..1c7f4af 100644 --- a/src/xdef.h +++ b/src/xdef.h @@ -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 +#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%s " \ + "Assert failed: " \ + "%s:%s():%s\n", \ + XCLR_RED, XCLR_RES, \ + timeStr, \ + __FILE__, \ + __FUNCTION__, \ + __XLOCATION__); \ + } +#else #define XTROW_LOCATION \ printf("%s%s " \ "Assert failed: " \ @@ -118,6 +137,7 @@ typedef uint8_t xbool_t; __FILE__, \ __FUNCTION__, \ __XLOCATION__) +#endif #define XASSERT_RET(condition, value) \ if (!condition) return value