From 75095f18a888cf800bb9041cc23b8da018373f58 Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Thu, 7 Apr 2022 22:35:01 -0600 Subject: ztest: motion_sense: add tests for the data subcommand Add tests for both code paths of the data subcommand (an invalid sensor number and a valid one). Verify that the result contains the right data. BRANCH=none BUG=b:224614211 TEST=zmake test --coverage test-drivers Signed-off-by: Yuval Peress Change-Id: Ib69621037daa758c40e2de3bac88b12171571dab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3578292 Reviewed-by: Tristan Honscheid --- zephyr/test/drivers/include/test/drivers/utils.h | 10 ++++++++++ zephyr/test/drivers/src/host_cmd/motion_sense.c | 23 +++++++++++++++++++++++ zephyr/test/drivers/src/utils.c | 15 +++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index 6d5d0c33bf..b476e4e322 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -226,6 +226,16 @@ host_cmd_get_charge_control(void) void host_cmd_motion_sense_dump(int max_sensor_count, struct ec_response_motion_sense *response); +/** + * @brief Call the host command MOTION_SENSE with the data sub-command + * + * @param sensor_num The sensor index in the motion_sensors array to query + * @param response Pointer to the response data structure to fill on success + * @return The result code from the host command + */ +int host_cmd_motion_sense_data(uint8_t sensor_num, + struct ec_response_motion_sense *response); + /** * Run the host command to get the PD discovery responses. * diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c index 3e4c8e0336..64e18ef11a 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -64,3 +64,26 @@ ZTEST_USER(host_cmd_motion_sense, test_dump__large_max_sensor_count) zassert_equal(result->dump.sensor_count, ALL_MOTION_SENSORS, NULL); } + +ZTEST_USER(host_cmd_motion_sense, test_read_data__invalid_sensor_num) +{ + struct ec_response_motion_sense response; + + zassert_equal(host_cmd_motion_sense_data(UINT8_MAX, &response), + EC_RES_INVALID_PARAM, NULL); +} + +ZTEST_USER(host_cmd_motion_sense, test_read_data) +{ + struct ec_response_motion_sense response; + + motion_sensors[0].xyz[0] = 1; + motion_sensors[0].xyz[1] = 2; + motion_sensors[0].xyz[2] = 3; + + zassert_ok(host_cmd_motion_sense_data(0, &response), NULL); + zassert_equal(response.data.flags, 0, NULL); + zassert_equal(response.data.data[0], 1, NULL); + zassert_equal(response.data.data[1], 2, NULL); + zassert_equal(response.data.data[2], 3, NULL); +} diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index ef2084ab07..bb0fcec6ad 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -112,6 +112,21 @@ void host_cmd_motion_sense_dump(int max_sensor_count, "Failed to get motion_sense dump"); } +int host_cmd_motion_sense_data(uint8_t sensor_num, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_DATA, + .sensor_odr = { + .sensor_num = sensor_num, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 4, *response, params); + + return host_command_process(&args); +} + void host_cmd_typec_discovery(int port, enum typec_partner_type partner_type, void *response, size_t response_size) { -- cgit v1.2.1