summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-09-30 23:52:18 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-05 14:22:19 +0000
commit536739789c90807168911c5cafdc90d51784b7f8 (patch)
tree3ed5dc10e66c042ce8e919a75a3514dba434c550
parent6bc606c6427b2aa8bad9de0e31afb887ad44dae5 (diff)
downloadchrome-ec-536739789c90807168911c5cafdc90d51784b7f8.tar.gz
zephyr: test: isl923x failure to read charge current reg
BRANCH=none BUG=b:201602829 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I7e4ed6327c3393f64153f4383002a2c9c38f57b1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3198687 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--zephyr/test/drivers/src/isl923x.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index c4d0bfc38b..f31423c9f2 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -41,6 +41,8 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_CHARGER_ISL9238),
void test_isl923x_set_current(void)
{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
int expected_current_milli_amps[] = {
EXPECTED_CURRENT_MA(0), EXPECTED_CURRENT_MA(4),
EXPECTED_CURRENT_MA(8), EXPECTED_CURRENT_MA(16),
@@ -49,18 +51,31 @@ void test_isl923x_set_current(void)
EXPECTED_CURRENT_MA(512), EXPECTED_CURRENT_MA(1024),
EXPECTED_CURRENT_MA(2048), EXPECTED_CURRENT_MA(4096)
};
- int current_mA;
+ int current_milli_amps;
+
+ /* Test I2C failure when reading charge current */
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CHG_CURRENT);
+ zassert_equal(EC_ERROR_INVAL,
+ isl923x_drv.get_current(CHARGER_NUM, &current_milli_amps),
+ NULL);
+
+ /* Reset fail register */
+ i2c_common_emul_set_read_fail_reg(i2c_emul,
+ I2C_COMMON_EMUL_NO_FAIL_REG);
for (int i = 0; i < ARRAY_SIZE(expected_current_milli_amps); ++i) {
zassert_ok(isl923x_drv.set_current(
CHARGER_NUM, expected_current_milli_amps[i]),
"Failed to set the current to %dmA",
expected_current_milli_amps[i]);
- zassert_ok(isl923x_drv.get_current(CHARGER_NUM, &current_mA),
+ zassert_ok(isl923x_drv.get_current(CHARGER_NUM,
+ &current_milli_amps),
"Failed to get current");
- zassert_equal(expected_current_milli_amps[i], current_mA,
+ zassert_equal(expected_current_milli_amps[i],
+ current_milli_amps,
"Expected current %dmA but got %dmA",
- expected_current_milli_amps[i], current_mA);
+ expected_current_milli_amps[i],
+ current_milli_amps);
}
}