1 /*
2  * Copyright (c) 2024 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <inttypes.h>
8 #include <stddef.h>
9 #include <stdint.h>
10 
11 #include "bs_types.h"
12 #include "bs_tracing.h"
13 #include "bs_utils.h"
14 #include "bstests.h"
15 
16 #define WAIT_TIME 10 /* Seconds */
17 
18 extern enum bst_result_t bst_result;
19 
20 #define FAIL(...)                                                                                  \
21 	do {                                                                                       \
22 		bst_result = Failed;                                                               \
23 		bs_trace_error_time_line(__VA_ARGS__);                                             \
24 	} while (0)
25 
26 #define PASS(...)                                                                                  \
27 	do {                                                                                       \
28 		bst_result = Passed;                                                               \
29 		bs_trace_info_time(1, __VA_ARGS__);                                                \
30 	} while (0)
31 
test_ccp_call_control_client_sample_init(void)32 static void test_ccp_call_control_client_sample_init(void)
33 {
34 	bst_ticker_set_next_tick_absolute(WAIT_TIME * 1e6);
35 	bst_result = In_progress;
36 }
37 
test_ccp_call_control_client_sample_tick(bs_time_t HW_device_time)38 static void test_ccp_call_control_client_sample_tick(bs_time_t HW_device_time)
39 {
40 	extern struct bt_ccp_call_control_client *client;
41 
42 	/* If discovery was a success then client is non-NULL - Use as pass criteria */
43 	if (client == NULL) {
44 		FAIL("CCP Call Control Client sample FAILED (Did not pass after %i seconds)\n",
45 		     WAIT_TIME);
46 	} else {
47 		PASS("CCP Call Control Client sample PASSED\n");
48 	}
49 }
50 
51 static const struct bst_test_instance test_sample[] = {
52 	{
53 		.test_id = "ccp_call_control_client",
54 		.test_descr = "Test based on the CCP Call Control Client sample. "
55 			      "It expects to be connected to a compatible CCP server, "
56 			      "waits for " STR(WAIT_TIME) " seconds, and checks how "
57 			      "many audio packets have been received correctly",
58 		.test_post_init_f = test_ccp_call_control_client_sample_init,
59 		.test_tick_f = test_ccp_call_control_client_sample_tick,
60 	},
61 	BSTEST_END_MARKER,
62 };
63 
64 static struct bst_test_list *
test_ccp_call_control_client_sample_install(struct bst_test_list * tests)65 test_ccp_call_control_client_sample_install(struct bst_test_list *tests)
66 {
67 	tests = bst_add_tests(tests, test_sample);
68 	return tests;
69 }
70 
71 bst_test_install_t test_installers[] = {test_ccp_call_control_client_sample_install, NULL};
72