diff options
author | Yuval Peress <peress@google.com> | 2022-05-02 16:21:10 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-03 19:38:48 +0000 |
commit | 1913306bbef3310807d4c87a5fe1a10fc6b9caf6 (patch) | |
tree | 987d32c966e36ecb8f79e8c67d7852081b91c5c2 | |
parent | 0377065b1576882a741cc2381e153d75f74c85d6 (diff) | |
download | chrome-ec-1913306bbef3310807d4c87a5fe1a10fc6b9caf6.tar.gz |
test: add tests for motion sense fifo flush host command
BRANCH=none
BUG=b:224614211
TEST=zmake test test-drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: I69416df51b69b79b714c7a6529b65c638c237c75
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3621798
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/test/drivers/include/test/drivers/utils.h | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/src/host_cmd/motion_sense.c | 30 | ||||
-rw-r--r-- | zephyr/test/drivers/src/utils.c | 15 |
3 files changed, 55 insertions, 0 deletions
diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index 46a39dbc93..a3be9f3281 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -365,6 +365,16 @@ int host_cmd_motion_sense_calib(uint8_t sensor_num, bool enable, struct ec_response_motion_sense *response); /** + * @brief Set the sensor's fifo flush bit + * + * @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_fifo_flush(uint8_t sensor_num, + struct ec_response_motion_sense *response); + +/** * Run the host command to get the PD discovery responses. * * @param port The USB-C port number diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c index 44f68b6b38..245769265c 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -6,6 +6,7 @@ #include <fff.h> #include <ztest.h> +#include "atomic.h" #include "driver/accel_bma2x2.h" #include "motion_sense.h" #include "test/drivers/test_state.h" @@ -29,6 +30,10 @@ FAKE_VALUE_FUNC(int, mock_perform_calib, struct motion_sensor_t *, int); (sizeof(struct ec_response_motion_sense) + \ n * sizeof(struct ec_response_motion_sensor_data)) +#define RESPONSE_SENSOR_FIFO_SIZE(n) \ + (sizeof(struct ec_response_motion_sense) + \ + n * sizeof(uint16_t)) + struct host_cmd_motion_sense_fixture { const struct accelgyro_drv *sensor_0_drv; struct accelgyro_drv mock_drv; @@ -63,6 +68,7 @@ static void host_cmd_motion_sense_before(void *fixture) RESET_FAKE(mock_perform_calib); FFF_RESET_HISTORY(); + atomic_clear(&motion_sensors[0].flush_pending); motion_sensors[0].config[SENSOR_CONFIG_AP].odr = 0; motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 1000 * MSEC; } @@ -638,3 +644,27 @@ ZTEST_USER_F(host_cmd_motion_sense, test_calib) zassert_equal(1, mock_get_offset_fake.call_count, NULL); zassert_true(mock_perform_calib_fake.arg1_history[0], NULL); } + +ZTEST(host_cmd_motion_sense, test_fifo_flush__invalid_sensor_num) +{ + int rv; + struct ec_response_motion_sense response; + + rv = host_cmd_motion_sense_fifo_flush(/*sensor_num=*/0xff, &response); + zassert_equal(rv, EC_RES_INVALID_PARAM, NULL); +} + +ZTEST(host_cmd_motion_sense, test_fifo_flush) +{ + uint8_t response_buffer[RESPONSE_SENSOR_FIFO_SIZE(ALL_MOTION_SENSORS)]; + struct ec_response_motion_sense *response = + (struct ec_response_motion_sense *)response_buffer; + + motion_sensors[0].lost = 5; + zassert_ok(host_cmd_motion_sense_fifo_flush(/*sensor_num=*/0, + response), + NULL); + zassert_equal(1, motion_sensors[0].flush_pending, NULL); + zassert_equal(5, response->fifo_info.lost[0], NULL); + zassert_equal(0, motion_sensors[0].lost, NULL); +} diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index 0829e4c874..ee90b41876 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -249,6 +249,21 @@ int host_cmd_motion_sense_calib(uint8_t sensor_num, bool enable, return host_command_process(&args); } +int host_cmd_motion_sense_fifo_flush(uint8_t sensor_num, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_FLUSH, + .sensor_odr = { + .sensor_num = sensor_num, + }, + }; + struct host_cmd_handler_args args = BUILD_HOST_COMMAND( + EC_CMD_MOTION_SENSE_CMD, 1, *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) { |