model: get_num_threads() should be const
[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 #ifdef CONFIG_DEBUG
12 #define DEBUG(fmt, ...) do { printf("*** %25s(): line %-4d *** " fmt, __func__, __LINE__, ##__VA_ARGS__); } while (0)
13 #define DBG() DEBUG("\n")
14 #define DBG_ENABLED() (1)
15 #else
16 #define DEBUG(fmt, ...)
17 #define DBG()
18 #define DBG_ENABLED() (0)
19 #endif
20
21 void assert_hook(void);
22
23 #ifdef CONFIG_ASSERT
24 #define ASSERT(expr) \
25 do { \
26         if (!(expr)) { \
27                 fprintf(stderr, "Error: assertion failed in %s at line %d\n", __FILE__, __LINE__); \
28                 print_trace(); \
29                 model_print_summary(); \
30                 assert_hook();                           \
31                 exit(EXIT_FAILURE); \
32         } \
33 } while (0)
34 #else
35 #define ASSERT(expr) \
36         do { } while (0)
37 #endif /* CONFIG_ASSERT */
38
39 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
40
41 void print_trace(void);
42 void model_print_summary(void);
43 #endif /* __COMMON_H__ */