1 /* main.c - Application main entry point */
2
3 /*
4 * Copyright (c) 2015-2016 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include <stddef.h>
10
11 #include <zephyr/kernel.h>
12
13 #include <zephyr/sys/printk.h>
14 #include <zephyr/sys/util.h>
15
16 #include "bs_types.h"
17 #include "bs_tracing.h"
18 #include "time_machine.h"
19 #include "bstests.h"
20
21 /* The test case is performing 250 simultaneous connections and managing
22 * parallel control procedures utilizing the available/configured minimum
23 * buffer counts. Hence, two iterations of connect-disconnect should be
24 * sufficient to catch any regressions/buffer leaks.
25 */
26 #define ITERATIONS 2
27
28 int init_central(uint8_t max_conn, uint8_t iterations);
29 int init_peripheral(uint8_t max_conn, uint8_t iterations);
30
31 #define FAIL(...) \
32 do { \
33 bst_result = Failed; \
34 bs_trace_error_time_line(__VA_ARGS__); \
35 } while (0)
36
37 #define PASS(...) \
38 do { \
39 bst_result = Passed; \
40 bs_trace_info_time(1, __VA_ARGS__); \
41 } while (0)
42
43 extern enum bst_result_t bst_result;
44
test_central_main(void)45 static void test_central_main(void)
46 {
47 int err;
48
49 err = init_central(CONFIG_BT_MAX_CONN, ITERATIONS);
50 if (err) {
51 goto exit;
52 }
53
54 /* Wait a little so that peripheral side completes the last
55 * connection establishment.
56 */
57 k_sleep(K_SECONDS(1));
58
59 PASS("Central tests passed\n");
60 bs_trace_silent_exit(0);
61
62 return;
63
64 exit:
65 FAIL("Central tests failed (%d)\n", err);
66 bs_trace_silent_exit(0);
67 }
68
test_peripheral_main(void)69 static void test_peripheral_main(void)
70 {
71 int err;
72
73 err = init_peripheral(CONFIG_BT_MAX_CONN, ITERATIONS);
74 if (err) {
75 goto exit;
76 }
77
78 PASS("Peripheral tests passed\n");
79
80 return;
81
82 exit:
83 FAIL("Peripheral tests failed (%d)\n", err);
84 bs_trace_silent_exit(0);
85 }
86
test_central_multiple_main(void)87 static void test_central_multiple_main(void)
88 {
89 int err;
90
91 err = init_central(20U, ITERATIONS);
92 if (err) {
93 goto exit;
94 }
95
96 /* Wait a little so that peripheral side completes the last
97 * connection establishment.
98 */
99 k_sleep(K_SECONDS(1));
100
101 PASS("Central tests passed\n");
102 bs_trace_silent_exit(0);
103
104 return;
105
106 exit:
107 FAIL("Central tests failed (%d)\n", err);
108 bs_trace_silent_exit(0);
109 }
110
test_peripheral_single_main(void)111 static void test_peripheral_single_main(void)
112 {
113 int err;
114
115 err = init_peripheral(1U, ITERATIONS);
116 if (err) {
117 goto exit;
118 }
119
120 PASS("Peripheral tests passed\n");
121
122 return;
123
124 exit:
125 FAIL("Peripheral tests failed (%d)\n", err);
126 bs_trace_silent_exit(0);
127 }
128
test_central_single_main(void)129 static void test_central_single_main(void)
130 {
131 int err;
132
133 err = init_central(1U, ITERATIONS);
134 if (err) {
135 goto exit;
136 }
137
138 PASS("Central tests passed\n");
139
140 return;
141
142 exit:
143 FAIL("Central tests failed (%d)\n", err);
144 bs_trace_silent_exit(0);
145 }
146
test_peripheral_multilink_main(void)147 static void test_peripheral_multilink_main(void)
148 {
149 int err;
150
151 err = init_peripheral(20U, ITERATIONS);
152 if (err) {
153 goto exit;
154 }
155
156 k_sleep(K_SECONDS(3));
157
158 PASS("Peripheral tests passed\n");
159 bs_trace_silent_exit(0);
160
161 return;
162
163 exit:
164 FAIL("Peripheral tests failed (%d)\n", err);
165 bs_trace_silent_exit(0);
166 }
167
test_multiple_init(void)168 static void test_multiple_init(void)
169 {
170 bst_ticker_set_next_tick_absolute(1500e6);
171 bst_result = In_progress;
172 }
173
test_multiple_tick(bs_time_t HW_device_time)174 static void test_multiple_tick(bs_time_t HW_device_time)
175 {
176 bst_result = Failed;
177 bs_trace_error_line("Test multiple finished.\n");
178 }
179
180 static const struct bst_test_instance test_def[] = {
181 {
182 .test_id = "central",
183 .test_descr = "Central Multilink",
184 .test_pre_init_f = test_multiple_init,
185 .test_tick_f = test_multiple_tick,
186 .test_main_f = test_central_main
187 },
188 {
189 .test_id = "peripheral",
190 .test_descr = "Peripheral multiple identity",
191 .test_pre_init_f = test_multiple_init,
192 .test_tick_f = test_multiple_tick,
193 .test_main_f = test_peripheral_main
194 },
195 {
196 .test_id = "central_multiple",
197 .test_descr = "Single Central Multilink device",
198 .test_pre_init_f = test_multiple_init,
199 .test_tick_f = test_multiple_tick,
200 .test_main_f = test_central_multiple_main
201 },
202 {
203 .test_id = "peripheral_single",
204 .test_descr = "Many Peripheral single link device",
205 .test_pre_init_f = test_multiple_init,
206 .test_tick_f = test_multiple_tick,
207 .test_main_f = test_peripheral_single_main
208 },
209 {
210 .test_id = "central_single",
211 .test_descr = "Single Central device",
212 .test_pre_init_f = test_multiple_init,
213 .test_tick_f = test_multiple_tick,
214 .test_main_f = test_central_single_main
215 },
216 {
217 .test_id = "peripheral_multilink",
218 .test_descr = "Peripheral multilink device",
219 .test_pre_init_f = test_multiple_init,
220 .test_tick_f = test_multiple_tick,
221 .test_main_f = test_peripheral_multilink_main
222 },
223 BSTEST_END_MARKER
224 };
225
test_multiple_install(struct bst_test_list * tests)226 struct bst_test_list *test_multiple_install(struct bst_test_list *tests)
227 {
228 return bst_add_tests(tests, test_def);
229 }
230
231 bst_test_install_t test_installers[] = {
232 test_multiple_install,
233 NULL
234 };
235
main(void)236 int main(void)
237 {
238 bst_main();
239 return 0;
240 }
241