|
11 | 11 |
|
12 | 12 | #include <stdbool.h>
|
13 | 13 |
|
14 |
| -void c_output(const char *format, ...) __attribute__ ((format (printf, 1, 2))); |
15 |
| - |
16 |
| - |
| 14 | +/** |
| 15 | + * Blocks calling thread until event is published. |
| 16 | + */ |
17 | 17 | void c_wait_event(const char *event);
|
18 | 18 |
|
| 19 | +/** |
| 20 | + * Unblocks all threads waiting for event. |
| 21 | + */ |
19 | 22 | void c_publish_event(const char *event);
|
20 | 23 |
|
| 24 | +/** |
| 25 | + * Returns true if event was published. |
| 26 | + */ |
21 | 27 | bool c_is_event_published(const char *event);
|
22 | 28 |
|
23 |
| - |
| 29 | +/** |
| 30 | + * Sets desired interleaving of blocks. Sequence that may run concurrently |
| 31 | + * should be delimited with ' ', sequences for sequential execution with ';'. |
| 32 | + */ |
24 | 33 | void c_set_blocks_interleaving(const char *interleaving);
|
25 | 34 |
|
| 35 | +/** |
| 36 | + * Marks beginning of block. |
| 37 | + */ |
26 | 38 | void c_begin_block(const char *block);
|
27 | 39 |
|
| 40 | +/** |
| 41 | + * Marks end of block. |
| 42 | + */ |
28 | 43 | void c_end_block();
|
29 | 44 |
|
| 45 | +/** |
| 46 | + * Convenience function equivalent to c_begin_block(id); c_end_block(). That |
| 47 | + * allows for similar behaviour as event API. |
| 48 | + */ |
30 | 49 | void c_one_line_block(const char *block);
|
31 | 50 |
|
| 51 | +/** |
| 52 | + * Checks if block has not been started yet. |
| 53 | + */ |
32 | 54 | bool c_is_before_block(const char *block);
|
33 | 55 |
|
| 56 | +/** |
| 57 | + * Checks if block has been started and has not finished yet. |
| 58 | + */ |
34 | 59 | bool c_is_during_block(const char *block);
|
35 | 60 |
|
| 61 | +/** |
| 62 | + * Check if block has finished. |
| 63 | + */ |
36 | 64 | bool c_is_after_block(const char *block);
|
37 | 65 |
|
| 66 | +/** |
| 67 | + * Function for safe outputting to stderr. |
| 68 | + */ |
| 69 | +void c_output(const char *format, ...) __attribute__ ((format (printf, 1, 2))); |
| 70 | + |
| 71 | +/** |
| 72 | + * Asserts that COND is true. Prints passed message otherwise. |
| 73 | + */ |
38 | 74 | #define c_assert_true(COND, FMT, ...) do { if (!(COND)) { c_output("[%s:%s:%d]: Assert failed: " FMT "\n", __FILE__, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); } } while (0)
|
| 75 | +/** |
| 76 | + * Asserts that COND is false. Prints passed message otherwise. |
| 77 | + */ |
39 | 78 | #define c_assert_false(COND, FMT, ...) c_assert_true(!(COND), FMT, ##__VA_ARGS__)
|
| 79 | +/** |
| 80 | + * Asserts that EVENT has not been published yet. Prints passed message otherwise. |
| 81 | + */ |
40 | 82 | #define c_assert_before_event(EVENT, FMT, ...) do { if (c_is_event_published(EVENT)) c_assert_true(0, FMT, ##__VA_ARGS__); } while (0)
|
| 83 | +/** |
| 84 | + * Asserts that EVENT has been published. Prints passed message otherwise. |
| 85 | + */ |
41 | 86 | #define c_assert_after_event(EVENT, FMT, ...) do { if (!c_is_event_published(EVENT)) c_assert_true(0, FMT, ##__VA_ARGS__); } while (0)
|
| 87 | +/** |
| 88 | + * Asserts that BLOCK has not been started yet. Prints passed message otherwise. |
| 89 | + */ |
42 | 90 | #define c_assert_before_block(BLOCK, FMT, ...) do { if (!c_is_before_block(BLOCK)) c_assert_true(0, FMT, ##__VA_ARGS__); } while (0)
|
| 91 | +/** |
| 92 | + * Asserts that BLOCK has been started but has not finished yet. Prints passed message otherwise. |
| 93 | + */ |
43 | 94 | #define c_assert_during_block(BLOCK, FMT, ...) do { if (!c_is_during_block(BLOCK)) c_assert_true(0, FMT, ##__VA_ARGS__); } while (0)
|
| 95 | +/** |
| 96 | + * Asserts that BLOCK has finished. Prints passed message otherwise. |
| 97 | + */ |
44 | 98 | #define c_assert_after_block(BLOCK, FMT, ...) do { if (!c_is_after_block(BLOCK)) c_assert_true(0, FMT, ##__VA_ARGS__); } while (0)
|
45 | 99 |
|
46 | 100 | #else
|
|
0 commit comments