summaryrefslogtreecommitdiff
path: root/zephyr/test
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-11-22 12:43:54 -0700
committerCommit Bot <commit-bot@chromium.org>2021-12-08 18:51:47 +0000
commitff99f9407aca97ca1c4e6055552f25817205598d (patch)
tree6b7188c8c76ba0b90193c25218acc5cc870b9ee5 /zephyr/test
parent60b21a3cd67324e967e1be4d18e8e7beaebf49a8 (diff)
downloadchrome-ec-ff99f9407aca97ca1c4e6055552f25817205598d.tar.gz
zephyr: lis2dw12: Add tests for set_power_mode()
* Export set_power_mode() in case of unit tests. We need direct access to this function in order to exercise all of this cases, because it is only ever called within the driver using fixed args that don't hit all cases. * Rename set_power_mode() to lis2dw12_set_power_mode to prevent naming collisions * Add a test BRANCH=None BUG=b:200046770 TEST=zmake -D configure --test test-drivers; make runhosttests Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I96b102c5a1a4c2524b775a32587afe16675a3cd1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3296683 Reviewed-by: Aaron Massey <aaronmassey@google.com> Tested-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Tristan Honscheid <honscheid@google.com>
Diffstat (limited to 'zephyr/test')
-rw-r--r--zephyr/test/drivers/src/lis2dw12.c39
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);
}