From 2d9d2a058395ca76787bf41a66a7a5125929cb40 Mon Sep 17 00:00:00 2001 From: Madhurima Paruchuri Date: Tue, 23 Aug 2022 11:58:57 +0530 Subject: zephyr: Add tests for failure paths of GPIO set host command Add tests for the EC_CMD_GPIO_SET host command covering few failing paths BUG=b:236131899 BRANCH=none TEST=./twister -s zephyr/test/drivers/drivers.default -c Signed-off-by: Madhurima Paruchuri Change-Id: I0716675e4e43caee67ccfba9155ed9a1e8da6e32 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3849666 Code-Coverage: Zoss Reviewed-by: Abe Levkoy --- zephyr/test/drivers/default/src/espi.c | 41 +++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/zephyr/test/drivers/default/src/espi.c b/zephyr/test/drivers/default/src/espi.c index 1ebf68abd2..c518f3922f 100644 --- a/zephyr/test/drivers/default/src/espi.c +++ b/zephyr/test/drivers/default/src/espi.c @@ -4,12 +4,14 @@ */ #include +#include #include #include #include "ec_commands.h" #include "gpio.h" #include "host_command.h" +#include "system.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" @@ -17,6 +19,20 @@ #define AC_OK_OD_GPIO_NAME "acok_od" +FAKE_VALUE_FUNC(int, system_is_locked); + +static void espi_before(void *state) +{ + ARG_UNUSED(state); + RESET_FAKE(system_is_locked); +} + +static void espi_after(void *state) +{ + ARG_UNUSED(state); + RESET_FAKE(system_is_locked); +} + ZTEST_USER(espi, test_host_command_get_protocol_info) { struct ec_response_get_protocol_info response; @@ -285,4 +301,27 @@ ZTEST_USER(espi, test_host_command_ec_cmd_get_features) "Known features were not returned."); } -ZTEST_SUITE(espi, drivers_predicate_post_main, NULL, NULL, NULL, NULL); +ZTEST(espi, test_hc_gpio_set_system_is_locked) +{ + struct ec_params_gpio_set params; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_GPIO_SET, 0, params); + + system_is_locked_fake.return_val = 1; + zassert_equal(EC_RES_ACCESS_DENIED, host_command_process(&args), NULL); +} + +ZTEST(espi, test_hc_gpio_set_invalid_gpio_name) +{ + struct ec_params_gpio_set params = { + .name = "", + .val = 0, + }; + struct host_cmd_handler_args args = + BUILD_HOST_COMMAND_PARAMS(EC_CMD_GPIO_SET, 0, params); + + zassert_equal(EC_RES_ERROR, host_command_process(&args), NULL); +} + +ZTEST_SUITE(espi, drivers_predicate_post_main, NULL, espi_before, espi_after, + NULL); -- cgit v1.2.1