From 31cf129cb7cb8ae61186ff276c7c68ded80660df Mon Sep 17 00:00:00 2001 From: Yuval Peress Date: Tue, 8 Nov 2022 03:14:01 -0700 Subject: test: verify common paths for charge_prevent_power_on Check that pressing the power button and having enough charge will allow power-on, while having too little charge and going through the "auto-power-on" will not. This change required moving the static 'automatic_power_on' outside of the charge_prevent_power_on() function so it can be properly reset between tests. BRANCH=none BUG=none TEST=twister Signed-off-by: Yuval Peress Change-Id: Iff500728493ad8002fb1daf50845db85690a0a8d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4011171 Code-Coverage: Zoss Reviewed-by: Al Semjonovs Commit-Queue: Al Semjonovs --- common/charge_state_v2.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'common/charge_state_v2.c') diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 54c49320c6..cd1b5988e2 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -2082,14 +2082,15 @@ int charge_want_shutdown(void) (curr.batt.state_of_charge < battery_level_shutdown); } -int charge_prevent_power_on(int power_button_pressed) +#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON +test_export_static int charge_prevent_power_on_automatic_power_on = 1; +#endif + +bool charge_prevent_power_on(bool power_button_pressed) { int prevent_power_on = 0; struct batt_params params; struct batt_params *current_batt_params = &curr.batt; -#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON - static int automatic_power_on = 1; -#endif /* If battery params seem uninitialized then retrieve them */ if (current_batt_params->is_present == BP_NOT_SURE) { @@ -2104,7 +2105,7 @@ int charge_prevent_power_on(int power_button_pressed) * power-ups are user-requested and non-automatic. */ if (power_button_pressed) - automatic_power_on = 0; + charge_prevent_power_on_automatic_power_on = 0; /* * Require a minimum battery level to power on and ensure that the * battery can provide power to the system. @@ -2150,12 +2151,13 @@ int charge_prevent_power_on(int power_button_pressed) * except when auto-power-on at EC startup and the battery * is physically present. */ - prevent_power_on &= - (system_is_locked() || (automatic_power_on + prevent_power_on &= (system_is_locked() || + (charge_prevent_power_on_automatic_power_on #ifdef CONFIG_BATTERY_HW_PRESENT_CUSTOM - && battery_hw_present() == BP_YES + + && battery_hw_present() == BP_YES #endif - )); + )); #endif /* CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON */ #ifdef CONFIG_CHARGE_MANAGER @@ -2189,7 +2191,7 @@ int charge_prevent_power_on(int power_button_pressed) prevent_power_on = 1; #endif /* CONFIG_SYSTEM_UNLOCKED */ - return prevent_power_on; + return prevent_power_on != 0; } static int battery_near_full(void) -- cgit v1.2.1