From b1bccc2ca84975bf4c0eefae4ba4d3c8074f7521 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Tue, 20 Jun 2023 15:06:05 +0100 Subject: [PATCH] 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 --- tests/subsys/input/input_shell/CMakeLists.txt | 8 ++++ tests/subsys/input/input_shell/prj.conf | 11 +++++ tests/subsys/input/input_shell/src/main.c | 41 +++++++++++++++++++ tests/subsys/input/input_shell/testcase.yaml | 14 +++++++ 4 files changed, 74 insertions(+) create mode 100644 tests/subsys/input/input_shell/CMakeLists.txt create mode 100644 tests/subsys/input/input_shell/prj.conf create mode 100644 tests/subsys/input/input_shell/src/main.c create mode 100644 tests/subsys/input/input_shell/testcase.yaml diff --git a/tests/subsys/input/input_shell/CMakeLists.txt b/tests/subsys/input/input_shell/CMakeLists.txt new file mode 100644 index 00000000000..86be092e663 --- /dev/null +++ b/tests/subsys/input/input_shell/CMakeLists.txt @@ -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) diff --git a/tests/subsys/input/input_shell/prj.conf b/tests/subsys/input/input_shell/prj.conf new file mode 100644 index 00000000000..c9239e22376 --- /dev/null +++ b/tests/subsys/input/input_shell/prj.conf @@ -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 diff --git a/tests/subsys/input/input_shell/src/main.c b/tests/subsys/input/input_shell/src/main.c new file mode 100644 index 00000000000..4f1b9a05106 --- /dev/null +++ b/tests/subsys/input/input_shell/src/main.c @@ -0,0 +1,41 @@ +/* + * Copyright 2023 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +#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; +} diff --git a/tests/subsys/input/input_shell/testcase.yaml b/tests/subsys/input/input_shell/testcase.yaml new file mode 100644 index 00000000000..e226780164f --- /dev/null +++ b/tests/subsys/input/input_shell/testcase.yaml @@ -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"