Commit | Line | Data |
---|---|---|
5d7e8359 PP |
1 | /* |
2 | * SPDX-License-Identifier: GPL-2.0-only | |
3 | * | |
4 | * Copyright (C) 2020 Philippe Proulx <pproulx@efficios.com> | |
5 | */ | |
6 | ||
7 | #ifndef TESTS_LIB_CONDS_UTILS_H | |
8 | #define TESTS_LIB_CONDS_UTILS_H | |
9 | ||
fb10c90e SM |
10 | #include <babeltrace2/babeltrace.h> |
11 | ||
5d15e4ca | 12 | #include "cpp-common/bt2/self-component-port.hpp" |
6e3150f4 | 13 | #include "cpp-common/bt2s/span.hpp" |
5d15e4ca | 14 | |
486428e8 SM |
15 | enum cond_trigger_func_type |
16 | { | |
17 | COND_TRIGGER_FUNC_TYPE_BASIC, | |
18 | COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, | |
5d7e8359 PP |
19 | }; |
20 | ||
486428e8 SM |
21 | enum cond_trigger_type |
22 | { | |
23 | COND_TRIGGER_TYPE_PRE, | |
24 | COND_TRIGGER_TYPE_POST, | |
5d7e8359 PP |
25 | }; |
26 | ||
486428e8 | 27 | typedef void (*cond_trigger_basic_func)(void); |
5d15e4ca | 28 | typedef void (*cond_trigger_run_in_comp_cls_init_func)(bt2::SelfComponent); |
5d7e8359 | 29 | |
486428e8 SM |
30 | struct cond_trigger |
31 | { | |
32 | enum cond_trigger_type type; | |
33 | enum cond_trigger_func_type func_type; | |
34 | const char *cond_id; | |
35 | const char *suffix; | |
36 | union | |
37 | { | |
38 | cond_trigger_basic_func basic; | |
39 | cond_trigger_run_in_comp_cls_init_func run_in_comp_cls_init; | |
40 | } func; | |
5d7e8359 PP |
41 | }; |
42 | ||
486428e8 SM |
43 | #define COND_TRIGGER_PRE_BASIC(_cond_id, _suffix, _func) \ |
44 | { \ | |
45 | .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ | |
46 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
47 | .basic = _func, \ | |
48 | } \ | |
49 | } | |
5d7e8359 | 50 | |
486428e8 SM |
51 | #define COND_TRIGGER_POST_BASIC(_cond_id, _suffix, _func) \ |
52 | { \ | |
53 | .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_BASIC, \ | |
54 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
55 | .basic = _func, \ | |
56 | } \ | |
57 | } | |
5d7e8359 | 58 | |
486428e8 SM |
59 | #define COND_TRIGGER_PRE_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ |
60 | { \ | |
61 | .type = COND_TRIGGER_TYPE_PRE, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ | |
62 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
63 | .run_in_comp_cls_init = _func, \ | |
64 | } \ | |
65 | } | |
5d7e8359 | 66 | |
486428e8 SM |
67 | #define COND_TRIGGER_POST_RUN_IN_COMP_CLS_INIT(_cond_id, _suffix, _func) \ |
68 | { \ | |
69 | .type = COND_TRIGGER_TYPE_POST, .func_type = COND_TRIGGER_FUNC_TYPE_RUN_IN_COMP_CLS_INIT, \ | |
70 | .cond_id = _cond_id, .suffix = _suffix, .func = { \ | |
71 | .run_in_comp_cls_init = _func, \ | |
72 | } \ | |
73 | } | |
5d7e8359 | 74 | |
6e3150f4 | 75 | void condMain(int argc, const char **argv, bt2s::span<const cond_trigger> triggers) noexcept; |
5d7e8359 PP |
76 | |
77 | #endif /* TESTS_LIB_CONDS_UTILS_H */ |