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 
start_adv(void)19 static void start_adv(void)
20 {
21 	int err;
22 
23 	err = bt_le_adv_start(BT_LE_ADV_CONN_FAST_1, ad, AD_SIZE, NULL, 0);
24 	if (err) {
25 		FAIL("Advertising failed to start (err %d)\n", err);
26 		return;
27 	}
28 
29 	printk("Advertising successfully started\n");
30 }
31 
test_main(void)32 static void test_main(void)
33 {
34 	int err;
35 
36 	printk("Media Control Server test application.  Board: %s\n", CONFIG_BOARD);
37 
38 	/* Initialize media player */
39 	err = media_proxy_pl_init();
40 	if (err) {
41 		FAIL("Initializing MPL failed (err %d)", err);
42 		return;
43 	}
44 
45 	/* Initialize Bluetooth, get connected */
46 	err = bt_enable(NULL);
47 	if (err) {
48 		FAIL("Bluetooth init failed (err %d)\n", err);
49 		return;
50 	}
51 	printk("Bluetooth initialized\n");
52 
53 	PASS("MCS passed\n");
54 
55 	while (1) {
56 		start_adv();
57 		WAIT_FOR_FLAG(flag_connected);
58 		WAIT_FOR_UNSET_FLAG(flag_connected);
59 	}
60 }
61 
62 static const struct bst_test_instance test_mcs[] = {
63 	{
64 		.test_id = "mcs",
65 		.test_pre_init_f = test_init,
66 		.test_tick_f = test_tick,
67 		.test_main_f = test_main
68 	},
69 	BSTEST_END_MARKER
70 };
71 
test_mcs_install(struct bst_test_list * tests)72 struct bst_test_list *test_mcs_install(struct bst_test_list *tests)
73 {
74 	return bst_add_tests(tests, test_mcs);
75 }
76 
77 #else
78 
test_mcs_install(struct bst_test_list * tests)79 struct bst_test_list *test_mcs_install(struct bst_test_list *tests)
80 {
81 	return tests;
82 }
83 
84 #endif /* CONFIG_BT_MCS */
85