Files
arcs/arcs-sdk/test/components/simple_box/mock_shell/mock_shell.c
2026-08-13 16:50:52 +08:00

55 lines
969 B
C

/**
* Copyright (c) 2025, LISTENAI
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "mock_shell.h"
#include "shell.h"
static Shell shell;
static char shellBuffer[512];
static char logBuffer[1024];
static char log_buf_index = 0;
extern unsigned int shellRunCommand(Shell *shell, ShellCommand *command);
signed short userShellWrite(char *data, unsigned short len)
{
unsigned short length = len;
signed short copied = 0;
while (length--)
{
copied++;
logBuffer[log_buf_index++] = *data++;
}
return copied;
}
void mock_shell_init(void)
{
shell.read = NULL;
shell.write = userShellWrite;
shellInit(&shell, shellBuffer, 512);
}
int mock_shell_run(const char *cmd)
{
return shellRun(&shell, cmd);
}
void mock_shell_reset(void)
{
log_buf_index = 0;
memset(logBuffer, 0, sizeof(logBuffer));
}
char *mock_shell_get_log_buf(size_t *log_size)
{
*log_size = log_buf_index;
return logBuffer;
}