yahelpers
Enhanced debugging functionality for the ya ecosystem
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1
12#ifndef ASSERT_H
13#define ASSERT_H
14
15#ifndef NDEBUG
16
17#include "log.h"
18
25#define ASSERT_DEFAULT 0
26
28#define ASSERT_NO_ABORT 1
29
31#define ASSERT_NO_TIMESTAMP 2
32
34#define ASSERT_FOR_TESTS 4
35
36#include <stdlib.h> /* for abort() */
37#include <time.h>
38
39#include <assert.h>
40
49#define ASSERT(cond, opts) \
50 do { \
51 if (!(cond)) { \
52 if ((opts) & ASSERT_NO_TIMESTAMP) { \
53 LOG_DEBUG("ASSERT " #cond " failed !!!"); \
54 } else { \
55 time_t assert_time = time(NULL); \
56 LOG_DEBUG("[% ld ] ASSERT " #cond " failed !!!"); \
57 } \
58 if ((opts) & ASSERT_FOR_TESTS) { \
59 assert((cond)); \
60 } else if (!((opts) & ASSERT_NO_ABORT)) { \
61 abort(); \
62 } \
63 } \
64 } while (0)
65
69#else
70
71#define ASSERT_DEFAULT 0
72#define ASSERT_NO_ABORT 0
73#define ASSERT_NO_TIMESTAMP 0
74
75#define ASSERT(cond, opts) /* Empty stub macro*/
76
77#endif
78
79#endif
Assertion utilities for the ya ecosystem.
Logging utilities for the ya ecosystem.