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.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/host_cmd/motion_sense.c b/zephyr/test/drivers/src/host_cmd/motion_sense.c
index 3bfc39096b..170730d3d5 100644
--- a/zephyr/test/drivers/src/host_cmd/motion_sense.c
+++ b/zephyr/test/drivers/src/host_cmd/motion_sense.c
@@ -16,6 +16,10 @@ FAKE_VALUE_FUNC(int, mock_set_offset, const struct motion_sensor_t *,
const int16_t *, int16_t);
FAKE_VALUE_FUNC(int, mock_get_offset, const struct motion_sensor_t *, int16_t *,
int16_t *);
+FAKE_VALUE_FUNC(int, mock_set_scale, const struct motion_sensor_t *,
+ const uint16_t *, int16_t);
+FAKE_VALUE_FUNC(int, mock_get_scale, const struct motion_sensor_t *, uint16_t *,
+ int16_t *);
/**
* Get the size needed for a struct ec_response_motion_sense
@@ -34,6 +38,8 @@ static struct host_cmd_motion_sense_fixture fixture = {
.set_range = mock_set_range,
.set_offset = mock_set_offset,
.get_offset = mock_get_offset,
+ .set_scale = mock_set_scale,
+ .get_scale = mock_get_scale,
},
};
@@ -50,6 +56,8 @@ static void host_cmd_motion_sense_before(void *state)
RESET_FAKE(mock_set_range);
RESET_FAKE(mock_set_offset);
RESET_FAKE(mock_get_offset);
+ RESET_FAKE(mock_set_scale);
+ RESET_FAKE(mock_get_scale);
FFF_RESET_HISTORY();
motion_sensors[0].config[SENSOR_CONFIG_AP].odr = 0;
@@ -459,3 +467,106 @@ ZTEST_USER_F(host_cmd_motion_sense, test_get_offset)
zassert_equal(3, mock_set_offset_fake.arg1_history[0][1], NULL);
zassert_equal(4, mock_set_offset_fake.arg1_history[0][2], NULL);
}
+
+ZTEST_USER(host_cmd_motion_sense, test_scale_invalid_sensor_num)
+{
+ struct ec_response_motion_sense response;
+
+ zassert_equal(EC_RES_INVALID_PARAM,
+ host_cmd_motion_sense_scale(
+ /*sensor_num=*/0xff,
+ /*flags=*/0,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_get_scale_not_in_driver)
+{
+ struct ec_response_motion_sense response;
+ struct accelgyro_drv drv = *motion_sensors[0].drv;
+
+ drv.get_scale = NULL;
+ motion_sensors[0].drv = &drv;
+
+ zassert_equal(EC_RES_INVALID_COMMAND,
+ host_cmd_motion_sense_scale(
+ /*sensor_num=*/0,
+ /*flags=*/0,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+}
+
+ZTEST_USER(host_cmd_motion_sense, test_set_scale_not_in_driver)
+{
+ struct ec_response_motion_sense response;
+ struct accelgyro_drv drv = *motion_sensors[0].drv;
+
+ drv.set_scale = NULL;
+ motion_sensors[0].drv = &drv;
+
+ zassert_equal(EC_RES_INVALID_COMMAND,
+ host_cmd_motion_sense_scale(
+ /*sensor_num=*/0,
+ /*flags=*/MOTION_SENSE_SET_OFFSET,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+}
+
+ZTEST_USER_F(host_cmd_motion_sense, test_get_scale_fail)
+{
+ struct ec_response_motion_sense response;
+
+ motion_sensors[0].drv = &this->mock_drv;
+ mock_get_scale_fake.return_val = 1;
+
+ zassert_equal(1,
+ host_cmd_motion_sense_scale(
+ /*sensor_num=*/0,
+ /*flags=*/0,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+ zassert_equal(1, mock_get_scale_fake.call_count, NULL);
+}
+
+ZTEST_USER_F(host_cmd_motion_sense, test_set_scale_fail)
+{
+ struct ec_response_motion_sense response;
+
+ motion_sensors[0].drv = &this->mock_drv;
+ mock_set_scale_fake.return_val = 1;
+
+ zassert_equal(1,
+ host_cmd_motion_sense_scale(
+ /*sensor_num=*/0,
+ /*flags=*/MOTION_SENSE_SET_OFFSET,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+ zassert_equal(1, mock_set_scale_fake.call_count, NULL);
+}
+
+ZTEST_USER_F(host_cmd_motion_sense, test_set_get_scale)
+{
+ struct ec_response_motion_sense response;
+
+ motion_sensors[0].drv = &this->mock_drv;
+ mock_set_scale_fake.return_val = 0;
+ mock_get_scale_fake.return_val = 0;
+
+ zassert_ok(host_cmd_motion_sense_scale(
+ /*sensor_num=*/0,
+ /*flags=*/MOTION_SENSE_SET_OFFSET,
+ /*temperature=*/1, /*scale_x=*/2,
+ /*scale_y=*/3, /*scale_z=*/4, &response),
+ NULL);
+ zassert_equal(1, mock_set_scale_fake.call_count, NULL);
+ zassert_equal(1, mock_get_scale_fake.call_count, NULL);
+ zassert_equal(1, mock_set_scale_fake.arg2_history[0], NULL);
+ zassert_equal(2, mock_set_scale_fake.arg1_history[0][0], NULL);
+ zassert_equal(3, mock_set_scale_fake.arg1_history[0][1], NULL);
+ zassert_equal(4, mock_set_scale_fake.arg1_history[0][2], NULL);
+}