1 /*
2  * Copyright (c) 2023 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/shell/shell.h>
9 #include "iut.h"
10 #include <zephyr/shell/shell_uart.h>
11 
12 extern int iut_trigger(size_t argc, char **argv);
13 
cmd_iut_list(const struct shell * shell,size_t argc,char ** argv)14 static int cmd_iut_list(const struct shell *shell,
15 			      size_t argc, char **argv)
16 {
17 	const struct iut_case *ut = (void *)__iut_cases_start;
18 
19 	ARG_UNUSED(argc);
20 	ARG_UNUSED(argv);
21 
22 	shell_fprintf(shell, SHELL_NORMAL, "IUT test cases:\n");
23 	while ((char *)ut < __iut_cases_end) {
24 		shell_fprintf(shell, SHELL_NORMAL, "\t- %s, %s, 0x%x\n",
25 				ut->group, ut->name, ut->attri);
26 		ut++;
27 	};
28 
29 	return 0;
30 }
31 
cmd_iut_run(const struct shell * shell,size_t argc,char ** argv)32 static int cmd_iut_run(const struct shell *shell,
33 			      size_t argc, char **argv)
34 {
35 	if (argc < 2)
36 		return -EPERM;
37 
38 	return iut_trigger(argc, argv);
39 }
40 
cmd_iut_grun(const struct shell * shell,size_t argc,char ** argv)41 static int cmd_iut_grun(const struct shell *shell,
42 			      size_t argc, char **argv)
43 {
44 	if (argc < 2)
45 		return -EPERM;
46 
47 	return iut_trigger(argc, argv);
48 }
49 
50 SHELL_STATIC_SUBCMD_SET_CREATE(sub_iut,
51 	SHELL_CMD(list, NULL, "List unit cases", cmd_iut_list),
52 	SHELL_CMD(run, NULL, "run one unit case", cmd_iut_run),
53 	SHELL_CMD(grun, NULL, "run one group of unit cases", cmd_iut_grun),
54 	SHELL_SUBCMD_SET_END /* Array terminated. */
55 );
56 
57 SHELL_CMD_REGISTER(iut, &sub_iut, "IUT commands", NULL);
58 
59 #ifdef CONFIG_PM
60 static const struct shell_uart *sh_uart;
61 
iut_shell_suspend(void)62 void iut_shell_suspend(void)
63 {
64 	if (!sh_uart) {
65 		/*get current uart shell pointer*/
66 		const struct shell *shell_ptr = shell_backend_uart_get_ptr();
67 
68 		if (shell_ptr == NULL) {
69 			iut_print("get shell pointer error!!!\n");
70 			return;
71 		}
72 
73 		/*get shell uart backend*/
74 		sh_uart = (const struct shell_uart *)shell_ptr->iface->ctx;
75 
76 		if (sh_uart == NULL) {
77 			iut_print("get shell UART pointer error!!!\n");
78 			return;
79 		}
80 	}
81 
82 	k_timer_stop(sh_uart->timer);
83 }
84 
iut_shell_resume(void)85 void iut_shell_resume(void)
86 {
87 	if (sh_uart) {
88 		k_timer_start(sh_uart->timer, K_NO_WAIT,
89 			K_MSEC(CONFIG_SHELL_BACKEND_SERIAL_RX_POLL_PERIOD));
90 	}
91 }
92 #endif
93