summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-04-08 11:24:00 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-12 00:17:27 +0000
commitbaf8f7c1aff107f856042acb66dc2ec3f86624a7 (patch)
tree171462e199b39a33d3a23c4ff75f00a4a4be31fd
parent75095f18a888cf800bb9041cc23b8da018373f58 (diff)
downloadchrome-ec-baf8f7c1aff107f856042acb66dc2ec3f86624a7.tar.gz
ztest: motion_sense: add tests for the info subcommand
Add tests for all code paths of the info subcommand (an invalid sensor number and a valid one as well as all the different versions). 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: I81b38fddda52c64813b074e0645ab003282a5fdd Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3579626 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/test/drivers/include/test/drivers/utils.h11
-rw-r--r--zephyr/test/drivers/src/host_cmd/motion_sense.c61
-rw-r--r--zephyr/test/drivers/src/utils.c15
3 files changed, 87 insertions, 0 deletions
diff --git a/zephyr/test/drivers/include/test/drivers/utils.h b/zephyr/test/drivers/include/test/drivers/utils.h
index b476e4e322..a97e527a90 100644
--- a/zephyr/test/drivers/include/test/drivers/utils.h
+++ b/zephyr/test/drivers/include/test/drivers/utils.h
@@ -237,6 +237,17 @@ int host_cmd_motion_sense_data(uint8_t sensor_num,
struct ec_response_motion_sense *response);
/**
+ * @brief Call the host command MOTION_SENSE with the info sub-command
+ *
+ * @param cmd_version The command version
+ * @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_info(uint8_t cmd_version, 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 64e18ef11a..454ca66dcb 100644
--- a/zephyr/test/drivers/src/host_cmd/motion_sense.c
+++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c
@@ -87,3 +87,64 @@ ZTEST_USER(host_cmd_motion_sense, test_read_data)
zassert_equal(response.data.data[1], 2, NULL);
zassert_equal(response.data.data[2], 3, NULL);
}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_info__invalid_sensor_num)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_equal(host_cmd_motion_sense_info(/*cmd_version=*/1,
+ /*sensor_num=*/UINT8_MAX,
+ &response),
+ EC_RES_INVALID_PARAM, NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_info_v1)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_ok(host_cmd_motion_sense_info(/*cmd_version=*/1,
+ /*sensor_num=*/0, &response),
+ NULL);
+ zassert_equal(response.info.type, motion_sensors[0].type, NULL);
+ zassert_equal(response.info.location, motion_sensors[0].location, NULL);
+ zassert_equal(response.info.chip, motion_sensors[0].chip, NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_info_v3)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_ok(host_cmd_motion_sense_info(/*cmd_version=*/3,
+ /*sensor_num=*/0, &response),
+ NULL);
+ zassert_equal(response.info.type, motion_sensors[0].type, NULL);
+ zassert_equal(response.info.location, motion_sensors[0].location, NULL);
+ zassert_equal(response.info.chip, motion_sensors[0].chip, NULL);
+ zassert_equal(response.info_3.min_frequency,
+ motion_sensors[0].min_frequency, NULL);
+ zassert_equal(response.info_3.max_frequency,
+ motion_sensors[0].max_frequency, NULL);
+ zassert_equal(response.info_3.fifo_max_event_count,
+ CONFIG_ACCEL_FIFO_SIZE, NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_info_v4__no_read_temp)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_ok(host_cmd_motion_sense_info(/*cmd_version=*/4,
+ /*sensor_num=*/0, &response),
+ NULL);
+ zassert_equal(response.info.type, motion_sensors[0].type, NULL);
+ zassert_equal(response.info.location, motion_sensors[0].location, NULL);
+ zassert_equal(response.info.chip, motion_sensors[0].chip, NULL);
+ if (IS_ENABLED(CONFIG_ONLINE_CALIB)) {
+ zassert_true(response.info_4.flags &
+ MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB,
+ NULL);
+ } else {
+ zassert_false(response.info_4.flags &
+ MOTION_SENSE_CMD_INFO_FLAG_ONLINE_CALIB,
+ NULL);
+ }
+}
diff --git a/zephyr/test/drivers/src/utils.c b/zephyr/test/drivers/src/utils.c
index bb0fcec6ad..b86ae52375 100644
--- a/zephyr/test/drivers/src/utils.c
+++ b/zephyr/test/drivers/src/utils.c
@@ -127,6 +127,21 @@ int host_cmd_motion_sense_data(uint8_t sensor_num,
return host_command_process(&args);
}
+int host_cmd_motion_sense_info(uint8_t cmd_version, uint8_t sensor_num,
+ struct ec_response_motion_sense *response)
+{
+ struct ec_params_motion_sense params = {
+ .cmd = MOTIONSENSE_CMD_INFO,
+ .sensor_odr = {
+ .sensor_num = sensor_num,
+ },
+ };
+ struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
+ EC_CMD_MOTION_SENSE_CMD, cmd_version, *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)
{