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:
Fabio Baltieri 2023-06-20 15:06:05 +01:00 committed by Fabio Baltieri
commit b1bccc2ca8
4 changed files with 74 additions and 0 deletions

View 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)

View 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

View 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;
}

View 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"