subsys: shell: add dummy backend to simplify commands testing

Added dummy backend which can be enabled with Kconfig. By default it is
disabled because it needs the same amount of memory as other phisical
backends. It shall be use only for commands testing purposes.

Improved shell_execute_cmd function, now it clears command context
before new command will be executed.

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
This commit is contained in:
Jakub Rzeszutko 2018-10-02 14:47:20 +02:00 committed by Anas Nashif
commit c3bc7180b0
8 changed files with 188 additions and 3 deletions

View file

@ -600,7 +600,9 @@ void shell_print_stream(const void *user_ctx, const char *data,
* Note: This by no means makes any of the commands a stable interface, so
* this function should only be used for debugging/diagnostic.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] shell Pointer to the shell instance. It can be NULL when
* the :option:`CONFIG_SHELL_BACKEND_DUMMY` option is
* enabled.
* @param[in] cmd Command to be executed.
*
* @returns Result of the execution

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef SHELL_DUMMY_H__
#define SHELL_DUMMY_H__
#include <shell/shell.h>
#ifdef __cplusplus
extern "C" {
#endif
extern const struct shell_transport_api shell_dummy_transport_api;
struct shell_dummy {
bool initialized;
};
#define SHELL_DUMMY_DEFINE(_name) \
static struct shell_dummy _name##_shell_dummy; \
struct shell_transport _name = { \
.api = &shell_dummy_transport_api, \
.ctx = (struct shell_dummy *)&_name##_shell_dummy \
}
/**
* @brief This function shall not be used directly. It provides pointer to shell
* dummy backend instance.
*
* Function returns pointer to the shell dummy instance. This instance can be
* next used with shell_execute_cmd function in order to test commands behavior.
*
* @returns Pointer to the shell instance.
*/
const struct shell *shell_backend_dummy_get_ptr(void);
#ifdef __cplusplus
}
#endif
#endif /* SHELL_DUMMY_H__ */

View file

@ -31,6 +31,16 @@ struct shell_uart {
.ctx = (struct shell_uart *)&_name##_shell_uart \
}
/**
* @brief This function provides pointer to shell uart backend instance.
*
* Function returns pointer to the shell uart instance. This instance can be
* next used with shell_execute_cmd function in order to test commands behavior.
*
* @returns Pointer to the shell instance.
*/
const struct shell *shell_backend_uart_get_ptr(void);
#ifdef __cplusplus
}
#endif