From 02114bf8220e1b6e8bdb86181d6ecc712a1849d2 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 28 Apr 2024 22:58:20 +0100 Subject: [PATCH] tests: shell: add tests for "device list" Add tests for the "device list" output with the various configuration of device power management. Signed-off-by: Fabio Baltieri --- .../subsys/shell/shell_device/CMakeLists.txt | 8 ++ tests/subsys/shell/shell_device/prj.conf | 5 ++ tests/subsys/shell/shell_device/src/main.c | 83 +++++++++++++++++++ tests/subsys/shell/shell_device/testcase.yaml | 45 ++++++++++ 4 files changed, 141 insertions(+) create mode 100644 tests/subsys/shell/shell_device/CMakeLists.txt create mode 100644 tests/subsys/shell/shell_device/prj.conf create mode 100644 tests/subsys/shell/shell_device/src/main.c create mode 100644 tests/subsys/shell/shell_device/testcase.yaml diff --git a/tests/subsys/shell/shell_device/CMakeLists.txt b/tests/subsys/shell/shell_device/CMakeLists.txt new file mode 100644 index 0000000000..fdea9ba07b --- /dev/null +++ b/tests/subsys/shell/shell_device/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(shell_device) + +target_sources(app PRIVATE src/main.c) diff --git a/tests/subsys/shell/shell_device/prj.conf b/tests/subsys/shell/shell_device/prj.conf new file mode 100644 index 0000000000..a50c21f56f --- /dev/null +++ b/tests/subsys/shell/shell_device/prj.conf @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_SHELL=y +CONFIG_SHELL_BACKEND_SERIAL=n +CONFIG_SHELL_BACKEND_DUMMY=y diff --git a/tests/subsys/shell/shell_device/src/main.c b/tests/subsys/shell/shell_device/src/main.c new file mode 100644 index 0000000000..d18c2c8098 --- /dev/null +++ b/tests/subsys/shell/shell_device/src/main.c @@ -0,0 +1,83 @@ +/* + * Copyright 2024 Google LLC + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_PM_DEVICE +static int dummy_device_pm_action(const struct device *dev, + enum pm_device_action action) +{ + return 0; +} + +PM_DEVICE_DEFINE(dummy_pm_driver_1, dummy_device_pm_action); +PM_DEVICE_DEFINE(dummy_pm_driver_2, dummy_device_pm_action); +PM_DEVICE_DEFINE(dummy_pm_driver_3, dummy_device_pm_action); +PM_DEVICE_DEFINE(dummy_pm_driver_4, dummy_device_pm_action); +#endif + +DEVICE_DEFINE(device_0, "device@0", NULL, NULL, + NULL, NULL, + POST_KERNEL, 0, NULL); + +DEVICE_DEFINE(device_1, "device@1", NULL, PM_DEVICE_GET(dummy_pm_driver_1), + NULL, NULL, + POST_KERNEL, 1, NULL); + +DEVICE_DEFINE(device_2, "device@2", NULL, PM_DEVICE_GET(dummy_pm_driver_2), + NULL, NULL, + POST_KERNEL, 2, NULL); + +DEVICE_DEFINE(device_3, "device@3", NULL, PM_DEVICE_GET(dummy_pm_driver_3), + NULL, NULL, + POST_KERNEL, 3, NULL); + +DEVICE_DEFINE(device_4, "device@4", NULL, PM_DEVICE_GET(dummy_pm_driver_4), + NULL, NULL, + POST_KERNEL, 4, NULL); + +#ifdef CONFIG_PM_DEVICE +static const struct device *d2 = &DEVICE_NAME_GET(device_2); +#endif +static const struct device *d3 = &DEVICE_NAME_GET(device_3); +static const struct device *d4 = &DEVICE_NAME_GET(device_4); + +int main(void) +{ + const struct shell *sh = shell_backend_dummy_get_ptr(); + const char *buf; + int err; + size_t size; + + /* Let the shell backend initialize. */ + k_usleep(10); + +#ifdef CONFIG_PM_DEVICE + pm_device_action_run(d2, PM_DEVICE_ACTION_SUSPEND); +#endif + + pm_device_runtime_enable(d3); + pm_device_runtime_enable(d4); + pm_device_runtime_get(d4); + + shell_backend_dummy_clear_output(sh); + + err = shell_execute_cmd(sh, "device list"); + if (err) { + printf("Failed to execute the shell command: %d.\n", + err); + } + + buf = shell_backend_dummy_get_output(sh, &size); + printf("%s\n", buf); + + return 0; +} diff --git a/tests/subsys/shell/shell_device/testcase.yaml b/tests/subsys/shell/shell_device/testcase.yaml new file mode 100644 index 0000000000..ccc36cf2ba --- /dev/null +++ b/tests/subsys/shell/shell_device/testcase.yaml @@ -0,0 +1,45 @@ +# SPDX-License-Identifier: Apache-2.0 + +common: + tags: shell + platform_allow: + - native_sim + integration_platforms: + - native_sim + +tests: + shell.device: + harness: console + harness_config: + type: multi_line + regex: + - "device@0 \\(READY\\)" + - "device@1 \\(READY\\)" + - "device@2 \\(READY\\)" + - "device@3 \\(READY\\)" + - "device@4 \\(READY\\)" + shell.device_pm_device: + extra_configs: + - CONFIG_PM_DEVICE=y + harness: console + harness_config: + type: multi_line + regex: + - "device@0 \\(READY\\)" + - "device@1 \\(active\\)" + - "device@2 \\(suspended\\)" + - "device@3 \\(active\\)" + - "device@4 \\(active\\)" + shell.device_pm_device_runtime: + extra_configs: + - CONFIG_PM_DEVICE=y + - CONFIG_PM_DEVICE_RUNTIME=y + harness: console + harness_config: + type: multi_line + regex: + - "device@0 \\(READY\\)" + - "device@1 \\(active\\)" + - "device@2 \\(suspended\\)" + - "device@3 \\(suspended, usage=0\\)" + - "device@4 \\(active, usage=1\\)"