diff options
Diffstat (limited to 'zephyr/test/drivers/src/lis2dw12.c')
-rw-r--r-- | zephyr/test/drivers/src/lis2dw12.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/zephyr/test/drivers/src/lis2dw12.c b/zephyr/test/drivers/src/lis2dw12.c index 287430e65b..c6117e2191 100644 --- a/zephyr/test/drivers/src/lis2dw12.c +++ b/zephyr/test/drivers/src/lis2dw12.c @@ -97,23 +97,52 @@ static void test_lis2dw12_init__fail_set_bdu(void) "expected at least one soft reset"); } +static void test_lis2dw12_set_power_mode(void) +{ + const struct emul *emul = emul_get_binding(EMUL_LABEL); + struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID]; + int rv; + + /* Part 1: happy path */ + rv = lis2dw12_set_power_mode(ms, LIS2DW12_LOW_POWER, + LIS2DW12_LOW_POWER_MODE_2); + zassert_equal(rv, EC_SUCCESS, "Expected %d but got %d", EC_SUCCESS, rv); + + /* Part 2: unimplemented modes */ + rv = lis2dw12_set_power_mode(ms, LIS2DW12_LOW_POWER, + LIS2DW12_LOW_POWER_MODE_1); + zassert_equal(rv, EC_ERROR_UNIMPLEMENTED, "Expected %d but got %d", + EC_ERROR_UNIMPLEMENTED, rv); + + /* Part 3: attempt to set mode but cannot modify reg. */ + i2c_common_emul_set_read_fail_reg(lis2dw12_emul_to_i2c_emul(emul), + LIS2DW12_ACC_MODE_ADDR); + rv = lis2dw12_set_power_mode(ms, LIS2DW12_LOW_POWER, + LIS2DW12_LOW_POWER_MODE_2); + zassert_equal(rv, EC_ERROR_INVAL, "Expected %d but got %d", + EC_ERROR_INVAL, rv); +} + void test_suite_lis2dw12(void) { ztest_test_suite(lis2dw12, ztest_unit_test_setup_teardown( test_lis2dw12_init__fail_read_who_am_i, - lis2dw12_setup, unit_test_noop), + lis2dw12_setup, lis2dw12_setup), ztest_unit_test_setup_teardown( test_lis2dw12_init__fail_who_am_i, - lis2dw12_setup, unit_test_noop), + lis2dw12_setup, lis2dw12_setup), ztest_unit_test_setup_teardown( test_lis2dw12_init__fail_write_soft_reset, - lis2dw12_setup, unit_test_noop), + lis2dw12_setup, lis2dw12_setup), ztest_unit_test_setup_teardown( test_lis2dw12_init__timeout_read_soft_reset, - lis2dw12_setup, unit_test_noop), + lis2dw12_setup, lis2dw12_setup), ztest_unit_test_setup_teardown( test_lis2dw12_init__fail_set_bdu, - lis2dw12_setup, unit_test_noop)); + lis2dw12_setup, lis2dw12_setup), + ztest_unit_test_setup_teardown( + test_lis2dw12_set_power_mode, + lis2dw12_setup, lis2dw12_setup)); ztest_run_test_suite(lis2dw12); } |