summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/test/drivers/src/stm_mems_common.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/zephyr/test/drivers/src/stm_mems_common.c b/zephyr/test/drivers/src/stm_mems_common.c
index 3085007f4d..464fdb9b38 100644
--- a/zephyr/test/drivers/src/stm_mems_common.c
+++ b/zephyr/test/drivers/src/stm_mems_common.c
@@ -36,6 +36,10 @@ static void test_st_raw_read_n(void)
int rv;
i2c_common_emul_set_read_func(i2c_emul, mock_read_fn, NULL);
+ /*
+ * Ensure the MSb (auto-increment bit) in the register address gets
+ * set, but also return an error condition
+ */
ztest_expect_value(mock_read_fn, reg, 0x80);
ztest_expect_value(mock_read_fn, bytes, 0);
ztest_returns_value(mock_read_fn, -EIO);
@@ -46,11 +50,35 @@ static void test_st_raw_read_n(void)
EC_ERROR_INVAL);
}
+static void test_st_raw_read_n_noinc(void)
+{
+ const struct emul *emul = MOCK_EMUL;
+ struct i2c_emul *i2c_emul = i2c_mock_to_i2c_emul(emul);
+ int rv;
+
+ i2c_common_emul_set_read_func(i2c_emul, mock_read_fn, NULL);
+ /*
+ * Unlike `st_raw_read_n`, the MSb (auto-increment bit) in the register
+ * address should NOT be automatically set. Also return an error.
+ */
+ ztest_expect_value(mock_read_fn, reg, 0x00);
+ ztest_expect_value(mock_read_fn, bytes, 0);
+ ztest_returns_value(mock_read_fn, -EIO);
+
+ rv = st_raw_read_n_noinc(I2C_PORT_POWER, i2c_mock_get_addr(emul), 0,
+ NULL, 2);
+ /* The shim layer translates -EIO to EC_ERROR_INVAL. */
+ zassert_equal(rv, EC_ERROR_INVAL, "rv was %d but expected %d", rv,
+ EC_ERROR_INVAL);
+}
+
void test_suite_stm_mems_common(void)
{
- ztest_test_suite(stm_mems_common,
- ztest_unit_test_setup_teardown(
- test_st_raw_read_n,
- setup, unit_test_noop));
+ ztest_test_suite(
+ stm_mems_common,
+ ztest_unit_test_setup_teardown(test_st_raw_read_n, setup,
+ unit_test_noop),
+ ztest_unit_test_setup_teardown(test_st_raw_read_n_noinc, setup,
+ unit_test_noop));
ztest_run_test_suite(stm_mems_common);
}