From 24a1cee59942b595f459d69c2aa2f97d37b268df Mon Sep 17 00:00:00 2001 From: Aaron Massey Date: Tue, 13 Sep 2022 17:25:36 -0600 Subject: test: EC thinks AP can boot on low battery cap Verify that the EC can still determine if the AP is bootable on a low battery capacity while there is a charger connected. Also verify that the EC thinks it can't boot when it's on low battery without a charger connected. BRANCH=none BUG=b:246335162 TEST=twister --coverage --clobber -i -s zephyr/test/drivers/drivers.default Signed-off-by: Aaron Massey Change-Id: I02be9616fe3bee9fedd716f46ccb862b2f1ef0e3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3892500 Code-Coverage: Zoss Reviewed-by: Keith Short --- .../src/integration/usbc/usb_5v_3a_pd_source.c | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c index 49716e55c3..4d89e8c0d3 100644 --- a/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c +++ b/zephyr/test/drivers/default/src/integration/usbc/usb_5v_3a_pd_source.c @@ -9,6 +9,7 @@ #include "emul/emul_isl923x.h" #include "emul/emul_smart_battery.h" #include "emul/tcpc/emul_tcpci_partner_src.h" +#include "system.h" #include "test/drivers/test_state.h" #include "test/drivers/utils.h" #include "usb_pd.h" @@ -205,3 +206,43 @@ ZTEST_F(usb_attach_5v_3a_pd_source, test_disconnect_power_info) "Expected the PD current limit to be >= 0, but got %dmA", power_info.meas.current_lim); } + +ZTEST(usb_attach_5v_3a_pd_source, + test_ap_can_boot_on_low_battery_while_charging) +{ + const struct emul *smart_batt_emul = EMUL_DT_GET(DT_NODELABEL(battery)); + struct sbat_emul_bat_data *batt_data = + sbat_emul_get_bat_data(smart_batt_emul); + + /* Set capacity to what gives a charge percentage less than required + * for booting the AP + * + * Capacaity is reset by emulator's ZTEST_RULE + */ + batt_data->cap = (CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON * + batt_data->design_cap / 100) - + 1; + + zassert_true(system_can_boot_ap(), NULL); +} + +ZTEST_F(usb_attach_5v_3a_pd_source, + test_ap_fails_to_boot_on_low_battery_while_not_charging) +{ + const struct emul *smart_batt_emul = EMUL_DT_GET(DT_NODELABEL(battery)); + struct sbat_emul_bat_data *batt_data = + sbat_emul_get_bat_data(smart_batt_emul); + + /* Set capacity to what gives a charge percentage less than required + * for booting the AP + * + * Capacaity is reset by emulator's ZTEST_RULE + */ + batt_data->cap = (CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON * + batt_data->design_cap / 100) - + 1; + + disconnect_source_from_port(fixture->tcpci_emul, fixture->charger_emul); + + zassert_false(system_can_boot_ap(), NULL); +} -- cgit v1.2.1