1 /* main_collision.c - Application main entry point */
2 
3 /*
4  * Copyright (c) 2022 Nordic Semiconductor
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #include "common.h"
10 
test_peripheral_main(void)11 static void test_peripheral_main(void)
12 {
13 	int err;
14 
15 	backchannel_init();
16 
17 	peripheral_setup_and_connect();
18 
19 	/*
20 	 * we need to sync with peer to ensure that we get collisions
21 	 */
22 	backchannel_sync_send();
23 	backchannel_sync_wait();
24 
25 	err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX);
26 	if (err) {
27 		FAIL("Sending credit based connection request failed (err %d)\n", err);
28 	}
29 
30 	while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) {
31 		k_sleep(K_MSEC(10));
32 	}
33 
34 	/* Do not disconnect until the central also has connected all channels */
35 	k_sleep(K_MSEC(1000));
36 
37 	disconnect();
38 
39 	PASS("EATT Peripheral tests Passed\n");
40 }
41 
test_central_main(void)42 static void test_central_main(void)
43 {
44 	int err;
45 
46 	backchannel_init();
47 
48 	central_setup_and_connect();
49 
50 	backchannel_sync_wait();
51 	backchannel_sync_send();
52 
53 	err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX);
54 	if (err) {
55 		FAIL("Sending credit based connection request failed (err %d)\n", err);
56 	}
57 
58 	while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) {
59 		k_sleep(K_MSEC(10));
60 	}
61 
62 	wait_for_disconnect();
63 
64 	PASS("EATT Central tests Passed\n");
65 }
66 
67 static const struct bst_test_instance test_def[] = {
68 	{
69 		.test_id = "peripheral",
70 		.test_descr = "Peripheral Collision",
71 		.test_pre_init_f = test_init,
72 		.test_tick_f = test_tick,
73 		.test_main_f = test_peripheral_main,
74 	},
75 	{
76 		.test_id = "central",
77 		.test_descr = "Central Collision",
78 		.test_pre_init_f = test_init,
79 		.test_tick_f = test_tick,
80 		.test_main_f = test_central_main,
81 	},
82 	BSTEST_END_MARKER,
83 };
84 
test_main_collision_install(struct bst_test_list * tests)85 struct bst_test_list *test_main_collision_install(struct bst_test_list *tests)
86 {
87 	return bst_add_tests(tests, test_def);
88 }
89