diff options
author | Tristan Honscheid <honscheid@google.com> | 2021-10-04 15:51:57 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-06 23:10:29 +0000 |
commit | d176f0270c4dbcf1c81ae97bf2fac44d38dd4ed5 (patch) | |
tree | 4c2488f0bb7971feaada1fe42e03fade541a58ca | |
parent | 793e9a859327d4c282587459362143c367850207 (diff) | |
download | chrome-ec-d176f0270c4dbcf1c81ae97bf2fac44d38dd4ed5.tar.gz |
zephyr: Add tests for `st_get_resolution()` and `st_get_data_rate()`
Add unit tests for `st_get_resolution()` and `st_get_data_rate()`.
BUG=b:200589041
BRANCH=None
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: I3d6ff3b10d028f137764350db58b444f5a645b6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3203592
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/test/drivers/src/stm_mems_common.c | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/stm_mems_common.c b/zephyr/test/drivers/src/stm_mems_common.c index 701a573f79..8ae5d860bf 100644 --- a/zephyr/test/drivers/src/stm_mems_common.c +++ b/zephyr/test/drivers/src/stm_mems_common.c @@ -172,6 +172,44 @@ static void test_st_write_data_with_mask(void) "mock_write_fn was not called."); } +static void test_st_get_resolution(void) +{ + int expected_resolution = 123; + int rv; + + struct stprivate_data driver_data = { + .resol = expected_resolution, + }; + + const struct motion_sensor_t sensor = { + .drv_data = &driver_data, + }; + + rv = st_get_resolution(&sensor); + zassert_equal(rv, expected_resolution, "rv is %d but expected %d", rv, + expected_resolution); +} + +static void test_st_get_data_rate(void) +{ + int expected_data_rate = 456; + int rv; + + struct stprivate_data driver_data = { + .base = { + .odr = expected_data_rate, + }, + }; + + const struct motion_sensor_t sensor = { + .drv_data = &driver_data, + }; + + rv = st_get_data_rate(&sensor); + zassert_equal(rv, expected_data_rate, "rv is %d but expected %d", rv, + expected_data_rate); +} + void test_suite_stm_mems_common(void) { ztest_test_suite( @@ -181,6 +219,8 @@ void test_suite_stm_mems_common(void) ztest_unit_test_setup_teardown(test_st_raw_read_n_noinc, setup, unit_test_noop), ztest_unit_test_setup_teardown(test_st_write_data_with_mask, - setup, unit_test_noop)); + setup, unit_test_noop), + ztest_unit_test(test_st_get_resolution), + ztest_unit_test(test_st_get_data_rate)); ztest_run_test_suite(stm_mems_common); } |