summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers
diff options
context:
space:
mode:
authorAl Semjonovs <asemjonovs@google.com>2022-09-07 14:40:03 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-09-08 23:46:54 +0000
commit6dce1d0e9d356484034123f8313b817237ba2d6f (patch)
treecc0214df7da4b981e7a5c6450135b19072666bb1 /zephyr/test/drivers
parent7bdfc8219bdc91804c025c22a52b682861928a00 (diff)
downloadchrome-ec-6dce1d0e9d356484034123f8313b817237ba2d6f.tar.gz
zephyr: Test RTC console commands
Validate RTC console commands BUG=b:236074639, b:236074640 BRANCH=NONE TEST=./twister -T zephyr/test Signed-off-by: Al Semjonovs <asemjonovs@google.com> Change-Id: Ib12154f876e0fef2411f23d26f572de4313c436c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3880866 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Aaron Massey <aaronmassey@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'zephyr/test/drivers')
-rw-r--r--zephyr/test/drivers/common/include/test/drivers/utils.h10
-rw-r--r--zephyr/test/drivers/common/src/utils.c24
-rw-r--r--zephyr/test/drivers/default/CMakeLists.txt1
-rw-r--r--zephyr/test/drivers/default/src/console_cmd/rtc.c73
4 files changed, 108 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/utils.h b/zephyr/test/drivers/common/include/test/drivers/utils.h
index 2328c810fa..4e192b769a 100644
--- a/zephyr/test/drivers/common/include/test/drivers/utils.h
+++ b/zephyr/test/drivers/common/include/test/drivers/utils.h
@@ -610,4 +610,14 @@ void test_free(void *mem);
*/
void test_set_chipset_to_g3_then_transition_to_s5(void);
+/**
+ * @brief Checks console command with expected console output and expected
+ * return value
+ *
+ */
+#define CHECK_CONSOLE_CMD(cmd, expected_output, expected_rv) \
+ check_console_cmd((cmd), (expected_output), (expected_rv), __FILE__, \
+ __LINE__)
+void check_console_cmd(const char *cmd, const char *expected_output,
+ const int expected_rv, const char *file, const int line);
#endif /* ZEPHYR_TEST_DRIVERS_INCLUDE_UTILS_H_ */
diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c
index 62e4b989ef..5641c27073 100644
--- a/zephyr/test/drivers/common/src/utils.c
+++ b/zephyr/test/drivers/common/src/utils.c
@@ -4,6 +4,8 @@
*/
#include <zephyr/drivers/gpio/gpio_emul.h>
+#include <zephyr/shell/shell.h>
+#include <zephyr/shell/shell_dummy.h> /* nocheck */
#include <zephyr/shell/shell_uart.h>
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
@@ -601,3 +603,25 @@ int emul_init_stub(const struct device *dev)
/* These 2 lines are needed because we don't define an espi host driver */
#define DT_DRV_COMPAT zephyr_espi_emul_espi_host
DT_INST_FOREACH_STATUS_OKAY(EMUL_STUB_DEVICE);
+
+void check_console_cmd(const char *cmd, const char *expected_output,
+ const int expected_rv, const char *file, const int line)
+{
+ const char *buffer;
+ size_t buffer_size;
+ int rv;
+
+ shell_backend_dummy_clear_output(get_ec_shell());
+ rv = shell_execute_cmd(get_ec_shell(), cmd);
+
+ zassert_equal(expected_rv, rv,
+ "%s:%u \'%s\' - Expected %d, returned %d", file, line,
+ cmd, expected_rv, rv);
+
+ if (expected_output) {
+ buffer = shell_backend_dummy_get_output(get_ec_shell(),
+ &buffer_size);
+ zassert_true(strstr(buffer, expected_output),
+ "Invalid console output %s", buffer);
+ }
+}
diff --git a/zephyr/test/drivers/default/CMakeLists.txt b/zephyr/test/drivers/default/CMakeLists.txt
index df3fe980e5..8f5a33cfa1 100644
--- a/zephyr/test/drivers/default/CMakeLists.txt
+++ b/zephyr/test/drivers/default/CMakeLists.txt
@@ -33,6 +33,7 @@ target_sources(app PRIVATE
src/console_cmd/port80.c
src/console_cmd/powerindebug.c
src/console_cmd/power_button.c
+ src/console_cmd/rtc.c
src/console_cmd/rw.c
src/console_cmd/sleepmask.c
src/console_cmd/sleeptimeout.c
diff --git a/zephyr/test/drivers/default/src/console_cmd/rtc.c b/zephyr/test/drivers/default/src/console_cmd/rtc.c
new file mode 100644
index 0000000000..6e084321e2
--- /dev/null
+++ b/zephyr/test/drivers/default/src/console_cmd/rtc.c
@@ -0,0 +1,73 @@
+/* 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.
+ */
+
+#include <zephyr/ztest.h>
+
+#include "console.h"
+#include "ec_commands.h"
+#include "system.h"
+#include "test/drivers/test_state.h"
+#include "test/drivers/utils.h"
+
+ZTEST_USER(console_cmd_rtc, test_rtc_no_arg)
+{
+ char expected_buffer[32];
+ uint32_t sec = 7;
+
+ snprintf(expected_buffer, sizeof(expected_buffer),
+ "RTC: 0x%08x (%d.00 s)", sec, sec);
+
+ system_set_rtc(sec);
+
+ CHECK_CONSOLE_CMD("rtc", expected_buffer, EC_SUCCESS);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_invalid)
+{
+ CHECK_CONSOLE_CMD("rtc set", NULL, EC_ERROR_INVAL);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_set)
+{
+ char command[32];
+ char expected_buffer[32];
+ uint32_t sec = 48879;
+
+ snprintf(expected_buffer, sizeof(expected_buffer),
+ "RTC: 0x%08x (%d.00 s)", sec, sec);
+ snprintf(command, sizeof(command), "rtc set %d", sec);
+
+ CHECK_CONSOLE_CMD(command, expected_buffer, EC_SUCCESS);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_set_bad)
+{
+ CHECK_CONSOLE_CMD("rtc set t", NULL, EC_ERROR_PARAM2);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_alarm_no_args)
+{
+ CHECK_CONSOLE_CMD("rtc_alarm", "Setting RTC alarm", EC_SUCCESS);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_alarm_good_args)
+{
+ CHECK_CONSOLE_CMD("rtc_alarm 1", "Setting RTC alarm", EC_SUCCESS);
+ CHECK_CONSOLE_CMD("rtc_alarm 1 5", "Setting RTC alarm", EC_SUCCESS);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_alarm_bad_args)
+{
+ CHECK_CONSOLE_CMD("rtc_alarm t", NULL, EC_ERROR_PARAM1);
+ CHECK_CONSOLE_CMD("rtc_alarm 1 t", NULL, EC_ERROR_PARAM2);
+}
+
+ZTEST_USER(console_cmd_rtc, test_rtc_alarm_reset)
+{
+ CHECK_CONSOLE_CMD("rtc_alarm 0", "Setting RTC alarm", EC_SUCCESS);
+ CHECK_CONSOLE_CMD("rtc_alarm 0 0", "Setting RTC alarm", EC_SUCCESS);
+}
+
+ZTEST_SUITE(console_cmd_rtc, NULL, NULL, NULL, NULL, NULL);