summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2021-12-13 17:08:42 -0700
committerCommit Bot <commit-bot@chromium.org>2021-12-16 23:58:15 +0000
commit04dd51538cd9bc9a0f846366bff8928acff5c5e4 (patch)
tree72cab9eb9d9a3d3d2b1d8f7cba001769d0d94364
parent16ba0109a7ea0592f8a83c4695b963481783c82c (diff)
downloadchrome-ec-04dd51538cd9bc9a0f846366bff8928acff5c5e4.tar.gz
zephyr: isl923x: Test ISL9238C hibernation
* Test isl9238c_hibernate(), both happy path and with register access failures BRANCH=None BUG=b:184856906 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ic2b24953c7dfcc77b0fdaed3c8fc0c58fd0fd73e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3336697 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Tristan Honscheid <honscheid@google.com> Tested-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/test/drivers/src/isl923x.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c
index c94b11ac5f..c5b26f495b 100644
--- a/zephyr/test/drivers/src/isl923x.c
+++ b/zephyr/test/drivers/src/isl923x.c
@@ -968,6 +968,60 @@ static void test_isl923x_hibernate__adc_disable(void)
expected >> 8);
}
+static void test_isl9238c_hibernate(void)
+{
+ const struct emul *isl923x_emul = ISL923X_EMUL;
+ struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul);
+ uint16_t control1_expected, control2_expected, control3_expected;
+ int rv;
+
+ /* Part 1: Happy path */
+ control1_expected =
+ (isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL1) &
+ ~ISL923X_C1_ENABLE_PSYS) |
+ ISL923X_C1_DISABLE_MON;
+ control2_expected =
+ isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL2) |
+ ISL923X_C2_COMPARATOR;
+ control3_expected =
+ isl923x_emul_peek_reg(i2c_emul, ISL9238_REG_CONTROL3) |
+ ISL9238_C3_BGATE_OFF;
+
+ rv = isl9238c_hibernate(CHARGER_NUM);
+
+ zassert_equal(EC_SUCCESS, rv, "Expected return code %d but got %d",
+ EC_SUCCESS, rv);
+ zassert_equal(isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL1),
+ control1_expected,
+ "Unexpected register value 0x%02x. Should be 0x%02x",
+ isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL1),
+ control1_expected);
+ zassert_equal(isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL2),
+ control2_expected,
+ "Unexpected register value 0x%02x. Should be 0x%02x",
+ isl923x_emul_peek_reg(i2c_emul, ISL923X_REG_CONTROL2),
+ control2_expected);
+ zassert_equal(isl923x_emul_peek_reg(i2c_emul, ISL9238_REG_CONTROL3),
+ control3_expected,
+ "Unexpected register value 0x%02x. Should be 0x%02x",
+ isl923x_emul_peek_reg(i2c_emul, ISL9238_REG_CONTROL3),
+ control3_expected);
+
+ /* Part 2: Fail reading each register and check for error code */
+ int registers[] = { ISL923X_REG_CONTROL1, ISL923X_REG_CONTROL2,
+ ISL9238_REG_CONTROL3 };
+
+ for (int i = 0; i < ARRAY_SIZE(registers); i++) {
+ i2c_common_emul_set_read_fail_reg(i2c_emul, registers[i]);
+
+ rv = isl9238c_hibernate(CHARGER_NUM);
+
+ zassert_equal(EC_ERROR_INVAL, rv,
+ "Wrong return code. Expected %d but got %d",
+ EC_ERROR_INVAL, rv);
+ }
+}
+
void test_suite_isl923x(void)
{
ztest_test_suite(
@@ -1006,6 +1060,9 @@ void test_suite_isl923x(void)
hibernate_test_setup, hibernate_test_teardown),
ztest_unit_test_setup_teardown(
test_isl923x_hibernate__adc_disable,
- hibernate_test_setup, hibernate_test_teardown));
+ hibernate_test_setup, hibernate_test_teardown),
+ ztest_unit_test_setup_teardown(test_isl9238c_hibernate,
+ unit_test_noop,
+ hibernate_test_teardown));
ztest_run_test_suite(isl923x);
}