1 /*
2  * Common functions and helpers for ISO tests
3  *
4  * Copyright (c) 2023 Nordic Semiconductor ASA
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include <stddef.h>
10 
11 #include <zephyr/sys/atomic.h>
12 
13 #include "bs_types.h"
14 #include "bs_tracing.h"
15 #include "bstests.h"
16 
17 #define CREATE_FLAG(flag) static 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 #define TEST_FLAG(flag)   (atomic_get(&flag) == (atomic_t) true)
21 #define WAIT_FOR_FLAG_SET(flag)                                                                    \
22 	while (!(bool)atomic_get(&flag)) {                                                         \
23 		(void)k_sleep(K_MSEC(1));                                                          \
24 	}
25 #define WAIT_FOR_FLAG_UNSET(flag)                                                                  \
26 	while ((bool)atomic_get(&flag)) {                                                          \
27 		(void)k_sleep(K_MSEC(1));                                                          \
28 	}
29 
30 #define WAIT_TIME (30e6) /* 30 seconds*/
31 
32 #define FAIL(...)                                                                                  \
33 	do {                                                                                       \
34 		bst_result = Failed;                                                               \
35 		bs_trace_error_time_line(__VA_ARGS__);                                             \
36 	} while (0)
37 
38 #define PASS(...)                                                                                  \
39 	do {                                                                                       \
40 		bst_result = Passed;                                                               \
41 		bs_trace_info_time(1, __VA_ARGS__);                                                \
42 	} while (0)
43 
44 extern struct bt_conn *default_conn;
45 extern atomic_t flag_connected;
46 extern atomic_t flag_conn_updated;
47 
48 void test_init(void);
49 void test_tick(bs_time_t HW_device_time);
50