blob: c6550ecd4db1efeaf0b0deed1eb82633ef49d6c5 [file] [log] [blame]
Mary Ruthven44b571c2018-09-25 05:10:17 -07001# Copyright 2018 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import time
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.server.cros.faft.cr50_test import Cr50Test
10
11
12class firmware_Cr50ECReset(Cr50Test):
13 """Make sure 'cr50 ecrst' works as intended
14
15 EC_RST_L needs to be able to wake the EC from hibernate and hold the EC in
16 reset. This test verifies the hardware works as intended
17 """
18 version = 1
19
20 # Delays used by the test. Time is given in seconds
21 # Used to wait long enough for the EC to enter/resume from hibernate
22 EC_SETTLE_TIME = 10
23 RELEASE_RESET_DELAY = 3
24 SHORT_PULSE = 1
25
26 def cleanup(self):
27 """Make sure the EC is on"""
28 self.guarantee_ec_is_up()
29 super(firmware_Cr50ECReset, self).cleanup()
30
31
32 def ec_is_up(self):
33 """If the console is responsive, then the EC is awake"""
34 time.sleep(self.EC_SETTLE_TIME)
35 try:
36 self.ec.send_command_get_output('time', ['.*>'])
37 except error.TestFail, e:
38 logging.info(e)
39 if 'Timeout waiting for response' in str(e):
40 return False
41 raise
42 else:
43 return True
44
45
46 def cold_reset(self, state):
47 """Set cold reset"""
48 self.servo.set('cold_reset', state)
49
50
51 def power_button(self, state):
52 """Press or release the power button"""
53 self.servo.set('pwr_button', 'press' if state == 'on' else 'release')
54
55
56 def cr50_ecrst(self, state):
57 """Set ecrst on cr50"""
58 self.cr50.send_command('ecrst ' + state)
59
60
61 def wake_ec(self, wake_method):
62 """Pulse the wake method to wake the EC
63
64 Args:
65 wake_method: a function that takes in 'on' or 'off' to control the
66 wake source.
67 """
68 wake_method('on')
69 time.sleep(self.SHORT_PULSE)
70 wake_method('off')
71
72
73 def ec_hibernate(self):
74 """Put the EC in hibernate"""
75 self.ec.send_command('hibernate')
76 if self.ec_is_up():
77 raise error.TestError('Could not put the EC into hibernate')
78
79
80 def guarantee_ec_is_up(self):
81 """Make sure ec isn't held in reset. Use the power button to wake it
82
83 The power button wakes the EC on all systems. Use that to wake the EC
84 and make sure all versions of ecrst are released.
85 """
86 self.cold_reset('off')
87 self.cr50_ecrst('off')
88 time.sleep(self.RELEASE_RESET_DELAY)
89 self.wake_ec(self.power_button)
90 if not self.ec_is_up():
91 raise error.TestError('Could not recover EC')
92
93
94 def can_wake_ec(self, wake_method):
95 """Put the EC in hibernate and verify it can wake up with wake_method
96
97 Args:
98 wake_method: a function that takes in 'on' or 'off' to control the
99 wake source.
100 Returns:
101 True if wake_method can be used to wake the EC from hibernate
102 """
103 self.ec_hibernate()
104 self.wake_ec(self.cold_reset)
105 wake_successful = self.ec_is_up()
106 self.guarantee_ec_is_up()
107 return wake_successful
108
109
110 def check_basic_ecrst(self):
111 """Verify cr50 can hold the EC in reset"""
112 self.cr50_ecrst('on')
113 if self.ec_is_up():
114 raise error.TestFail('Could not use cr50 ecrst to hold the EC in '
115 'reset')
116 # Verify cr50 can release the EC from reset
117 self.cr50_ecrst('off')
118 if not self.ec_is_up():
119 raise error.TestFail('Could not release the EC from reset')
120 self.guarantee_ec_is_up()
121
Mary Ruthven58776db2018-12-06 11:05:36 -0800122 def check_ec_hibernate(self):
123 """Verify EC hibernate"""
124 try:
125 self.ec_hibernate()
126 except error.TestError, e:
127 if 'Could not put the EC into hibernate' in str(e):
128 raise error.TestNAError("EC hibernate doesn't work.")
129 finally:
130 self.guarantee_ec_is_up()
131
Mary Ruthven44b571c2018-09-25 05:10:17 -0700132
133 def run_once(self):
134 """Make sure 'cr50 ecrst' works as intended."""
135 failed_wake = []
Mary Ruthven58776db2018-12-06 11:05:36 -0800136 # The test needs to be able to hibernate the EC. Make sure it works as
137 # intended before running the test.
138 self.check_ec_hibernate()
139
Mary Ruthven44b571c2018-09-25 05:10:17 -0700140 # Open cr50 so the test has access to ecrst
141 self.fast_open(True)
142
143 self.check_basic_ecrst()
144
145 if not self.can_wake_ec(self.cr50_ecrst):
146 failed_wake.append('cr50 ecrst')
147
148 if not self.can_wake_ec(self.cold_reset):
149 failed_wake.append('servo cold_reset')
150
151 if failed_wake:
152 raise error.TestFail('Failed to wake EC with %s' %
153 ' and '.join(failed_wake))