summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-11-14 10:36:44 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-11-16 16:40:24 +0000
commitb5b4376ce9d5257bc22d6a4d3350477b2ddea15a (patch)
treee898c1ded3d65facb0b3699e5954ac17dd38af65 /common
parent41cf03de4c8c0cc1bf0297796893f925e8ee1cd8 (diff)
downloadchrome-ec-b5b4376ce9d5257bc22d6a4d3350477b2ddea15a.tar.gz
test: add tests for battery_fuel_gauge
- Add error handling tests for fuel gauge. - Add cutoff handling tests for fuel gauge. - Add tests for default implementation of the get_default_battery_type - Add tests for battery_sleep_fuel_gauge - Add tests for battery_is_charge_fet_disabled - Add tests for battery_get_disconnect_state BRANCH=none BUG=none TEST=twister Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I87552b936184c6152c4be4a64bd42278ce5b5ca2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4026562 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com>
Diffstat (limited to 'common')
-rw-r--r--common/battery_fuel_gauge.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/common/battery_fuel_gauge.c b/common/battery_fuel_gauge.c
index e6aca68472..6a62c21479 100644
--- a/common/battery_fuel_gauge.c
+++ b/common/battery_fuel_gauge.c
@@ -7,6 +7,7 @@
#include "battery_fuel_gauge.h"
#include "battery_smart.h"
+#include "builtin/assert.h"
#include "console.h"
#include "hooks.h"
#include "i2c.h"
@@ -22,7 +23,8 @@
* a device name has been specified in the board_battery_info table,
* then both the manufacturer and device name must match.
*/
-static bool authenticate_battery_type(int index, char *manuf_name)
+test_export_static bool authenticate_battery_type(int index,
+ const char *manuf_name)
{
char device_name[32];
@@ -84,6 +86,12 @@ void battery_set_fixed_battery_type(int type)
}
#endif /* CONFIG_BATTERY_TYPE_NO_AUTO_DETECT */
+/**
+ * Allows us to override the battery in order to select the battery which has
+ * the right configuration for the test.
+ */
+test_export_static int battery_fuel_gauge_type_override = -1;
+
/* Get type of the battery connected on the board */
static int get_battery_type(void)
{
@@ -91,6 +99,10 @@ static int get_battery_type(void)
int i;
static enum battery_type battery_type = BATTERY_TYPE_COUNT;
+ if (IS_ENABLED(TEST_BUILD) && battery_fuel_gauge_type_override >= 0) {
+ return battery_fuel_gauge_type_override;
+ }
+
/*
* If battery_type is not the default value, then can return here
* as there is no need to query the fuel gauge.