summaryrefslogtreecommitdiff
path: root/test/charging.py
blob: 366d3faa3cd894799d44c44e19115bafa989b3c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# 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 !