1 /*
2  * Copyright 2023 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stddef.h>
7 
8 #include <zephyr/autoconf.h>
9 #include <zephyr/bluetooth/audio/bap.h>
10 #include <zephyr/bluetooth/audio/tmap.h>
11 #include <zephyr/bluetooth/bluetooth.h>
12 #include <zephyr/bluetooth/gap.h>
13 #include <zephyr/bluetooth/hci.h>
14 #include <zephyr/bluetooth/conn.h>
15 #include <zephyr/bluetooth/uuid.h>
16 #include <zephyr/bluetooth/gatt.h>
17 #include <zephyr/sys/printk.h>
18 #include <zephyr/sys/util.h>
19 #include <zephyr/types.h>
20 
21 #include "bstests.h"
22 #include "common.h"
23 
24 #ifdef CONFIG_BT_TMAP
25 extern enum bst_result_t bst_result;
26 
test_main(void)27 static void test_main(void)
28 {
29 	int err;
30 	struct bt_le_ext_adv *ext_adv;
31 
32 	err = bt_enable(NULL);
33 	if (err != 0) {
34 		FAIL("Bluetooth init failed (err %d)\n", err);
35 		return;
36 	}
37 
38 	printk("Bluetooth initialized\n");
39 	/* Initialize TMAP */
40 	err = bt_tmap_register(TMAP_ROLE_SUPPORTED);
41 	if (err != 0) {
42 		FAIL("Failed to register TMAP (err %d)\n", err);
43 		return;
44 	}
45 	printk("TMAP initialized. Start advertising...\n");
46 	setup_connectable_adv(&ext_adv);
47 
48 	WAIT_FOR_FLAG(flag_connected);
49 	printk("Connected!\n");
50 
51 	PASS("TMAP test passed\n");
52 }
53 
54 static const struct bst_test_instance test_tmas[] = {
55 	{
56 		.test_id = "tmap_server",
57 		.test_pre_init_f = test_init,
58 		.test_tick_f = test_tick,
59 		.test_main_f = test_main,
60 
61 	},
62 	BSTEST_END_MARKER
63 };
64 
test_tmap_server_install(struct bst_test_list * tests)65 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
66 {
67 	return bst_add_tests(tests, test_tmas);
68 }
69 #else
test_tmap_server_install(struct bst_test_list * tests)70 struct bst_test_list *test_tmap_server_install(struct bst_test_list *tests)
71 {
72 	return tests;
73 }
74 #endif /* CONFIG_BT_TMAP */
75