diff options
author | Keith Short <keithshort@chromium.org> | 2022-08-22 11:48:49 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-09-08 20:52:27 +0000 |
commit | e7b63fbc3e6ee9a56d9390d074d1f2f8a399ac20 (patch) | |
tree | 1e89e02529700c0b550c7ae743172f7e1954d9db | |
parent | 633a9eafb4229ba721b4e1659fc424b1f85d8e45 (diff) | |
download | chrome-ec-e7b63fbc3e6ee9a56d9390d074d1f2f8a399ac20.tar.gz |
zephyr test: create hostevent helper
Create a helper routine for sending the "hostevent" console command.
This ensures 64-bit host events are tested consistently.
BUG=b:236074810
BRANCH=none
TEST=./twister -T zephyr/test/drivers
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: Ifd7d5ee8d2864242a5e05e386297e16854663ddd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3871741
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r-- | zephyr/test/drivers/default/src/console_cmd/hostevent.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/zephyr/test/drivers/default/src/console_cmd/hostevent.c b/zephyr/test/drivers/default/src/console_cmd/hostevent.c index bcce2ff568..2459dc905a 100644 --- a/zephyr/test/drivers/default/src/console_cmd/hostevent.c +++ b/zephyr/test/drivers/default/src/console_cmd/hostevent.c @@ -12,6 +12,12 @@ #include "test/drivers/test_state.h" #include "test/drivers/utils.h" +#ifdef CONFIG_HOST_EVENT64 +#define HOSTEVENT_PRINT_FORMAT "016" PRIx64 +#else +#define HOSTEVENT_PRINT_FORMAT "08" PRIx32 +#endif + struct console_cmd_hostevent_fixture { struct host_events_ctx ctx; }; @@ -37,6 +43,21 @@ static void console_cmd_hostevent_after(void *fixture) host_events_restore(&f->ctx); } +static int console_cmd_hostevent(const char *subcommand, host_event_t mask) +{ + int rv; + char cmd_buf[CONFIG_SHELL_CMD_BUFF_SIZE]; + + rv = snprintf(cmd_buf, CONFIG_SHELL_CMD_BUFF_SIZE, + "hostevent %s 0x%" HOSTEVENT_PRINT_FORMAT, subcommand, + mask); + + zassume_between_inclusive(rv, 0, CONFIG_SHELL_CMD_BUFF_SIZE, + "hostevent console command too long"); + + return shell_execute_cmd(get_ec_shell(), cmd_buf); +} + /* hostevent with no arguments */ ZTEST_USER(console_cmd_hostevent, test_hostevent) { @@ -48,9 +69,10 @@ ZTEST_USER(console_cmd_hostevent, test_hostevent) ZTEST_USER(console_cmd_hostevent, test_hostevent_invalid) { int rv; + host_event_t mask = 0; /* Test invalid sub-command */ - rv = shell_execute_cmd(get_ec_shell(), "hostevent invalid 0xFFFF"); + rv = console_cmd_hostevent("invalid", mask); zassert_equal(rv, EC_ERROR_PARAM1, "Expected %d, but got %d", EC_ERROR_PARAM1, rv); |