diff options
author | Yuval Peress <peress@google.com> | 2022-05-02 17:07:41 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-05-03 19:38:59 +0000 |
commit | 49c1700ab4ccb5bb01d95ae85cab6e340bfe735e (patch) | |
tree | 465e19dea1919e6aba3e07883b14d7e8b3a3a70f | |
parent | 24866f37b9ad93425aeeb93a130e5acc5873cc9b (diff) | |
download | chrome-ec-49c1700ab4ccb5bb01d95ae85cab6e340bfe735e.tar.gz |
test: add tests for motion sense fifo read host command
BRANCH=none
BUG=b:224614211
TEST=zmake test test-drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: Ib354e2f1832fde80d5ec38ad54091bbd342cf85b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3621800
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | zephyr/test/drivers/include/test/drivers/utils.h | 10 | ||||
-rw-r--r-- | zephyr/test/drivers/src/host_cmd/motion_sense.c | 56 | ||||
-rw-r--r-- | zephyr/test/drivers/src/utils.c | 15 |
3 files changed, 81 insertions, 0 deletions
diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h index d38eed3297..92ab8a69d7 100644 --- a/zephyr/test/drivers/include/test/drivers/utils.h +++ b/zephyr/test/drivers/include/test/drivers/utils.h @@ -383,6 +383,16 @@ int host_cmd_motion_sense_fifo_flush(uint8_t sensor_num, int host_cmd_motion_sense_fifo_info(struct ec_response_motion_sense *response); /** + * @brief Get the current fifo data + * + * @param buffer_length The number of entries available on the response pointer + * @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_read(uint8_t buffer_length, + 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 5b4b82b6d1..c5f946ded7 100644 --- a/zephyr/test/drivers/src/host_cmd/motion_sense.c +++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c @@ -9,6 +9,7 @@ #include "atomic.h" #include "driver/accel_bma2x2.h" #include "motion_sense.h" +#include "motion_sense_fifo.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" @@ -680,3 +681,58 @@ ZTEST(host_cmd_motion_sense, test_fifo_info) zassert_equal(4, response->fifo_info.lost[0], NULL); zassert_equal(0, motion_sensors[0].lost, NULL); } + +ZTEST(host_cmd_motion_sense, test_fifo_read) +{ + struct ec_response_motion_sensor_data data; + uint8_t response_buffer[RESPONSE_MOTION_SENSE_BUFFER_SIZE(2)]; + struct ec_response_motion_sense *response = + (struct ec_response_motion_sense *)response_buffer; + + motion_sensors[0].oversampling_ratio = 1; + motion_sensors[1].oversampling_ratio = 1; + + data = (struct ec_response_motion_sensor_data){ + .flags = 0, + .sensor_num = 0, + .data = { 0, 1, 2 }, + }; + motion_sense_fifo_stage_data(&data, &motion_sensors[0], 1, 0); + + data = (struct ec_response_motion_sensor_data){ + .flags = 0, + .sensor_num = 1, + .data = { 3, 4, 5 }, + }; + motion_sense_fifo_stage_data(&data, &motion_sensors[1], 1, 5); + motion_sense_fifo_commit_data(); + + /* Read 2 samples */ + zassert_ok(host_cmd_motion_sense_fifo_read(4, response), NULL); + zassert_equal(2, response->fifo_read.number_data, NULL); + + zassert_equal(MOTIONSENSE_SENSOR_FLAG_TIMESTAMP, + response->fifo_read.data[0].flags, NULL); + zassert_equal(0, response->fifo_read.data[0].sensor_num, NULL); + zassert_equal(0, response->fifo_read.data[0].timestamp, NULL); + + zassert_equal(0, response->fifo_read.data[1].flags, NULL); + zassert_equal(0, response->fifo_read.data[1].sensor_num, NULL); + zassert_equal(0, response->fifo_read.data[1].data[0], NULL); + zassert_equal(1, response->fifo_read.data[1].data[1], NULL); + zassert_equal(2, response->fifo_read.data[1].data[2], NULL); + + /* Read the next 2 samples */ + zassert_ok(host_cmd_motion_sense_fifo_read(4, response), NULL); + zassert_equal(2, response->fifo_read.number_data, NULL); + zassert_equal(MOTIONSENSE_SENSOR_FLAG_TIMESTAMP, + response->fifo_read.data[0].flags, NULL); + zassert_equal(1, response->fifo_read.data[0].sensor_num, NULL); + zassert_equal(5, response->fifo_read.data[0].timestamp, NULL); + + zassert_equal(0, response->fifo_read.data[1].flags, NULL); + zassert_equal(1, response->fifo_read.data[1].sensor_num, NULL); + zassert_equal(3, response->fifo_read.data[1].data[0], NULL); + zassert_equal(4, response->fifo_read.data[1].data[1], NULL); + zassert_equal(5, response->fifo_read.data[1].data[2], NULL); +} diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c index eb639f32b5..4aa5f3d219 100644 --- a/zephyr/test/drivers/src/utils.c +++ b/zephyr/test/drivers/src/utils.c @@ -275,6 +275,21 @@ int host_cmd_motion_sense_fifo_info(struct ec_response_motion_sense *response) return host_command_process(&args); } +int host_cmd_motion_sense_fifo_read(uint8_t buffer_length, + struct ec_response_motion_sense *response) +{ + struct ec_params_motion_sense params = { + .cmd = MOTIONSENSE_CMD_FIFO_READ, + .fifo_read = { + .max_data_vector = buffer_length, + }, + }; + 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) { |