summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-04-07 22:35:01 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-12 00:17:20 +0000
commit75095f18a888cf800bb9041cc23b8da018373f58 (patch)
tree7a66c6d45797092a0aaae602b0a8f789404ea7ff
parent7d04c7a1acd9e2eb20b36d4d31fd7aa692507d65 (diff)
downloadchrome-ec-75095f18a888cf800bb9041cc23b8da018373f58.tar.gz
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 <peress@google.com> Change-Id: Ib69621037daa758c40e2de3bac88b12171571dab Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3578292 Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/test/drivers/include/test/drivers/utils.h10
-rw-r--r--zephyr/test/drivers/src/host_cmd/motion_sense.c23
-rw-r--r--zephyr/test/drivers/src/utils.c15
3 files changed, 48 insertions, 0 deletions
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
@@ -227,6 +227,16 @@ 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.
*
* @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 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)
{