1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "bs_tracing.h"
8 #include "bs_types.h"
9 #include "bstests.h"
10 
11 #define BS_SECONDS(dur_sec)    ((bs_time_t)dur_sec * USEC_PER_SEC)
12 #define TEST_TIMEOUT_SIMULATED BS_SECONDS(10)
13 
14 extern enum bst_result_t bst_result;
15 
16 #define DECLARE_FLAG(flag) extern atomic_t flag
17 #define DEFINE_FLAG(flag)  atomic_t flag = (atomic_t) false
18 #define SET_FLAG(flag)     (void)atomic_set(&flag, (atomic_t) true)
19 #define UNSET_FLAG(flag)   (void)atomic_set(&flag, (atomic_t) false)
20 
21 #define WAIT_FOR_EXPR(var, expr)                                                                   \
22 	while (atomic_get(&var) expr) {                                                            \
23 		(void)k_sleep(K_MSEC(1));                                                          \
24 	}
25 #define WAIT_FOR_VAL(var, val)                                                                     \
26 	while (atomic_get(&var) != val) {                                                          \
27 		(void)k_sleep(K_MSEC(1));                                                          \
28 	}
29 #define WAIT_FOR_FLAG(flag)                                                                        \
30 	while (!(bool)atomic_get(&flag)) {                                                         \
31 		(void)k_sleep(K_MSEC(1));                                                          \
32 	}
33 #define WAIT_FOR_FLAG_UNSET(flag)                                                                  \
34 	while ((bool)atomic_get(&flag)) {                                                          \
35 		(void)k_sleep(K_MSEC(1));                                                          \
36 	}
37 #define TAKE_FLAG(flag)                                                                            \
38 	while (!(bool)atomic_cas(&flag, true, false)) {                                            \
39 		(void)k_sleep(K_MSEC(1));                                                          \
40 	}
41 
42 #define ASSERT(expr, ...)                                                                          \
43 	do {                                                                                       \
44 		if (!(expr)) {                                                                     \
45 			FAIL(__VA_ARGS__);                                                         \
46 		}                                                                                  \
47 	} while (0)
48 
49 #define FAIL(...)                                                                                  \
50 	do {                                                                                       \
51 		bst_result = Failed;                                                               \
52 		bs_trace_error_time_line(__VA_ARGS__);                                             \
53 	} while (0)
54 
55 #define PASS(...)                                                                                  \
56 	do {                                                                                       \
57 		bst_result = Passed;                                                               \
58 		bs_trace_info_time(1, __VA_ARGS__);                                                \
59 	} while (0)
60 
61 #define HVX_HANDLE 0x0012
62 #define INDICATION_PAYLOAD "indication"
63 #define NOTIFICATION_PAYLOAD "notification"
64