summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhurima Paruchuri <mparuchuri@google.com>2022-08-23 11:58:57 +0530
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-25 08:08:24 +0000
commit2d9d2a058395ca76787bf41a66a7a5125929cb40 (patch)
tree2a9aa4f7153ceae1a527e68fd35bbbf4da56639b
parent8c28b4fa0b514935868764f0113766c93d3b5acb (diff)
downloadchrome-ec-2d9d2a058395ca76787bf41a66a7a5125929cb40.tar.gz
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 <mparuchuri@google.com> Change-Id: I0716675e4e43caee67ccfba9155ed9a1e8da6e32 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3849666 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--zephyr/test/drivers/default/src/espi.c41
1 files changed, 40 insertions, 1 deletions
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 <string.h>
+#include <zephyr/fff.h>
#include <zephyr/zephyr.h>
#include <zephyr/ztest.h>
#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);