summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Massey <aaronmassey@google.com>2022-10-05 08:42:21 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-07 18:05:35 +0000
commit7e893faf0972ea2b764a7783ac5109cbdb05de80 (patch)
tree379563644e8b5f3f2766c0cc3cd3fce417490ed8
parent7c5f4b9021be26ff63fed71bae466104b00fde2f (diff)
downloadchrome-ec-7e893faf0972ea2b764a7783ac5109cbdb05de80.tar.gz
test: shim system.c system_hibernate()
Add test that verifies the system_hibernate() function calls the chip-specific cros system routine for hibernation and can respond to an error from the aforementioned test without going into an infinite loop. 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: Ice3aed18d7f9f858263aac4aecc980ca6720bfe1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3936482 Reviewed-by: Keith Short <keithshort@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--zephyr/shim/src/system.c6
-rw-r--r--zephyr/test/system_shim/test_system.c67
2 files changed, 72 insertions, 1 deletions
diff --git a/zephyr/shim/src/system.c b/zephyr/shim/src/system.c
index c2182e92c5..b3dd2c121b 100644
--- a/zephyr/shim/src/system.c
+++ b/zephyr/shim/src/system.c
@@ -159,9 +159,15 @@ test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds)
return;
}
+ /*
+ * Ignore infinite loop for coverage as the test would fail via timeout
+ * and not report regardless of executing code.
+ */
+ /* LCOV_EXCL_START */
/* should never reach this point */
while (1)
continue;
+ /* LCOV_EXCL_STOP */
}
#ifdef CONFIG_PM
diff --git a/zephyr/test/system_shim/test_system.c b/zephyr/test/system_shim/test_system.c
index ddf992169a..e4b4ddebc6 100644
--- a/zephyr/test/system_shim/test_system.c
+++ b/zephyr/test/system_shim/test_system.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include <setjmp.h>
#include <zephyr/device.h>
#include <zephyr/drivers/bbram.h>
#include <zephyr/fff.h>
@@ -24,11 +25,14 @@ static char mock_data[64] =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@";
FAKE_VALUE_FUNC(uint64_t, cros_system_native_posix_deep_sleep_ticks,
- const struct device *)
+ const struct device *);
+FAKE_VALUE_FUNC(int, cros_system_native_posix_hibernate, const struct device *,
+ uint32_t, uint32_t);
static void system_before_after(void *test_data)
{
RESET_FAKE(cros_system_native_posix_deep_sleep_ticks);
+ RESET_FAKE(cros_system_native_posix_hibernate);
}
ZTEST_SUITE(system, NULL, NULL, system_before_after, system_before_after, NULL);
@@ -85,6 +89,67 @@ ZTEST(system, test_system_set_get_scratchpad)
zassert_equal(scratch_read, scratch_set);
}
+static jmp_buf jmp_hibernate;
+
+static int _test_cros_system_native_posix_hibernate(const struct device *dev,
+ uint32_t seconds,
+ uint32_t microseconds)
+{
+ longjmp(jmp_hibernate, 1);
+
+ return 0;
+}
+
+ZTEST(system, test_system_hibernate)
+{
+ /*
+ * Due to setjmp usage, this test provides no coverage, but does
+ * actually cover the code. This is due to a bug in LCOV.
+ */
+ const struct device *sys_dev = device_get_binding("CROS_SYSTEM");
+ int ret = setjmp(jmp_hibernate);
+ /* Validate 0th and last bit preserved*/
+ uint32_t secs = BIT(31) + 1;
+ uint32_t msecs = BIT(31) + 3;
+
+ zassert_not_null(sys_dev);
+
+ cros_system_native_posix_hibernate_fake.custom_fake =
+ _test_cros_system_native_posix_hibernate;
+
+ if (ret == 0) {
+ system_hibernate(secs, msecs);
+ }
+
+ zassert_not_equal(ret, 0);
+
+ zassert_equal(cros_system_native_posix_hibernate_fake.call_count, 1);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg0_val,
+ sys_dev);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg1_val, secs);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg2_val, msecs);
+}
+
+ZTEST(system, test_system_hibernate__failure)
+{
+ const struct device *sys_dev = device_get_binding("CROS_SYSTEM");
+ /* Validate 0th and last bit preserved*/
+ uint32_t secs = BIT(31) + 1;
+ uint32_t msecs = BIT(31) + 3;
+
+ zassert_not_null(sys_dev);
+
+ cros_system_native_posix_hibernate_fake.return_val = -1;
+
+ system_hibernate(secs, msecs);
+
+ zassert_equal(cros_system_native_posix_hibernate_fake.call_count, 1);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg0_val,
+ sys_dev);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg1_val, secs);
+ zassert_equal(cros_system_native_posix_hibernate_fake.arg2_val, msecs);
+}
+
ZTEST_USER(system, test_system_console_cmd__idlestats)
{
const struct device *sys_dev = device_get_binding("CROS_SYSTEM");