Add Asan profile, fix multiple bugs.
Added Asan profile to help catch and fix various bugs (and indeed, there were few of them). Additionally, fixed bhunit macro to process arguments only once.
This commit is contained in:
@@ -25,5 +25,5 @@ target_include_directories(bhunit PUBLIC include)
|
||||
if(MSVC)
|
||||
target_compile_options(bhunit PRIVATE /W4 /WX)
|
||||
else()
|
||||
target_compile_options(bhunit PRIVATE -Wall -Wextra -Wpedantic -Werror)
|
||||
target_compile_options(bhunit PRIVATE -Wall -Wextra -Wpedantic -Werror -fstrict-aliasing)
|
||||
endif()
|
||||
@@ -2,26 +2,37 @@
|
||||
#define BH_UNIT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
typedef int (*bh_unit_cb_t)(void);
|
||||
|
||||
#define BH_VERIFY(e) \
|
||||
do { if (!(e)) { \
|
||||
printf("%s:%d\t%s\n", __FILE__, __LINE__, #e); \
|
||||
return -1; \
|
||||
} } while(0)
|
||||
do { \
|
||||
if (!(e)) { \
|
||||
printf("%s:%d\t%s\n", __FILE__, __LINE__, #e); \
|
||||
return -1; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define BH_FAIL(msg) \
|
||||
do { printf("%s:%d\t%s\n", __FILE__, __LINE__, msg); \
|
||||
return -1; } while(0)
|
||||
do { \
|
||||
printf("%s:%d\t%s\n", __FILE__, __LINE__, msg); \
|
||||
return -1; \
|
||||
} while(0)
|
||||
|
||||
|
||||
#define BH_VERIFY_DELTA(x, y, e) \
|
||||
do { if ((((x)>(y))?((x)-(y)):((y)-(x)))>(e)) { \
|
||||
printf("%s:%d\t%s\n", __FILE__, __LINE__, #x " == " #y); \
|
||||
return -1; \
|
||||
} while (0)
|
||||
do { \
|
||||
double BH_VERIFY_DELTA = (x)-(y); \
|
||||
if (BH_VERIFY_DELTA < 0.0) \
|
||||
BH_VERIFY_DELTA = -BH_VERIFY_DELTA; \
|
||||
if (BH_VERIFY_DELTA > (e)) { \
|
||||
printf("%s:%d\t%s (differs by %f)\n", __FILE__, __LINE__, #x " == " #y, BH_VERIFY_DELTA); \
|
||||
return -1; \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
|
||||
void bh_unit_add(const char *name, bh_unit_cb_t func);
|
||||
int bh_unit_run(void);
|
||||
|
||||
Reference in New Issue
Block a user