summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-05 14:43:48 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-10 17:51:47 +0000
commit896363cce8e54d6682360cff855abd905800aad0 (patch)
tree2bed5db9b91b43e7b1112d00090884b3eebce2be
parentb6826411d184bc52d2afe9f4a5d369baca8e68f1 (diff)
downloadchrome-ec-896363cce8e54d6682360cff855abd905800aad0.tar.gz
test: shim system.c system_reset()
Add test that verifies the system_reset() function saves system encoded reset flags, calls chip-specific cros system soc reset routine, and makes 1000 calls to watchdog_reload() if the SYSTEM_RESET_WAIT_EXT reset flag is set. BRANCH=none BUG=b:236074898 TEST=twister --clobber -i -s zephyr/test/system_shim/system_shim.default Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I2cdbb99028dc5b48a1b244380e76472624bad5e0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3935639 Reviewed-by: Sam Hurst <shurst@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--include/watchdog.h2
-rw-r--r--zephyr/shim/src/system.c6
-rw-r--r--zephyr/test/system_shim/test_system.c45
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");