1 /*
2  * Copyright (c) 2019 - 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stddef.h>
7 
8 #include <zephyr/autoconf.h>
9 #include <zephyr/bluetooth/audio/media_proxy.h>
10 #include <zephyr/bluetooth/bluetooth.h>
11 #include <zephyr/sys/printk.h>
12 
13 #include "bstests.h"
14 #include "common.h"
15 
16 #ifdef CONFIG_BT_MCS
17 extern enum bst_result_t bst_result;
18 
test_main(void)19 static void test_main(void)
20 {
21 	struct bt_le_ext_adv *ext_adv;
22 	int err;
23 
24 	printk("Media Control Server test application.  Board: %s\n", CONFIG_BOARD);
25 
26 	/* Initialize media player */
27 	err = media_proxy_pl_init();
28 	if (err) {
29 		FAIL("Initializing MPL failed (err %d)", err);
30 		return;
31 	}
32 
33 	/* Initialize Bluetooth, get connected */
34 	err = bt_enable(NULL);
35 	if (err) {
36 		FAIL("Bluetooth init failed (err %d)\n", err);
37 		return;
38 	}
39 	printk("Bluetooth initialized\n");
40 
41 	setup_connectable_adv(&ext_adv);
42 
43 	PASS("MCS passed\n");
44 
45 	while (1) {
46 		WAIT_FOR_FLAG(flag_connected);
47 		WAIT_FOR_UNSET_FLAG(flag_connected);
48 
49 		err = bt_le_ext_adv_start(ext_adv, BT_LE_EXT_ADV_START_DEFAULT);
50 		if (err != 0) {
51 			FAIL("Failed to start advertising set (err %d)\n", err);
52 
53 			bt_le_ext_adv_delete(ext_adv);
54 
55 			return;
56 		}
57 	}
58 }
59 
60 static const struct bst_test_instance test_mcs[] = {
61 	{
62 		.test_id = "mcs",
63 		.test_pre_init_f = test_init,
64 		.test_tick_f = test_tick,
65 		.test_main_f = test_main
66 	},
67 	BSTEST_END_MARKER
68 };
69 
test_mcs_install(struct bst_test_list * tests)70 struct bst_test_list *test_mcs_install(struct bst_test_list *tests)
71 {
72 	return bst_add_tests(tests, test_mcs);
73 }
74 
75 #else
76 
test_mcs_install(struct bst_test_list * tests)77 struct bst_test_list *test_mcs_install(struct bst_test_list *tests)
78 {
79 	return tests;
80 }
81 
82 #endif /* CONFIG_BT_MCS */
83