shell: Add test for custom shell macros
Verify customized shell macro APIs Signed-off-by: Al Semjonovs <asemjonovs@google.com>
This commit is contained in:
parent
0bca04635d
commit
023248a1f3
5 changed files with 103 additions and 0 deletions
10
tests/subsys/shell/shell_custom_header/CMakeLists.txt
Normal file
10
tests/subsys/shell/shell_custom_header/CMakeLists.txt
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.20.0)
|
||||||
|
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||||
|
project(shell_custom_header)
|
||||||
|
|
||||||
|
FILE(GLOB app_sources src/*.c)
|
||||||
|
target_sources(app PRIVATE ${app_sources})
|
||||||
|
|
||||||
|
zephyr_include_directories(src)
|
11
tests/subsys/shell/shell_custom_header/prj.conf
Normal file
11
tests/subsys/shell/shell_custom_header/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
CONFIG_SHELL=y
|
||||||
|
CONFIG_SHELL_BACKEND_SERIAL=n
|
||||||
|
CONFIG_SHELL_BACKEND_DUMMY=y
|
||||||
|
CONFIG_SHELL_CMDS_SELECT=y
|
||||||
|
CONFIG_SHELL_CMD_BUFF_SIZE=90
|
||||||
|
CONFIG_SHELL_PRINTF_BUFF_SIZE=15
|
||||||
|
CONFIG_SHELL_METAKEYS=n
|
||||||
|
CONFIG_SHELL_CUSTOM_HEADER=y
|
||||||
|
CONFIG_LOG=n
|
||||||
|
CONFIG_ZTEST=y
|
||||||
|
CONFIG_TEST_LOGGING_DEFAULTS=n
|
56
tests/subsys/shell/shell_custom_header/src/main.c
Normal file
56
tests/subsys/shell/shell_custom_header/src/main.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Google, Inc.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Custom header shell test suite
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
#include <zephyr/shell/shell.h>
|
||||||
|
#include <zephyr/shell/shell_dummy.h>
|
||||||
|
|
||||||
|
static void *shell_setup(void)
|
||||||
|
{
|
||||||
|
const struct shell *sh = shell_backend_dummy_get_ptr();
|
||||||
|
|
||||||
|
/* Wait for the initialization of the shell dummy backend. */
|
||||||
|
WAIT_FOR(shell_ready(sh), 20000, k_msleep(1));
|
||||||
|
zassert_true(shell_ready(sh), "timed out waiting for dummy shell backend");
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(sh, NULL, shell_setup, NULL, NULL, NULL);
|
||||||
|
|
||||||
|
ZTEST(sh, test_shell_fprintf)
|
||||||
|
{
|
||||||
|
static const char expect[] = "[CUSTOM_PREFIX]testing 1 2 3";
|
||||||
|
const struct shell *sh;
|
||||||
|
const char *buf;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
sh = shell_backend_dummy_get_ptr();
|
||||||
|
zassert_not_null(sh, "Failed to get shell");
|
||||||
|
|
||||||
|
/* Clear the output buffer */
|
||||||
|
shell_backend_dummy_clear_output(sh);
|
||||||
|
|
||||||
|
shell_fprintf(sh, SHELL_VT100_COLOR_DEFAULT, "testing %d %s %c",
|
||||||
|
1, "2", '3');
|
||||||
|
buf = shell_backend_dummy_get_output(sh, &size);
|
||||||
|
zassert_true(size >= sizeof(expect), "Expected size > %u, got %d",
|
||||||
|
sizeof(expect), size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There are prompts and various ANSI characters in the output, so just
|
||||||
|
* check that the string is in there somewhere.
|
||||||
|
*/
|
||||||
|
zassert_true(strstr(buf, expect),
|
||||||
|
"Expected string to contain '%s', got '%s'", expect, buf);
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Google, Inc.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ZEPHYR_CUSTOM_SHELL_H
|
||||||
|
#define __ZEPHYR_CUSTOM_SHELL_H
|
||||||
|
|
||||||
|
#define CUSTOM_SHELL_PREFIX "[CUSTOM_PREFIX]"
|
||||||
|
|
||||||
|
#undef shell_fprintf
|
||||||
|
|
||||||
|
#define shell_fprintf(sh, color, fmt, ...) \
|
||||||
|
shell_fprintf_impl(sh, color, CUSTOM_SHELL_PREFIX fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#endif /* __ZEPHYR_CUSTOM_SHELL_H */
|
9
tests/subsys/shell/shell_custom_header/testcase.yaml
Normal file
9
tests/subsys/shell/shell_custom_header/testcase.yaml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
common:
|
||||||
|
integration_platforms:
|
||||||
|
- native_sim
|
||||||
|
|
||||||
|
tests:
|
||||||
|
shell.shell_custom_header:
|
||||||
|
tags:
|
||||||
|
- shell_custom_header
|
||||||
|
- shell
|
Loading…
Add table
Add a link
Reference in a new issue