summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/src/host_cmd/motion_sense.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/drivers/src/host_cmd/motion_sense.c')
-rw-r--r--zephyr/test/drivers/src/host_cmd/motion_sense.c130
1 files changed, 128 insertions, 2 deletions
diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c
index 3e4c8e0336..4063007401 100644
--- a/zephyr/test/drivers/src/host_cmd/motion_sense.c
+++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c
@@ -16,8 +16,13 @@
(sizeof(struct ec_response_motion_sense) + \
n * sizeof(struct ec_response_motion_sensor_data))
-ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, NULL, NULL,
- NULL, NULL);
+static void host_cmd_motion_sense_before(void *state)
+{
+ motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate = 1000 * MSEC;
+}
+
+ZTEST_SUITE(host_cmd_motion_sense, drivers_predicate_post_main, NULL,
+ host_cmd_motion_sense_before, NULL, NULL);
ZTEST_USER(host_cmd_motion_sense, test_dump)
{
@@ -64,3 +69,124 @@ 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);
+}
+
+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);
+ }
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_ec_rate__invalid_sensor_num)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_equal(host_cmd_motion_sense_ec_rate(
+ /*sensor_num=*/0xff,
+ /*data_rate_ms=*/EC_MOTION_SENSE_NO_VALUE,
+ &response),
+ EC_RES_INVALID_PARAM, NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_ec_rate)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_ok(host_cmd_motion_sense_ec_rate(
+ /*sensor_num=*/0,
+ /*data_rate_ms=*/EC_MOTION_SENSE_NO_VALUE,
+ &response),
+ NULL);
+ zassert_equal(response.ec_rate.ret, 1000, NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_set_ec_rate)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_ok(host_cmd_motion_sense_ec_rate(
+ /*sensor_num=*/0, /*data_rate_ms=*/2000, &response),
+ NULL);
+ /* The command should return the previous rate */
+ zassert_equal(response.ec_rate.ret, 1000, NULL);
+ /* The sensor's AP config value should be updated */
+ zassert_equal(motion_sensors[0].config[SENSOR_CONFIG_AP].ec_rate,
+ 2000 * MSEC, NULL);
+}