summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Honscheid <honscheid@google.com>2022-11-02 13:43:07 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-09 06:04:47 +0000
commit78f474275cfe0be44551f9f15ff0be56da8af08c (patch)
tree4c92e70e4504e8db3aff3dbdb6ff87e56a4f4696
parentf95572076ab223eb99e84435d974fd96ffde5b5f (diff)
downloadchrome-ec-78f474275cfe0be44551f9f15ff0be56da8af08c.tar.gz
zephyr: tests: Test charger.c charger_get_actual_voltage()
Test charger_get_actual_voltage in common/charger.c BRANCH=None BUG=None TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I82421e3141d657d7b6290187eb7ed18024732af2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4000831 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--zephyr/test/drivers/common_charger/src/test_common_charger_mocked.c45
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 060f0cf748..a8b01b3c87 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
@@ -27,6 +27,7 @@ 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 *);
+FAKE_VALUE_FUNC(enum ec_error_list, get_actual_voltage, int, int *);
struct common_charger_mocked_driver_fixture {
/* The original driver pointer that gets restored after the tests */
@@ -154,6 +155,49 @@ ZTEST_F(common_charger_mocked_driver, test_charger_get_actual_current)
zassert_equal(1000, current);
}
+ZTEST(common_charger_mocked_driver, test_charger_get_actual_voltage__invalid)
+{
+ /* charger number out of bounds */
+ zassert_equal(EC_ERROR_INVAL, charger_get_actual_voltage(-1, NULL));
+ zassert_equal(EC_ERROR_INVAL,
+ charger_get_actual_voltage(INT_MAX, NULL));
+}
+
+ZTEST(common_charger_mocked_driver, test_charger_get_actual_voltage__unimpl)
+{
+ /* get_actual_voltage is NULL */
+ zassert_equal(EC_ERROR_UNIMPLEMENTED,
+ charger_get_actual_voltage(CHG_NUM, NULL));
+}
+
+/**
+ * @brief Custom fake for get_actual_voltage that can write to the output param
+ */
+static enum ec_error_list get_actual_voltage_custom_fake(int chgnum,
+ int *voltage)
+{
+ ARG_UNUSED(chgnum);
+
+ *voltage = 2000;
+
+ return EC_SUCCESS;
+}
+
+ZTEST_F(common_charger_mocked_driver, test_charger_get_actual_voltage)
+{
+ int voltage;
+
+ fixture->mock_driver.get_actual_voltage = get_actual_voltage;
+ get_actual_voltage_fake.custom_fake = get_actual_voltage_custom_fake;
+
+ zassert_equal(EC_SUCCESS,
+ charger_get_actual_voltage(CHG_NUM, &voltage));
+
+ zassert_equal(1, get_actual_voltage_fake.call_count);
+ zassert_equal(CHG_NUM, get_actual_voltage_fake.arg0_history[0]);
+ zassert_equal(2000, voltage);
+}
+
static void *setup(void)
{
static struct common_charger_mocked_driver_fixture f;
@@ -182,6 +226,7 @@ static void reset(void *data)
RESET_FAKE(set_otg_current_voltage);
RESET_FAKE(is_sourcing_otg_power);
RESET_FAKE(get_actual_current);
+ RESET_FAKE(get_actual_voltage);
}
static void teardown(void *data)