1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "bstests.h"
8 #include "bs_bt_utils.h"
9 
10 #define BS_SECONDS_TO_US(dur_sec)    ((bs_time_t)dur_sec * USEC_PER_SEC)
11 #define TEST_TIMEOUT_SIMULATED BS_SECONDS_TO_US(60)
12 
13 extern void central(void);
14 extern void peripheral(void);
15 
test_tick(bs_time_t HW_device_time)16 static void test_tick(bs_time_t HW_device_time)
17 {
18 	bs_trace_debug_time(0, "Simulation ends now.\n");
19 	if (bst_result != Passed) {
20 		bst_result = Failed;
21 		bs_trace_error("Test did not pass before simulation ended.\n");
22 	}
23 }
24 
test_init(void)25 static void test_init(void)
26 {
27 	bst_ticker_set_next_tick_absolute(TEST_TIMEOUT_SIMULATED);
28 	bst_result = In_progress;
29 }
30 
31 static const struct bst_test_instance test_to_add[] = {
32 	{
33 		.test_id = "central",
34 		.test_pre_init_f = test_init,
35 		.test_tick_f = test_tick,
36 		.test_main_f = central,
37 	},
38 	{
39 		.test_id = "peripheral",
40 		.test_pre_init_f = test_init,
41 		.test_tick_f = test_tick,
42 		.test_main_f = peripheral,
43 	},
44 	BSTEST_END_MARKER,
45 };
46 
install(struct bst_test_list * tests)47 static struct bst_test_list *install(struct bst_test_list *tests)
48 {
49 	return bst_add_tests(tests, test_to_add);
50 };
51 
52 bst_test_install_t test_installers[] = {install, NULL};
53 
main(void)54 int main(void)
55 {
56 	bst_main();
57 	return 0;
58 }
59