summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/src/isl923x.c
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-12-13 15:27:07 -0700
committerCommit Bot <commit-bot@chromium.org>2021-12-16 23:58:06 +0000
commit32dbddfa436185e707ab006c3d6fdff00de339ac (patch)
treec642af27295823d288703d85e863c6cc97f13680 /zephyr/test/drivers/src/isl923x.c
parent84d75fc81b32c9b331e9fd3d16be54d9dfaad023 (diff)
downloadchrome-ec-32dbddfa436185e707ab006c3d6fdff00de339ac.tar.gz
zephyr: isl923x: Test hibernation (reg write errors)
* Test raa489000_hibernate() but fail at each of the register writes. BRANCH=None BUG=b:184856906 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ie88a7556cb17b0cd53f6b16ea49a62d697cdb823 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3335877 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.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index d734d33f32..453c925a8b 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -861,6 +861,93 @@ static void test_isl923x_hibernate__invalid_charger_number(void)
"No I2C writes should have happened");
}
+static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL0);
+
+ raa489000_hibernate(CHARGER_NUM, false);
+
+ /*
+ * We have no return codes to check, so instead verify that the first
+ * successful I2C write is to CONTROL1 and not CONTROL0.
+ */
+
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 0, ISL923X_REG_CONTROL1,
+ MOCK_IGNORE_VALUE);
+}
+
+static void test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL923X_REG_CONTROL1);
+
+ raa489000_hibernate(CHARGER_NUM, false);
+
+ /*
+ * Ensure we skipped CONTROL1. (NB: due to 16-bit regs, each write takes
+ * two calls to the mock_write_fn)
+ */
+
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 0, ISL923X_REG_CONTROL0,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 1, ISL923X_REG_CONTROL0,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 2, ISL9238_REG_CONTROL3,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 3, ISL9238_REG_CONTROL3,
+ MOCK_IGNORE_VALUE);
+}
+
+static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL9238_REG_CONTROL3);
+
+ raa489000_hibernate(CHARGER_NUM, false);
+
+ /*
+ * Ensure we skipped CONTROL3. (NB: due to 16-bit regs, each write takes
+ * two calls to the mock_write_fn)
+ */
+
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 2, ISL923X_REG_CONTROL1,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 3, ISL923X_REG_CONTROL1,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 4, ISL9238_REG_CONTROL4,
+ MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn, 5, ISL9238_REG_CONTROL4,
+ MOCK_IGNORE_VALUE);
+}
+
+static void test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+
+ i2c_common_emul_set_read_fail_reg(i2c_emul, ISL9238_REG_CONTROL4);
+
+ raa489000_hibernate(CHARGER_NUM, false);
+
+ /*
+ * Ensure we skipped CONTROL4. (i.e. the last calls should be to write
+ * to CONTROL3)
+ */
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn,
+ hibernate_mock_write_fn_fake.call_count - 2,
+ ISL9238_REG_CONTROL3, MOCK_IGNORE_VALUE);
+ MOCK_ASSERT_I2C_WRITE(hibernate_mock_write_fn,
+ hibernate_mock_write_fn_fake.call_count - 1,
+ ISL9238_REG_CONTROL3, MOCK_IGNORE_VALUE);
+}
+
void test_suite_isl923x(void)
{
ztest_test_suite(
@@ -884,6 +971,18 @@ void test_suite_isl923x(void)
hibernate_test_setup, hibernate_test_teardown),
ztest_unit_test_setup_teardown(
test_isl923x_hibernate__invalid_charger_number,
+ hibernate_test_setup, hibernate_test_teardown),
+ ztest_unit_test_setup_teardown(
+ test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL0,
+ hibernate_test_setup, hibernate_test_teardown),
+ ztest_unit_test_setup_teardown(
+ test_isl923x_hibernate__fail_at_ISL923X_REG_CONTROL1,
+ hibernate_test_setup, hibernate_test_teardown),
+ ztest_unit_test_setup_teardown(
+ test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL3,
+ hibernate_test_setup, hibernate_test_teardown),
+ ztest_unit_test_setup_teardown(
+ test_isl923x_hibernate__fail_at_ISL9238_REG_CONTROL4,
hibernate_test_setup, hibernate_test_teardown));
ztest_run_test_suite(isl923x);
}