diff options
author | Aaron Massey <aaronmassey@google.com> | 2022-10-03 17:40:04 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-06 00:10:12 +0000 |
commit | bcd18f426a4b5fae16074c2a0b24793c6d3ddaf1 (patch) | |
tree | d1559bf3bf79f8da5f4f5000e0cc1036aa9527f5 | |
parent | f3889b69a302e953513a400012eaaf4893ad111d (diff) | |
download | chrome-ec-bcd18f426a4b5fae16074c2a0b24793c6d3ddaf1.tar.gz |
test: shim system.c idlestats console command
Verify the idlestats console command fetches the idling time stats from
the cros system chip specific driver. Adds a new cros system driver for
native posix explicitly for testing purposes.
BRANCH=none
BUG=b:236074898
TEST=twister --clobber -i -s zephyr/test/system_shim/system_shim.default
TEST=CQ
Signed-off-by: Aaron Massey <aaronmassey@google.com>
Change-Id: I44a5bea19923ecf46a1906a323aaa446b51bba41
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3933259
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | zephyr/drivers/cros_system/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/drivers/cros_system/Kconfig | 24 | ||||
-rw-r--r-- | zephyr/drivers/cros_system/cros_system_native_posix.c | 117 | ||||
-rw-r--r-- | zephyr/test/system_shim/CMakeLists.txt | 3 | ||||
-rw-r--r-- | zephyr/test/system_shim/test_system.c | 36 | ||||
-rw-r--r-- | zephyr/test/system_shim/testcase.yaml | 9 |
6 files changed, 189 insertions, 1 deletions
diff --git a/zephyr/drivers/cros_system/CMakeLists.txt b/zephyr/drivers/cros_system/CMakeLists.txt index 0838dca1ae..79d320f9a1 100644 --- a/zephyr/drivers/cros_system/CMakeLists.txt +++ b/zephyr/drivers/cros_system/CMakeLists.txt @@ -5,3 +5,4 @@ zephyr_library_sources_ifdef(CONFIG_CROS_SYSTEM_IT8XXX2 cros_system_it8xxx2.c) zephyr_library_sources_ifdef(CONFIG_CROS_SYSTEM_NPCX cros_system_npcx.c) zephyr_library_sources_ifdef(CONFIG_CROS_SYSTEM_XEC cros_system_xec.c) +zephyr_library_sources_ifdef(CONFIG_CROS_SYSTEM_NATIVE_POSIX cros_system_native_posix.c) diff --git a/zephyr/drivers/cros_system/Kconfig b/zephyr/drivers/cros_system/Kconfig index 80fc701285..79e1499b2c 100644 --- a/zephyr/drivers/cros_system/Kconfig +++ b/zephyr/drivers/cros_system/Kconfig @@ -68,3 +68,27 @@ config CROS_SYSTEM_XEC_INIT_PRIORITY CONFIG_PLATFORM_EC_SYSTEM_PRE_INIT_PRIORITY. endif # CONFIG_CROS_SYSTEM_XEC + +menuconfig CROS_SYSTEM_NATIVE_POSIX + bool "Native POSIX cros system driver (test only)" + depends on SOC_POSIX && CROS_EC + default y + help + This option enables the cros system driver for the native POSIX + testing board. Currently, Zephyr doesn't provide the system related + API. The cros system driver provides fakable stubs for the low-level + driver related to chromium ec system functionality. + +if CROS_SYSTEM_NATIVE_POSIX + +config CROS_SYSTEM_NATIVE_POSIX_INIT_PRIORITY + int "cros_system native POSIX initialization priority (test only)" + default 10 + range 10 19 + help + This sets the native POSIX cros_system driver initialization + priority. The cros_system driver provides access to mockable cros + system functions to facillitate testing and must be higher priority + than CONFIG_SYSTEM_PRE_INIT_PRIORITY. + +endif # CROS_SYSTEM_NATIVE_POSIX diff --git a/zephyr/drivers/cros_system/cros_system_native_posix.c b/zephyr/drivers/cros_system/cros_system_native_posix.c new file mode 100644 index 0000000000..fab9c4d033 --- /dev/null +++ b/zephyr/drivers/cros_system/cros_system_native_posix.c @@ -0,0 +1,117 @@ +/* Copyright 2022 The ChromiumOS Authors + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* LCOV_EXCL_START */ +/* This is test code, so it should be excluded from coverage */ + +#include <zephyr/logging/log.h> +#include <zephyr/sys/util.h> + +#include "common.h" +#include "drivers/cros_system.h" + +LOG_MODULE_REGISTER(cros_system, LOG_LEVEL_ERR); + +/* Driver config stub */ +struct cros_system_native_posix_config {}; + +/* Driver data stub */ +struct cros_system_native_posix_data {}; + +test_mockable_static int cros_system_native_posix_init(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +/* Stubbed cros_system API */ + +test_mockable_static int +cros_system_native_posix_get_reset_cause(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +test_mockable_static int +cros_system_native_posix_soc_reset(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +test_mockable_static int +cros_system_native_posix_hibernate(const struct device *dev, uint32_t seconds, + uint32_t microseconds) +{ + ARG_UNUSED(dev); + ARG_UNUSED(seconds); + ARG_UNUSED(microseconds); + + return 0; +} + +test_mockable_static const char * +cros_system_native_posix_get_chip_vendor(const struct device *dev) +{ + ARG_UNUSED(dev); + + return "NATIVE_POSIX_VENDOR"; +} + +test_mockable_static const char * +cros_system_native_posix_get_chip_name(const struct device *dev) +{ + ARG_UNUSED(dev); + + return "NATIVE_POSIX_CHIP"; +} + +test_mockable_static const char * +cros_system_native_posix_get_chip_revision(const struct device *dev) +{ + ARG_UNUSED(dev); + + return "NATIVE_POSIX_REVISION"; +} + +__maybe_unused test_mockable_static uint64_t +cros_system_native_posix_deep_sleep_ticks(const struct device *dev) +{ + ARG_UNUSED(dev); + + return 0; +} + +static struct cros_system_native_posix_data cros_system_native_posix_dev_data; + +static const struct cros_system_native_posix_config cros_system_dev_cfg = {}; + +/* clang-format off */ +/* clang-format extends past 80 lines here */ +static const struct +cros_system_driver_api cros_system_driver_native_posix_api = { + .get_reset_cause = cros_system_native_posix_get_reset_cause, + .soc_reset = cros_system_native_posix_soc_reset, + .hibernate = cros_system_native_posix_hibernate, + .chip_vendor = cros_system_native_posix_get_chip_vendor, + .chip_name = cros_system_native_posix_get_chip_name, + .chip_revision = cros_system_native_posix_get_chip_revision, +#ifdef CONFIG_PM + .deep_sleep_ticks = cros_system_native_posix_deep_sleep_ticks, +#endif +}; +/* clang-format on */ + +DEVICE_DEFINE(cros_system_native_posix_0, "CROS_SYSTEM", + cros_system_native_posix_init, NULL, + &cros_system_native_posix_dev_data, &cros_system_dev_cfg, + PRE_KERNEL_1, CONFIG_CROS_SYSTEM_NATIVE_POSIX_INIT_PRIORITY, + &cros_system_driver_native_posix_api); + +/* LCOV_EXCL_STOP */ diff --git a/zephyr/test/system_shim/CMakeLists.txt b/zephyr/test/system_shim/CMakeLists.txt index 2f8b61cda8..5db9cb285d 100644 --- a/zephyr/test/system_shim/CMakeLists.txt +++ b/zephyr/test/system_shim/CMakeLists.txt @@ -6,5 +6,8 @@ cmake_minimum_required(VERSION 3.13.1) find_package(Zephyr REQUIRED HINTS "${ZEPHYR_BASE}") project(system_shim_test) +# Include FFF fakes +add_subdirectory(${PLATFORM_EC}/zephyr/test/test_utils test_utils) + target_sources(app PRIVATE test_system.c ${PLATFORM_EC}/zephyr/shim/src/system.c) diff --git a/zephyr/test/system_shim/test_system.c b/zephyr/test/system_shim/test_system.c index 2f1cdc8aaf..ddf992169a 100644 --- a/zephyr/test/system_shim/test_system.c +++ b/zephyr/test/system_shim/test_system.c @@ -5,7 +5,9 @@ #include <zephyr/device.h> #include <zephyr/drivers/bbram.h> +#include <zephyr/fff.h> #include <zephyr/logging/log.h> +#include <zephyr/shell/shell_dummy.h> #include <zephyr/ztest_assert.h> #include <zephyr/ztest_test_new.h> @@ -21,7 +23,15 @@ LOG_MODULE_REGISTER(test); static char mock_data[64] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@"; -ZTEST_SUITE(system, NULL, NULL, NULL, NULL, NULL); +FAKE_VALUE_FUNC(uint64_t, cros_system_native_posix_deep_sleep_ticks, + const struct device *) + +static void system_before_after(void *test_data) +{ + RESET_FAKE(cros_system_native_posix_deep_sleep_ticks); +} + +ZTEST_SUITE(system, NULL, NULL, system_before_after, system_before_after, NULL); ZTEST(system, test_bbram_get) { @@ -74,3 +84,27 @@ ZTEST(system, test_system_set_get_scratchpad) system_get_scratchpad(&scratch_read); zassert_equal(scratch_read, scratch_set); } + +ZTEST_USER(system, test_system_console_cmd__idlestats) +{ + const struct device *sys_dev = device_get_binding("CROS_SYSTEM"); + const struct shell *shell_zephyr = get_ec_shell(); + const char *outbuffer; + size_t buffer_size; + + zassert_not_null(sys_dev); + + shell_backend_dummy_clear_output(shell_zephyr); + + k_sleep(K_SECONDS(1)); + zassert_ok(shell_execute_cmd(shell_zephyr, "idlestats"), NULL); + + /* Weakly verify contents */ + outbuffer = shell_backend_dummy_get_output(shell_zephyr, &buffer_size); + zassert_not_equal(buffer_size, 0); + zassert_not_null(strstr(outbuffer, "Time spent in deep-sleep:")); + zassert_not_null(strstr(outbuffer, "Total time on:")); + + zassert_equal(cros_system_native_posix_deep_sleep_ticks_fake.call_count, + 1); +} diff --git a/zephyr/test/system_shim/testcase.yaml b/zephyr/test/system_shim/testcase.yaml index 1dfdd982be..3374c7f5f3 100644 --- a/zephyr/test/system_shim/testcase.yaml +++ b/zephyr/test/system_shim/testcase.yaml @@ -4,3 +4,12 @@ tests: system_shim.default: tags: system + extra_configs: + # Make console work + - CONFIG_SERIAL=y + - CONFIG_SHELL_BACKEND_DUMMY=y + - CONFIG_SHELL_BACKEND_DUMMY_BUF_SIZE=1000 + - CONFIG_SHELL_BACKEND_SERIAL=n + # Make cros_system driver work + - CONFIG_PM=y + - CONFIG_CROS_SYSTEM_NATIVE_POSIX=y |