mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-29 18:11:05 +00:00
This test checks charging state machine works correctly: - Charge when AC plugged. Discharge when AC unplugged. - Shutdown when over/under-temperature during discharging. - Stop charging when over/under-temperature during charging. BUG=chrome-os-partner:10270 TEST=Test passed Change-Id: I460645c70f5dcd30e258c43956ffe416c8bce906 Reviewed-on: https://gerrit.chromium.org/gerrit/26383 Reviewed-by: Rong Chang <rongchang@chromium.org> Commit-Ready: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
# Copyright (c) 2011 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.
|
|
#
|
|
# Charging state machine unit test
|
|
#
|
|
|
|
import time
|
|
|
|
def consume_charge_state(helper):
|
|
try:
|
|
while True:
|
|
helper.wait_output("Charge state \S+ -> \S+",
|
|
use_re=True,
|
|
timeout=1)
|
|
except:
|
|
pass
|
|
|
|
def wait_charge_state(helper, state):
|
|
helper.wait_output("Charge state \S+ -> %s" % state, use_re=True)
|
|
|
|
def test(helper):
|
|
helper.wait_output("--- UART initialized")
|
|
|
|
# Check charge when AC present
|
|
consume_charge_state(helper)
|
|
helper.ec_command("gpiomock AC_PRESENT 1")
|
|
wait_charge_state(helper, "charge")
|
|
|
|
# Check discharge when AC not present
|
|
helper.ec_command("gpiomock AC_PRESENT 0")
|
|
wait_charge_state(helper, "discharge")
|
|
|
|
# Check charge current
|
|
helper.ec_command("sbmock desire_current 2800")
|
|
helper.ec_command("gpiomock AC_PRESENT 1")
|
|
helper.wait_output("Charger set current: 2800")
|
|
|
|
# Check charger voltage
|
|
helper.ec_command("gpiomock AC_PRESENT 0")
|
|
wait_charge_state(helper, "discharge")
|
|
helper.ec_command("sbmock desire_voltage 7500")
|
|
helper.ec_command("gpiomock AC_PRESENT 1")
|
|
helper.wait_output("Charger set voltage: 7500")
|
|
|
|
# While powered on and discharging, over-temperature should trigger
|
|
# system shutdown
|
|
helper.ec_command("gpiomock AC_PRESENT 0")
|
|
wait_charge_state(helper, "discharge")
|
|
helper.ec_command("powermock on")
|
|
helper.ec_command("sbmock temperature 3700")
|
|
helper.wait_output("Force shutdown")
|
|
helper.ec_command("sbmock temperature 2981")
|
|
time.sleep(1)
|
|
|
|
# While powered on and discharging, under-temperature should trigger
|
|
# system shutdown
|
|
helper.ec_command("powermock on")
|
|
helper.ec_command("sbmock temperature 2600")
|
|
helper.wait_output("Force shutdown")
|
|
helper.ec_command("sbmock temperature 2981")
|
|
|
|
# While powered on and charging, over-temperature should stop battery
|
|
# from charging
|
|
consume_charge_state(helper)
|
|
helper.ec_command("gpiomock AC_PRESENT 1")
|
|
wait_charge_state(helper, "charge")
|
|
helper.ec_command("powermock on")
|
|
helper.ec_command("sbmock temperature 3700")
|
|
wait_charge_state(helper, "idle")
|
|
helper.ec_command("sbmock temperature 2981")
|
|
wait_charge_state(helper, "charge")
|
|
|
|
# While powered on and charging, under-temperature should stop battery
|
|
# from charging
|
|
helper.ec_command("sbmock temperature 2600")
|
|
wait_charge_state(helper, "idle")
|
|
helper.ec_command("sbmock temperature 2981")
|
|
wait_charge_state(helper, "charge")
|
|
|
|
return True # PASS !
|