diff options
author | Tristan Honscheid <honscheid@google.com> | 2021-10-04 15:16:48 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-05 22:03:14 +0000 |
commit | 9e0193c18bcf86ad43f7343e6efe5b0b43f6f99b (patch) | |
tree | 10cb4e3b516691b817ac3a541face0add707f9ea | |
parent | 1737e04d766b5d6be543960271b5e781cb9c9235 (diff) | |
download | chrome-ec-9e0193c18bcf86ad43f7343e6efe5b0b43f6f99b.tar.gz |
zephyr: Add test for `st_raw_read_n_noinc()`
Add a unit test for `st_raw_read_n_noinc()` in `stm_mems_common.c` and
a clarifying comment to `test_st_raw_read_n()`
BUG=b:200589041
BRANCH=None
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: I55bfacaf139283705765ad236807d9b871d77429
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3203630
Reviewed-by: Yuval Peress <peress@google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | zephyr/test/drivers/src/stm_mems_common.c | 36 |
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); } |