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 "babblekit/testcase.h"
10 #include "babblekit/sync.h"
11 #include "common.h"
12
test_peripheral_main(void)13 static void test_peripheral_main(void)
14 {
15 int err;
16
17 TEST_ASSERT(bk_sync_init() == 0, "Failed to open backchannel");
18
19 peripheral_setup_and_connect();
20
21 /*
22 * we need to sync with peer to ensure that we get collisions
23 */
24 bk_sync_send();
25 bk_sync_wait();
26
27 err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX);
28 if (err) {
29 TEST_FAIL("Sending credit based connection request failed (err %d)", err);
30 }
31
32 while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) {
33 k_sleep(K_MSEC(10));
34 }
35
36 /* Do not disconnect until the central also has connected all channels */
37 k_sleep(K_MSEC(1000));
38
39 disconnect();
40
41 TEST_PASS("EATT Peripheral tests Passed");
42 }
43
test_central_main(void)44 static void test_central_main(void)
45 {
46 int err;
47
48 TEST_ASSERT(bk_sync_init() == 0, "Failed to open backchannel");
49
50 central_setup_and_connect();
51
52 bk_sync_wait();
53 bk_sync_send();
54
55 err = bt_eatt_connect(default_conn, CONFIG_BT_EATT_MAX);
56 if (err) {
57 TEST_FAIL("Sending credit based connection request failed (err %d)", err);
58 }
59
60 while (bt_eatt_count(default_conn) < CONFIG_BT_EATT_MAX) {
61 k_sleep(K_MSEC(10));
62 }
63
64 wait_for_disconnect();
65
66 TEST_PASS("EATT Central tests Passed");
67 }
68
69 static const struct bst_test_instance test_def[] = {
70 {
71 .test_id = "peripheral",
72 .test_descr = "Peripheral Collision",
73 .test_main_f = test_peripheral_main,
74 },
75 {
76 .test_id = "central",
77 .test_descr = "Central Collision",
78 .test_main_f = test_central_main,
79 },
80 BSTEST_END_MARKER,
81 };
82
test_main_collision_install(struct bst_test_list * tests)83 struct bst_test_list *test_main_collision_install(struct bst_test_list *tests)
84 {
85 return bst_add_tests(tests, test_def);
86 }
87