1 /**
2  * Copyright (c) 2024 Croxel, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_
8 #define ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_
9 
10 #include <zephyr/kernel.h>
11 
12 #include "bs_types.h"
13 #include "bs_tracing.h"
14 #include "time_machine.h"
15 #include "bstests.h"
16 
17 #define WAIT_SECONDS 30                         /* seconds */
18 #define WAIT_TIME (WAIT_SECONDS * USEC_PER_SEC) /* microseconds*/
19 
20 #define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
21 #define SET_FLAG(flag)	   (void)atomic_set(&flag, (atomic_t) true)
22 #define TEST_FLAG(flag)    (atomic_get(&flag) == (atomic_t)true)
23 #define UNSET_FLAG(flag)   (void)atomic_set(&flag, (atomic_t) false)
24 #define WAIT_FOR_FLAG(flag)                                                                        \
25 	while (!(bool)atomic_get(&flag)) {                                                         \
26 		(void)k_sleep(K_MSEC(1));                                                          \
27 	}
28 #define WAIT_FOR_FLAG_UNSET(flag)                                                                  \
29 	while ((bool)atomic_get(&flag)) {                                                          \
30 		(void)k_sleep(K_MSEC(1));                                                          \
31 	}
32 #define TAKE_FLAG(flag)                                                                            \
33 	while (!(bool)atomic_cas(&flag, true, false)) {                                            \
34 		(void)k_sleep(K_MSEC(1));                                                          \
35 	}
36 
37 
38 #define FAIL(...) \
39 	do { \
40 		bst_result = Failed; \
41 		bs_trace_error_time_line(__VA_ARGS__); \
42 	} while (0)
43 
44 #define PASS(...) \
45 	do { \
46 		bst_result = Passed; \
47 		bs_trace_info_time(1, "PASSED: " __VA_ARGS__); \
48 	} while (0)
49 
50 void test_tick(bs_time_t HW_device_time);
51 void test_init(void);
52 
53 #endif /* ZEPHYR_TEST_BSIM_BT_EXT_ADV_TEST_ */
54