From 53080524f2fdc69a9a843f8e12b365c1388c1dd5 Mon Sep 17 00:00:00 2001 From: Tristan Honscheid Date: Thu, 9 Dec 2021 13:49:54 -0700 Subject: zephyr: isl923x: Test raa489000_is_acok Test the raa489000_is_acok() function in the ISL923x driver BRANCH=None BUG=b:184856906 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid Change-Id: I59040f9f83047b71f3d232598389cd9c20920e32 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3327329 Reviewed-by: Abe Levkoy --- zephyr/test/drivers/src/isl923x.c | 40 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/zephyr/test/drivers/src/isl923x.c b/zephyr/test/drivers/src/isl923x.c index e1b1dbc020..4aad2ecd34 100644 --- a/zephyr/test/drivers/src/isl923x.c +++ b/zephyr/test/drivers/src/isl923x.c @@ -673,6 +673,43 @@ static void test_init(void) system_jumped_late_mock.ret_val = false; } +static void test_isl923x_is_acok(void) +{ + const struct emul *isl923x_emul = ISL923X_EMUL; + struct i2c_emul *i2c_emul = isl923x_emul_get_i2c_emul(isl923x_emul); + enum ec_error_list rv; + bool acok; + + /* Part 1: invalid charger number */ + rv = raa489000_is_acok(board_get_charger_chip_count() + 1, &acok); + zassert_equal(EC_ERROR_INVAL, rv, + "Invalid charger num, but AC OK check succeeded"); + + /* Part 2: error accessing register */ + i2c_common_emul_set_read_fail_reg(i2c_emul, ISL9238_REG_INFO2); + + rv = raa489000_is_acok(CHARGER_NUM, &acok); + zassert_equal(EC_ERROR_INVAL, rv, + "Register read failure, but AC OK check succeeded"); + + i2c_common_emul_set_read_fail_reg(i2c_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Part 3: successful path - ACOK is true */ + raa489000_emul_set_acok_pin(isl923x_emul, 1); + + rv = raa489000_is_acok(CHARGER_NUM, &acok); + zassert_equal(EC_SUCCESS, rv, "AC OK check did not return success"); + zassert_true(acok, "AC OK is false"); + + /* Part 3: successful path - ACOK is false */ + raa489000_emul_set_acok_pin(isl923x_emul, 0); + + rv = raa489000_is_acok(CHARGER_NUM, &acok); + zassert_equal(EC_SUCCESS, rv, "AC OK check did not return success"); + zassert_false(acok, "AC OK is true"); +} + void test_suite_isl923x(void) { ztest_test_suite(isl923x, @@ -691,6 +728,7 @@ void test_suite_isl923x(void) ztest_unit_test(test_comparator_inversion), ztest_unit_test(test_discharge_on_ac), ztest_unit_test(test_get_vbus_voltage), - ztest_unit_test(test_init)); + ztest_unit_test(test_init), + ztest_unit_test(test_isl923x_is_acok)); ztest_run_test_suite(isl923x); } -- cgit v1.2.1