summaryrefslogtreecommitdiff
path: root/zephyr/test
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-12-06 15:48:44 -0700
committerCommit Bot <commit-bot@chromium.org>2021-12-08 19:43:36 +0000
commitc9728f47023b468a963228e4ada9d38bc121b6b0 (patch)
tree017f3b4acbd4f85190740f90ba2cefe5d90fdb48 /zephyr/test
parentf9e16502a9d6eea20f4c92375ff3a17fbdb9143a (diff)
downloadchrome-ec-c9728f47023b468a963228e4ada9d38bc121b6b0.tar.gz
zephyr: lis2dw12: Finish init() tests
Add tests for the remainder of the LIS2DW12 init() function. Also added the CTRL3 register to the emulator since this is accessed in the init routine. BRANCH=None BUG=b:200046770 TEST=zmake -D configure --test test-drivers; make runhosttests Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Iacb767f384474801c69159476a5ce446df1f9ae0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3318820 Reviewed-by: Aaron Massey <aaronmassey@google.com>
Diffstat (limited to 'zephyr/test')
-rw-r--r--zephyr/test/drivers/src/lis2dw12.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/lis2dw12.c b/zephyr/test/drivers/src/lis2dw12.c
index 56521f8085..24218aea9f 100644
--- a/zephyr/test/drivers/src/lis2dw12.c
+++ b/zephyr/test/drivers/src/lis2dw12.c
@@ -122,6 +122,69 @@ static void test_lis2dw12_init__fail_set_bdu(void)
"expected at least one soft reset");
}
+static void test_lis2dw12_init__fail_set_lir(void)
+{
+ const struct emul *emul = emul_get_binding(EMUL_LABEL);
+ struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
+ int rv;
+
+ i2c_common_emul_set_read_fail_reg(lis2dw12_emul_to_i2c_emul(emul),
+ LIS2DW12_LIR_ADDR);
+
+ rv = ms->drv->init(ms);
+ zassert_equal(EC_ERROR_INVAL, rv, "init returned %d but expected %d",
+ rv, EC_ERROR_INVAL);
+ zassert_true(lis2dw12_emul_get_soft_reset_count(emul) > 0,
+ "expected at least one soft reset");
+}
+
+static int lis2dw12_test_mock_write_fail_set_power_mode(struct i2c_emul *emul,
+ int reg, uint8_t val,
+ int bytes, void *data)
+{
+ if (reg == LIS2DW12_ACC_LPMODE_ADDR && bytes == 1 &&
+ (val & LIS2DW12_ACC_LPMODE_MASK) != 0) {
+ /* Cause an error when trying to set the LPMODE */
+ return -EIO;
+ }
+ return 1;
+}
+
+static void test_lis2dw12_init__fail_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;
+
+ i2c_common_emul_set_write_func(
+ lis2dw12_emul_to_i2c_emul(emul),
+ lis2dw12_test_mock_write_fail_set_power_mode, NULL);
+
+ rv = ms->drv->init(ms);
+ zassert_equal(EC_ERROR_INVAL, rv, "init returned %d but expected %d",
+ rv, EC_ERROR_INVAL);
+ zassert_true(lis2dw12_emul_get_soft_reset_count(emul) > 0,
+ "expected at least one soft reset");
+}
+
+static void test_lis2dw12_init__success(void)
+{
+ const struct emul *emul = emul_get_binding(EMUL_LABEL);
+ struct motion_sensor_t *ms = &motion_sensors[LIS2DW12_SENSOR_ID];
+ struct stprivate_data *drvdata = ms->drv_data;
+
+ int rv;
+
+ rv = ms->drv->init(ms);
+ zassert_equal(EC_SUCCESS, rv, "init returned %d but expected %d", rv,
+ EC_SUCCESS);
+ zassert_true(lis2dw12_emul_get_soft_reset_count(emul) > 0,
+ "expected at least one soft reset");
+ zassert_equal(LIS2DW12_RESOLUTION, drvdata->resol,
+ "Expected resolution of %d but got %d",
+ LIS2DW12_RESOLUTION, drvdata->resol);
+}
+
static void test_lis2dw12_set_power_mode(void)
{
const struct emul *emul = emul_get_binding(EMUL_LABEL);
@@ -384,6 +447,15 @@ void test_suite_lis2dw12(void)
test_lis2dw12_init__fail_set_bdu,
lis2dw12_setup, lis2dw12_setup),
ztest_unit_test_setup_teardown(
+ test_lis2dw12_init__fail_set_lir,
+ lis2dw12_setup, lis2dw12_setup),
+ ztest_unit_test_setup_teardown(
+ test_lis2dw12_init__fail_set_power_mode,
+ lis2dw12_setup, lis2dw12_setup),
+ ztest_unit_test_setup_teardown(
+ test_lis2dw12_init__success,
+ lis2dw12_setup, lis2dw12_setup),
+ ztest_unit_test_setup_teardown(
test_lis2dw12_set_power_mode,
lis2dw12_setup, lis2dw12_setup),
ztest_unit_test_setup_teardown(