diff options
author | Tristan Honscheid <honscheid@google.com> | 2022-11-02 13:38:07 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-09 06:04:28 +0000 |
commit | f95572076ab223eb99e84435d974fd96ffde5b5f (patch) | |
tree | 071f10ba29e2457c27c7fe1e00d7dd4d9208bf96 | |
parent | 4449ac2bbf9349456a3c1c286acef203f4611f81 (diff) | |
download | chrome-ec-f95572076ab223eb99e84435d974fd96ffde5b5f.tar.gz |
zephyr: tests: Test charger.c charger_get_actual_current()
Test charger_get_actual_current in common/charger.c
BRANCH=None
BUG=None
TEST=./twister
Signed-off-by: Tristan Honscheid <honscheid@google.com>
Change-Id: Idd220b05371d90621f874e9b8152522d124da131
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4000830
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c b/zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c index 2319256315..060f0cf748 100644 --- a/zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c +++ b/zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c @@ -26,6 +26,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_PLATFORM_EC_CHARGER_RUNTIME_CONFIG), FAKE_VALUE_FUNC(enum ec_error_list, enable_otg_power, int, int); FAKE_VALUE_FUNC(enum ec_error_list, set_otg_current_voltage, int, int, int); FAKE_VALUE_FUNC(int, is_sourcing_otg_power, int, int); +FAKE_VALUE_FUNC(enum ec_error_list, get_actual_current, int, int *); struct common_charger_mocked_driver_fixture { /* The original driver pointer that gets restored after the tests */ @@ -110,6 +111,49 @@ ZTEST_F(common_charger_mocked_driver, test_charger_is_sourcing_otg_power) zassert_equal(1, is_sourcing_otg_power_fake.call_count); } +ZTEST(common_charger_mocked_driver, test_charger_get_actual_current__invalid) +{ + /* charger number out of bounds */ + zassert_equal(EC_ERROR_INVAL, charger_get_actual_current(-1, NULL)); + zassert_equal(EC_ERROR_INVAL, + charger_get_actual_current(INT_MAX, NULL)); +} + +ZTEST(common_charger_mocked_driver, test_charger_get_actual_current__unimpl) +{ + /* get_actual_current is NULL */ + zassert_equal(EC_ERROR_UNIMPLEMENTED, + charger_get_actual_current(CHG_NUM, NULL)); +} + +/** + * @brief Custom fake for get_actual_current that can write to the output param + */ +static enum ec_error_list get_actual_current_custom_fake(int chgnum, + int *current) +{ + ARG_UNUSED(chgnum); + + *current = 1000; + + return EC_SUCCESS; +} + +ZTEST_F(common_charger_mocked_driver, test_charger_get_actual_current) +{ + int current; + + fixture->mock_driver.get_actual_current = get_actual_current; + get_actual_current_fake.custom_fake = get_actual_current_custom_fake; + + zassert_equal(EC_SUCCESS, + charger_get_actual_current(CHG_NUM, ¤t)); + + zassert_equal(1, get_actual_current_fake.call_count); + zassert_equal(CHG_NUM, get_actual_current_fake.arg0_history[0]); + zassert_equal(1000, current); +} + static void *setup(void) { static struct common_charger_mocked_driver_fixture f; @@ -137,6 +181,7 @@ static void reset(void *data) RESET_FAKE(enable_otg_power); RESET_FAKE(set_otg_current_voltage); RESET_FAKE(is_sourcing_otg_power); + RESET_FAKE(get_actual_current); } static void teardown(void *data) |