summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/charge_state_v2.c2
-rw-r--r--test/sbs_charging_v2.c78
2 files changed, 64 insertions, 16 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index e5f62fff60..f293c61175 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -1280,7 +1280,7 @@ static void show_charging_progress(void)
}
/* Calculate if battery is full based on whether it is accepting charge */
-static int calc_is_full(void)
+test_mockable int calc_is_full(void)
{
static int __bss_slow ret;
diff --git a/test/sbs_charging_v2.c b/test/sbs_charging_v2.c
index 20722b563a..714cf89124 100644
--- a/test/sbs_charging_v2.c
+++ b/test/sbs_charging_v2.c
@@ -28,6 +28,7 @@ static int is_force_discharge;
static int is_hibernated;
static int override_voltage, override_current, override_usec;
static int display_soc;
+static int is_full;
/* The simulation doesn't really hibernate, so we must reset this ourselves */
extern timestamp_t shutdown_target_time;
@@ -38,6 +39,7 @@ static void reset_mocks(void)
is_shutdown = is_force_discharge = is_hibernated = 0;
override_voltage = override_current = override_usec = 0;
shutdown_target_time.val = 0ULL;
+ is_full = 0;
}
int board_cut_off_battery(void)
@@ -131,10 +133,14 @@ static int wait_charging_state(void)
static int charge_control(enum ec_charge_control_mode mode)
{
- struct ec_params_charge_control params;
- params.mode = mode;
- return test_send_host_command(EC_CMD_CHARGE_CONTROL, 1, &params,
- sizeof(params), NULL, 0);
+ struct ec_params_charge_control p;
+
+ p.cmd = EC_CHARGE_CONTROL_CMD_SET;
+ p.mode = mode;
+ p.sustain_soc.lower = -1;
+ p.sustain_soc.upper = -1;
+ return test_send_host_command(EC_CMD_CHARGE_CONTROL, 2, &p, sizeof(p),
+ NULL, 0);
}
__override int charge_get_display_charge(void)
@@ -142,6 +148,11 @@ __override int charge_get_display_charge(void)
return display_soc;
}
+__override int calc_is_full(void)
+{
+ return is_full;
+}
+
/* Setup init condition */
static void test_setup(int on_ac)
{
@@ -761,49 +772,86 @@ static int test_battery_sustainer(void)
/* Check mode transition as the SoC changes. */
- /* SoC < lower < upper */
+ ccprintf("Test SoC < lower < upper.\n");
display_soc = 780;
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL);
+ ccprintf("Pass.\n");
- /* lower < upper < SoC */
+ ccprintf("Test lower < upper < SoC.\n");
display_soc = 810;
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_DISCHARGE);
+ ccprintf("Pass.\n");
- /* Unplug AC. Sustainer gets deactivated. */
+ ccprintf("Test unplug AC.\n");
gpio_set_level(GPIO_AC_PRESENT, 0);
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL);
+ ccprintf("Pass.\n");
- /* Replug AC. Sustainer gets re-activated. */
+ ccprintf("Test replug AC.\n");
gpio_set_level(GPIO_AC_PRESENT, 1);
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_DISCHARGE);
+ ccprintf("Pass.\n");
- /* lower < SoC < upper */
+ ccprintf("Test lower < SoC < upper.\n");
display_soc = 799;
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_IDLE);
+ ccprintf("Pass.\n");
- /* SoC < lower < upper */
+ ccprintf("Test SoC < lower < upper.\n");
display_soc = 789;
wait_charging_state();
TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL);
+ ccprintf("Pass.\n");
+
+ ccprintf("Test disable sustainer.\n");
+ charge_control(CHARGE_CONTROL_NORMAL);
+ display_soc = 810;
+ wait_charging_state();
+ TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL);
+ ccprintf("Pass.\n");
- /* Disable sustainer */
+ ccprintf("Test enable sustainer when battery is full.\n");
+ display_soc = 1000;
+ is_full = 1;
+ wait_charging_state();
+ /* Enable sustainer. */
p.cmd = EC_CHARGE_CONTROL_CMD_SET;
p.mode = CHARGE_CONTROL_NORMAL;
- p.sustain_soc.lower = -1;
- p.sustain_soc.upper = -1;
+ p.sustain_soc.lower = 79;
+ p.sustain_soc.upper = 80;
rv = test_send_host_command(EC_CMD_CHARGE_CONTROL, 2,
&p, sizeof(p), NULL, 0);
TEST_ASSERT(rv == EC_RES_SUCCESS);
+ wait_charging_state();
+ TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_DISCHARGE);
+ ccprintf("Pass.\n");
- /* This time, mode will stay in NORMAL even when upper < SoC. */
+ /* Disable sustainer, unplug AC, upper < SoC < 100. */
+ charge_control(CHARGE_CONTROL_NORMAL);
display_soc = 810;
+ is_full = 0;
+ gpio_set_level(GPIO_AC_PRESENT, 0);
wait_charging_state();
- TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_NORMAL);
+
+ ccprintf("Test enable sustainer when AC is present.\n");
+ gpio_set_level(GPIO_AC_PRESENT, 1);
+ wait_charging_state();
+ /* Enable sustainer. */
+ p.cmd = EC_CHARGE_CONTROL_CMD_SET;
+ p.mode = CHARGE_CONTROL_NORMAL;
+ p.sustain_soc.lower = 79;
+ p.sustain_soc.upper = 80;
+ rv = test_send_host_command(EC_CMD_CHARGE_CONTROL, 2,
+ &p, sizeof(p), NULL, 0);
+ TEST_ASSERT(rv == EC_RES_SUCCESS);
+ wait_charging_state();
+ TEST_ASSERT(get_chg_ctrl_mode() == CHARGE_CONTROL_DISCHARGE);
+ ccprintf("Pass.\n");
return EC_SUCCESS;
}