diff options
-rw-r--r-- | include/watchdog.h | 2 | ||||
-rw-r--r-- | zephyr/shim/src/system.c | 6 | ||||
-rw-r--r-- | zephyr/test/system_shim/test_system.c | 45 |
3 files changed, 52 insertions, 1 deletions
diff --git a/include/watchdog.h b/include/watchdog.h index 9bfed9c192..d6768425ce 100644 --- a/include/watchdog.h +++ b/include/watchdog.h @@ -49,7 +49,7 @@ void watchdog_stop_and_unlock(void); #ifdef CONFIG_WATCHDOG void watchdog_reload(void); #else -static inline void watchdog_reload(void) +test_mockable_static_inline void watchdog_reload(void) { } #endif diff --git a/zephyr/shim/src/system.c b/zephyr/shim/src/system.c index b3dd2c121b..53e651ec03 100644 --- a/zephyr/shim/src/system.c +++ b/zephyr/shim/src/system.c @@ -244,9 +244,15 @@ test_mockable void system_reset(int flags) if (err < 0) LOG_ERR("soc reset failed"); + /* + * Ignore infinite loop for coverage as the test would fail via timeout + * and not report regardless of executing code. + */ + /* LCOV_EXCL_START */ /* should never return */ while (1) continue; + /* LCOV_EXCL_STOP */ } static int check_reset_cause(void) diff --git a/zephyr/test/system_shim/test_system.c b/zephyr/test/system_shim/test_system.c index de54fda1fb..3bf43d6669 100644 --- a/zephyr/test/system_shim/test_system.c +++ b/zephyr/test/system_shim/test_system.c @@ -34,6 +34,8 @@ FAKE_VALUE_FUNC(const char *, cros_system_native_posix_get_chip_name, const struct device *); FAKE_VALUE_FUNC(const char *, cros_system_native_posix_get_chip_revision, const struct device *); +FAKE_VALUE_FUNC(int, cros_system_native_posix_soc_reset, const struct device *); +FAKE_VOID_FUNC(watchdog_reload); static void system_before_after(void *test_data) { @@ -187,6 +189,49 @@ ZTEST(system, test_system_get_chip_values) sys_dev); } +static int _test_cros_system_native_posix_soc_reset(const struct device *dev) +{ + printf("called from soc reset"); + longjmp(jmp_hibernate, 1); + + return 0; +} + +ZTEST(system, test_system_reset) +{ + /* + * Despite using setjmp this test consistently covers the code under + * test. Context: https://github.com/llvm/llvm-project/issues/50119 + */ + const struct device *sys_dev = device_get_binding("CROS_SYSTEM"); + int ret = setjmp(jmp_hibernate); + uint32_t arbitrary_flags_w_reset_wait_ext = 0x1234 | + SYSTEM_RESET_WAIT_EXT; + uint32_t encoded_arbitrary_flags_w_reset_wait_ext; + + system_encode_save_flags(arbitrary_flags_w_reset_wait_ext, + &encoded_arbitrary_flags_w_reset_wait_ext); + + zassert_not_null(sys_dev); + + cros_system_native_posix_soc_reset_fake.custom_fake = + _test_cros_system_native_posix_soc_reset; + + if (ret == 0) { + system_reset(arbitrary_flags_w_reset_wait_ext); + } + + zassert_not_null(sys_dev); + + zassert_equal(chip_read_reset_flags(), + encoded_arbitrary_flags_w_reset_wait_ext); + + zassert_equal(watchdog_reload_fake.call_count, 1000); + zassert_equal(cros_system_native_posix_soc_reset_fake.call_count, 1); + zassert_equal(cros_system_native_posix_soc_reset_fake.arg0_val, + sys_dev); +} + ZTEST_USER(system, test_system_console_cmd__idlestats) { const struct device *sys_dev = device_get_binding("CROS_SYSTEM"); |