1 /*
2 * Copyright 2023 Meta
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/kernel.h>
8 #include <zephyr/ztest.h>
9
10 #include <zephyr/shell/shell.h>
11 #include <zephyr/shell/shell_backend.h>
12 #include <zephyr/shell/shell_dummy.h>
13 #include <zephyr/shell/shell_uart.h>
14
ZTEST(shell_backend,test_backend_apis)15 ZTEST(shell_backend, test_backend_apis)
16 {
17 const struct shell *sh_dummy = shell_backend_get_by_name("shell_dummy");
18 const struct shell *sh_uart = shell_backend_get_by_name("shell_uart");
19
20 zassert_equal(shell_backend_count_get(), 2, "Expecting 2, got %d",
21 shell_backend_count_get());
22
23 zassert_equal_ptr(sh_dummy, shell_backend_dummy_get_ptr(),
24 "Unexpected shell_dummy backend");
25 zassert_equal_ptr(sh_uart, shell_backend_uart_get_ptr(), "Unexpected shell_uart backend");
26 zassert_equal_ptr(shell_backend_get_by_name("blah"), NULL, "Should be NULL if not found");
27
28 zassert_equal_ptr(shell_backend_get(0), sh_dummy < sh_uart ? sh_dummy : sh_uart,
29 "Unexpected backend at index 0");
30 zassert_equal_ptr(shell_backend_get(1), sh_dummy < sh_uart ? sh_uart : sh_dummy,
31 "Unexpected backend at index 1");
32 }
33
shell_setup(void)34 static void *shell_setup(void)
35 {
36 /* Let the shell backend initialize. */
37 k_usleep(10);
38 return NULL;
39 }
40
41 ZTEST_SUITE(shell_backend, NULL, shell_setup, NULL, NULL, NULL);
42