diff options
Diffstat (limited to 'zephyr/test/drivers/common/src/utils.c')
-rw-r--r-- | zephyr/test/drivers/common/src/utils.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/zephyr/test/drivers/common/src/utils.c b/zephyr/test/drivers/common/src/utils.c index 2a75c87c10..f083300886 100644 --- a/zephyr/test/drivers/common/src/utils.c +++ b/zephyr/test/drivers/common/src/utils.c @@ -1,11 +1,13 @@ -/* Copyright 2022 The Chromium OS Authors. All rights reserved. +/* 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/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/zephyr.h> +#include <zephyr/kernel.h> #include <zephyr/ztest.h> #include "acpi.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); + } +} |