tests: input_shell: add an input shell test
Add a test to validate the input shell command and event dump output. Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit is contained in:
parent
15f78fa545
commit
b1bccc2ca8
4 changed files with 74 additions and 0 deletions
8
tests/subsys/input/input_shell/CMakeLists.txt
Normal file
8
tests/subsys/input/input_shell/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
|
||||
project(input_shell)
|
||||
|
||||
target_sources(app PRIVATE src/main.c)
|
11
tests/subsys/input/input_shell/prj.conf
Normal file
11
tests/subsys/input/input_shell/prj.conf
Normal file
|
@ -0,0 +1,11 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
CONFIG_LOG=y
|
||||
CONFIG_LOG_MODE_MINIMAL=y
|
||||
CONFIG_SHELL=y
|
||||
CONFIG_SHELL_BACKEND_SERIAL=n
|
||||
CONFIG_SHELL_BACKEND_DUMMY=y
|
||||
|
||||
CONFIG_INPUT=y
|
||||
CONFIG_INPUT_EVENT_DUMP=y
|
||||
CONFIG_INPUT_SHELL=y
|
41
tests/subsys/input/input_shell/src/main.c
Normal file
41
tests/subsys/input/input_shell/src/main.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2023 Google LLC
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <zephyr/shell/shell.h>
|
||||
#include <zephyr/shell/shell_dummy.h>
|
||||
|
||||
#define SLEEP_TIME_MS 200
|
||||
#define CMD_BUF_LEN 128
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const struct shell *sh = shell_backend_dummy_get_ptr();
|
||||
bool val = false;
|
||||
int err;
|
||||
char buf[CMD_BUF_LEN];
|
||||
|
||||
err = shell_execute_cmd(sh, "input dump on");
|
||||
if (err) {
|
||||
printf("Failed to execute the shell command: %d.\n",
|
||||
err);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
snprintf(buf, 128, "input report 1 2 %d", val);
|
||||
err = shell_execute_cmd(sh, buf);
|
||||
if (err) {
|
||||
printf("Failed to execute the shell command: %d.\n",
|
||||
err);
|
||||
}
|
||||
|
||||
val = !val;
|
||||
|
||||
k_msleep(SLEEP_TIME_MS);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
14
tests/subsys/input/input_shell/testcase.yaml
Normal file
14
tests/subsys/input/input_shell/testcase.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
tests:
|
||||
input.input_shell:
|
||||
tags: input
|
||||
platform_allow:
|
||||
- native_posix
|
||||
- native_posix_64
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "I: input event: dev=NULL SYN type= 1 code= 2 value=0"
|
||||
- "I: input event: dev=NULL SYN type= 1 code= 2 value=1"
|
Loading…
Add table
Add a link
Reference in a new issue