summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/isl923x
diff options
context:
space:
mode:
authorAl Semjonovs <asemjonovs@google.com>2022-03-18 15:45:43 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-29 00:37:12 +0000
commitd82c02f5d36e0748a49562a27cbac3e2edfa9491 (patch)
treeea25b196195987586c737f30d8b8b80f341d3fee /zephyr/test/drivers/isl923x
parentbd186c8c118df3115147c6559fef7eb5979c1720 (diff)
downloadchrome-ec-d82c02f5d36e0748a49562a27cbac3e2edfa9491.tar.gz
zephyr:test: Add tests for CHARGER_RAMP_HW
Add tests for CHARGER_RAMP_HW BRANCH=none BUG=none TEST=zmake -D configure --coverage --test zephyr/test/drivers/ Signed-off-by: Al Semjonovs <asemjonovs@google.com> Change-Id: I37e401ebc2ae4b6be3203409473d2ea1ebf88f12 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3523681 Reviewed-by: Yuval Peress <peress@google.com>
Diffstat (limited to 'zephyr/test/drivers/isl923x')
-rw-r--r--zephyr/test/drivers/isl923x/CMakeLists.txt2
-rw-r--r--zephyr/test/drivers/isl923x/src/charge_ramp_hw.c52
2 files changed, 54 insertions, 0 deletions
diff --git a/zephyr/test/drivers/isl923x/CMakeLists.txt b/zephyr/test/drivers/isl923x/CMakeLists.txt
index 3425a3d94b..36a97589c1 100644
--- a/zephyr/test/drivers/isl923x/CMakeLists.txt
+++ b/zephyr/test/drivers/isl923x/CMakeLists.txt
@@ -15,6 +15,8 @@ zephyr_include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
# Add source files
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CONSOLE_CMD_CHARGER_ADC_AMON_BMON
"${CMAKE_CURRENT_SOURCE_DIR}/src/console_cmd_amon_bmon.c")
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGE_RAMP_HW
+ "${CMAKE_CURRENT_SOURCE_DIR}/src/charge_ramp_hw.c")
# Link in the library
zephyr_library_link_libraries(${lib_name})
diff --git a/zephyr/test/drivers/isl923x/src/charge_ramp_hw.c b/zephyr/test/drivers/isl923x/src/charge_ramp_hw.c
new file mode 100644
index 0000000000..a405fab963
--- /dev/null
+++ b/zephyr/test/drivers/isl923x/src/charge_ramp_hw.c
@@ -0,0 +1,52 @@
+/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+
+#include <ztest.h>
+
+#include "charger_utils.h"
+#include "driver/charger/isl923x.h"
+#include "driver/charger/isl923x_public.h"
+#include "emul/emul_common_i2c.h"
+#include "emul/emul_isl923x.h"
+#include "test_state.h"
+
+#define CHARGER_NUM get_charger_num(&isl923x_drv)
+#define ISL923X_EMUL emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul)))
+
+ZTEST_SUITE(charge_ramp_hw, drivers_predicate_post_main, NULL, NULL,
+ NULL, NULL);
+
+ZTEST(charge_ramp_hw, test_charge_ramp_hw_ramp)
+{
+ zassert_ok(isl923x_drv.set_hw_ramp(CHARGER_NUM, 1), NULL);
+
+ zassert_ok(isl923x_drv.ramp_is_stable(CHARGER_NUM), NULL);
+ zassert_true(isl923x_drv.ramp_is_detected(CHARGER_NUM), NULL);
+
+ zassert_ok(isl923x_drv.set_input_current_limit(CHARGER_NUM, 512), NULL);
+ zassert_equal(512, isl923x_drv.ramp_get_current_limit(CHARGER_NUM),
+ NULL);
+}
+
+ZTEST(charge_ramp_hw, test_charge_ramp_hw_ramp_read_fail_reg0)
+{
+ 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);
+ zassert_equal(EC_ERROR_INVAL, isl923x_drv.set_hw_ramp(CHARGER_NUM, 1),
+ NULL);
+}
+
+ZTEST(charge_ramp_hw, test_charge_ramp_hw_ramp_read_fail_acl1)
+{
+ 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_ADAPTER_CURRENT_LIMIT1);
+ zassert_equal(0, isl923x_drv.ramp_get_current_limit(CHARGER_NUM), NULL);
+}