diff options
author | Yuval Peress <peress@google.com> | 2021-09-30 11:32:35 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-02 02:28:10 +0000 |
commit | 1b804b2e071c9fd520ac12de3d493cb2a1f28baf (patch) | |
tree | 98396cb2e23c21d6984c4cc1fa1f9121d9e8b61f /zephyr/test/drivers/src/isl923x.c | |
parent | a7ef9770338570a2ce71af97b80687844b109691 (diff) | |
download | chrome-ec-1b804b2e071c9fd520ac12de3d493cb2a1f28baf.tar.gz |
zephyr: test: verify isl923x get/set ctrl 0/1 registers
Test the code paths for the options in control 0 and 1 registers.
Including the expected bits 23 and 0 which will always be 0 when
reading.
BRANCH=none
BUG=b:201602829
TEST=zmake configure --test zephyr/test/drivers
Signed-off-by: Yuval Peress <peress@google.com>
Change-Id: I9fd4e00b8a3f6fcc7a7295f1084987b7bb493e56
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3198238
Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'zephyr/test/drivers/src/isl923x.c')
-rw-r--r-- | zephyr/test/drivers/src/isl923x.c | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c index d6a9fb0c59..022eccb98b 100644 --- a/zephyr/test/drivers/src/isl923x.c +++ b/zephyr/test/drivers/src/isl923x.c @@ -200,6 +200,47 @@ void test_device_id(void) I2C_COMMON_EMUL_NO_FAIL_REG); } +void test_options(void) +{ + const struct emul *isl923x_emul = ISL923X_EMUL; + struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul); + uint32_t option; + + /* Test failed control 0 read */ + i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL0); + zassert_equal(EC_ERROR_INVAL, + isl923x_drv.get_option(CHARGER_NUM, &option), NULL); + + /* Test failed control 1 read */ + i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL1); + zassert_equal(EC_ERROR_INVAL, + isl923x_drv.get_option(CHARGER_NUM, &option), NULL); + + /* Reset failed read */ + i2c_common_emul_set_read_fail_reg(i2c_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Test failed control 0 write */ + i2c_common_emul_set_write_fail_reg(i2c_emul, ISL923X_REG_CONTROL0); + zassert_equal(EC_ERROR_INVAL, + isl923x_drv.set_option(CHARGER_NUM, option), NULL); + + /* Test failed control 1 write */ + i2c_common_emul_set_write_fail_reg(i2c_emul, ISL923X_REG_CONTROL1); + zassert_equal(EC_ERROR_INVAL, + isl923x_drv.set_option(CHARGER_NUM, option), NULL); + + /* Reset failed write */ + i2c_common_emul_set_write_fail_reg(i2c_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Test normal write/read, note that bits 23 and 0 are always 0 */ + zassert_ok(isl923x_drv.set_option(CHARGER_NUM, 0xffffffff), NULL); + zassert_ok(isl923x_drv.get_option(CHARGER_NUM, &option), NULL); + zassert_equal(0xff7ffffe, option, + "Expected options 0xff7ffffe but got 0x%x", option); +} + void test_suite_isl923x(void) { ztest_test_suite(isl923x, @@ -207,6 +248,7 @@ void test_suite_isl923x(void) ztest_unit_test(test_isl923x_set_voltage), ztest_unit_test(test_isl923x_set_input_current_limit), ztest_unit_test(test_manufacturer_id), - ztest_unit_test(test_device_id)); + ztest_unit_test(test_device_id), + ztest_unit_test(test_options)); ztest_run_test_suite(isl923x); } |