diff options
author | Wai-Hong Tam <waihong@google.com> | 2022-08-18 14:43:37 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-19 23:53:26 +0000 |
commit | 9f012dc430157b6aaf20af3cd51c371bd8131976 (patch) | |
tree | dbca31205d600adeaee381c7db6c7ef8a784c5a2 | |
parent | 3199d3a3aeb1807d8699df8931f6ebb35567e034 (diff) | |
download | chrome-ec-9f012dc430157b6aaf20af3cd51c371bd8131976.tar.gz |
zephyr: test: Add I2C passthru protect host command test cases
Add the test cases for I2C passthru protect. They cover the subcommands:
status, enable, and enable_tcpc. They covers the error cases.
BRANCH=None
BUG=b:236131905
TEST=./twister -s zephyr/test/drivers/drivers.default
Change-Id: I16fe91880265204376477aac60ca8b2ed456c7bf
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3840659
Reviewed-by: Yuval Peress <peress@google.com>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | common/i2c_controller.c | 5 | ||||
-rw-r--r-- | include/i2c.h | 2 | ||||
-rw-r--r-- | zephyr/test/drivers/default/src/i2c_passthru.c | 83 |
3 files changed, 89 insertions, 1 deletions
diff --git a/common/i2c_controller.c b/common/i2c_controller.c index e04eec6a6c..ee72caa1ef 100644 --- a/common/i2c_controller.c +++ b/common/i2c_controller.c @@ -1358,6 +1358,11 @@ static enum ec_status i2c_command_passthru(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_I2C_PASSTHRU, i2c_command_passthru, EC_VER_MASK(0)); +__test_only void i2c_passthru_protect_reset(void) +{ + memset(port_protected, 0, sizeof(port_protected)); +} + static void i2c_passthru_protect_port(uint32_t port) { if (port < ARRAY_SIZE(port_protected)) diff --git a/include/i2c.h b/include/i2c.h index 4e4d88b0ad..99651d04c1 100644 --- a/include/i2c.h +++ b/include/i2c.h @@ -589,4 +589,6 @@ const struct i2c_port_t *get_i2c_port(const int port); int i2c_port_is_locked(int port); #endif +__test_only void i2c_passthru_protect_reset(void); + #endif /* __CROS_EC_I2C_H */ diff --git a/zephyr/test/drivers/default/src/i2c_passthru.c b/zephyr/test/drivers/default/src/i2c_passthru.c index 3011057f6d..a9a1ac6638 100644 --- a/zephyr/test/drivers/default/src/i2c_passthru.c +++ b/zephyr/test/drivers/default/src/i2c_passthru.c @@ -8,6 +8,7 @@ #include "ec_commands.h" #include "host_command.h" +#include "i2c.h" #include "test/drivers/test_state.h" ZTEST_USER(i2c_passthru, test_read_without_write) @@ -39,4 +40,84 @@ ZTEST_USER(i2c_passthru, test_read_without_write) sizeof(struct ec_response_i2c_passthru), NULL); } -ZTEST_SUITE(i2c_passthru, drivers_predicate_post_main, NULL, NULL, NULL, NULL); +ZTEST_USER(i2c_passthru, test_passthru_protect) +{ + struct ec_response_i2c_passthru_protect response; + struct ec_params_i2c_passthru_protect status_params = { + .port = I2C_PORT_SENSOR, + .subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_STATUS, + }; + struct host_cmd_handler_args status_args = BUILD_HOST_COMMAND( + EC_CMD_I2C_PASSTHRU_PROTECT, 0, response, status_params); + struct ec_params_i2c_passthru_protect enable_params = { + .port = I2C_PORT_SENSOR, + .subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE, + }; + struct host_cmd_handler_args enable_args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_I2C_PASSTHRU_PROTECT, 0, enable_params); + + /* Check the protect status: 0 (unprotected) */ + zassert_ok(host_command_process(&status_args), NULL); + zassert_ok(status_args.result, NULL); + zassert_equal(status_args.response_size, sizeof(response), NULL); + zassert_equal(response.status, 0, "response.status = %d", + response.status); + + /* Protect the bus */ + zassert_ok(host_command_process(&enable_args), NULL); + zassert_ok(enable_args.result, NULL); + + /* Check the protect status: 1 (protected) */ + zassert_ok(host_command_process(&status_args), NULL); + zassert_ok(status_args.result, NULL); + zassert_equal(status_args.response_size, sizeof(response), NULL); + zassert_equal(response.status, 1, "response.status = %d", + response.status); + + /* Error case: wrong subcmd */ + status_params.subcmd = 10; + zassert_equal(host_command_process(&status_args), + EC_RES_INVALID_COMMAND, NULL); + status_params.subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_STATUS; + + /* Error case: wrong port */ + status_params.port = 10; + zassert_equal(host_command_process(&status_args), EC_RES_INVALID_PARAM, + NULL); + status_params.port = I2C_PORT_SENSOR; + + /* Error case: response size not enough */ + status_args.response_max = 0; + zassert_equal(host_command_process(&status_args), EC_RES_INVALID_PARAM, + NULL); + status_args.response_max = sizeof(response); + + /* Error case: params size not enough */ + status_args.params_size = 0; + zassert_equal(host_command_process(&status_args), EC_RES_INVALID_PARAM, + NULL); + status_args.params_size = sizeof(status_params); +} + +ZTEST_USER(i2c_passthru, test_passthru_protect_tcpcs) +{ + struct ec_params_i2c_passthru_protect enable_params = { + .port = I2C_PORT_SENSOR, + .subcmd = EC_CMD_I2C_PASSTHRU_PROTECT_ENABLE_TCPCS, + }; + struct host_cmd_handler_args enable_args = BUILD_HOST_COMMAND_PARAMS( + EC_CMD_I2C_PASSTHRU_PROTECT, 0, enable_params); + + /* Protect the all TCPC buses */ + zassert_ok(host_command_process(&enable_args), NULL); + zassert_ok(enable_args.result, NULL); +} + +static void i2c_passthru_after(void *state) +{ + ARG_UNUSED(state); + i2c_passthru_protect_reset(); +} + +ZTEST_SUITE(i2c_passthru, drivers_predicate_post_main, NULL, NULL, + i2c_passthru_after, NULL); |