b1d6b31ecfe89e4136cee5a368e27534283c0bd6
[c11tester.git] / common.h
1 /** @file common.h
2  *  @brief General purpose macros.
3  */
4
5 #ifndef __COMMON_H__
6 #define __COMMON_H__
7
8 #include <stdio.h>
9 #include "config.h"
10
11 #define model_print(fmt, ...) do { printf(fmt, ##__VA_ARGS__); } while (0)
12
13 #ifdef CONFIG_DEBUG
14 #define DEBUG(fmt, ...) do { model_print("*** %25s(): line %-4d *** " fmt, __func__, __LINE__, ##__VA_ARGS__); } while (0)
15 #define DBG() DEBUG("\n")
16 #define DBG_ENABLED() (1)
17 #else
18 #define DEBUG(fmt, ...)
19 #define DBG()
20 #define DBG_ENABLED() (0)
21 #endif
22
23 void assert_hook(void);
24
25 #ifdef CONFIG_ASSERT
26 #define ASSERT(expr) \
27 do { \
28         if (!(expr)) { \
29                 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
30                 print_trace(); \
31                 model_print_summary(); \
32                 assert_hook();                           \
33                 exit(EXIT_FAILURE); \
34         } \
35 } while (0)
36 #else
37 #define ASSERT(expr) \
38         do { } while (0)
39 #endif /* CONFIG_ASSERT */
40
41 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
42
43 void print_trace(void);
44 void model_print_summary(void);
45 #endif /* __COMMON_H__ */