1 /* Copyright (c) 2023 Nordic Semiconductor ASA
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5 #include <zephyr/kernel.h>
6
7 #include "bs_types.h"
8 #include "bs_tracing.h"
9 #include "bstests.h"
10 #include <string.h>
11
12 #include <zephyr/logging/log.h>
13
14 LOG_MODULE_REGISTER(bt_bsim_ccc_update, LOG_LEVEL_DBG);
15
16 #define FAIL(...) \
17 do { \
18 bst_result = Failed; \
19 bs_trace_error_time_line(__VA_ARGS__); \
20 } while (0)
21
22 #define PASS(...) \
23 do { \
24 bst_result = Passed; \
25 bs_trace_info_time(1, __VA_ARGS__); \
26 } while (0)
27
28 extern enum bst_result_t bst_result;
29
30 #define WAIT_TIME_S 60
31 #define WAIT_TIME (WAIT_TIME_S * 1e6)
32
33 extern void run_peripheral(void);
34 extern void run_central(void);
35 extern void run_bad_central(void);
36
central_main(void)37 static void central_main(void)
38 {
39 run_central();
40 }
41
bad_central_main(void)42 static void bad_central_main(void)
43 {
44 run_bad_central();
45 }
46
peripheral_main(void)47 static void peripheral_main(void)
48 {
49 run_peripheral();
50 }
51
test_tick(bs_time_t HW_device_time)52 void test_tick(bs_time_t HW_device_time)
53 {
54 if (bst_result != Passed) {
55 bst_result = Failed;
56 bs_trace_error_time_line("Test failed (not passed after %d seconds)\n",
57 WAIT_TIME_S);
58 }
59 }
60
test_ccc_update_init(void)61 static void test_ccc_update_init(void)
62 {
63 bst_ticker_set_next_tick_absolute(WAIT_TIME);
64 }
65
66 static const struct bst_test_instance test_def[] = {
67 {
68 .test_id = "central",
69 .test_descr = "Central device",
70 .test_pre_init_f = test_ccc_update_init,
71 .test_tick_f = test_tick,
72 .test_main_f = central_main,
73 },
74 {
75 .test_id = "bad_central",
76 .test_descr = "Bad Central device",
77 .test_pre_init_f = test_ccc_update_init,
78 .test_tick_f = test_tick,
79 .test_main_f = bad_central_main,
80 },
81 {
82 .test_id = "peripheral",
83 .test_descr = "Peripheral device",
84 .test_pre_init_f = test_ccc_update_init,
85 .test_tick_f = test_tick,
86 .test_main_f = peripheral_main,
87 },
88 BSTEST_END_MARKER};
89
test_ccc_update_install(struct bst_test_list * tests)90 struct bst_test_list *test_ccc_update_install(struct bst_test_list *tests)
91 {
92 return bst_add_tests(tests, test_def);
93 }
94
95 bst_test_install_t test_installers[] = {test_ccc_update_install, NULL};
96
main(void)97 int main(void)
98 {
99 bst_main();
100 return 0;
101 }
102