J. Richard Barnette | 384056b | 2012-04-16 11:04:46 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | # |
| 5 | # Expects to be run in an environment with sudo and no interactive password |
| 6 | # prompt, such as within the Chromium OS development chroot. |
| 7 | |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 8 | import ast |
| 9 | import logging |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 10 | import os |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 11 | import re |
Dana Goyette | a2f00ea | 2019-06-26 16:14:12 -0700 | [diff] [blame] | 12 | import socket |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 13 | import time |
| 14 | import xmlrpclib |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 15 | |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 16 | from autotest_lib.client.common_lib import error |
Mary Ruthven | ecf1271 | 2019-06-26 17:36:21 -0700 | [diff] [blame] | 17 | from autotest_lib.client.common_lib import lsbrelease_utils |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 18 | from autotest_lib.server import utils as server_utils |
Ricky Liang | c31aab3 | 2014-07-03 16:23:29 +0800 | [diff] [blame] | 19 | from autotest_lib.server.cros.servo import firmware_programmer |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 20 | |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 21 | # Time to wait when probing for a usb device, it takes on avg 17 seconds |
| 22 | # to do a full probe. |
| 23 | _USB_PROBE_TIMEOUT = 40 |
| 24 | |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 25 | |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 26 | # Regex to match XMLRPC errors due to a servod control not existing. |
| 27 | NO_CONTROL_RE = re.compile(r'No control named (\w*\.?\w*)') |
| 28 | |
| 29 | class ControlUnavailableError(error.TestFail): |
| 30 | """Custom error class to indicate a control is unavailable on servod.""" |
| 31 | pass |
| 32 | |
| 33 | |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 34 | def _extract_image_from_tarball(tarball, dest_dir, image_candidates): |
| 35 | """Try extracting the image_candidates from the tarball. |
| 36 | |
| 37 | @param tarball: The path of the tarball. |
| 38 | @param dest_path: The path of the destination. |
| 39 | @param image_candidates: A tuple of the paths of image candidates. |
| 40 | |
| 41 | @return: The first path from the image candidates, which succeeds, or None |
| 42 | if all the image candidates fail. |
| 43 | """ |
| 44 | for image in image_candidates: |
| 45 | status = server_utils.system( |
| 46 | ('tar xf %s -C %s %s' % (tarball, dest_dir, image)), |
| 47 | timeout=60, ignore_status=True) |
| 48 | if status == 0: |
| 49 | return image |
| 50 | return None |
| 51 | |
| 52 | |
J. Richard Barnette | 0c9c588 | 2014-06-11 15:27:05 -0700 | [diff] [blame] | 53 | class _PowerStateController(object): |
| 54 | |
| 55 | """Class to provide board-specific power operations. |
| 56 | |
| 57 | This class is responsible for "power on" and "power off" |
| 58 | operations that can operate without making assumptions in |
| 59 | advance about board state. It offers an interface that |
| 60 | abstracts out the different sequences required for different |
| 61 | board types. |
| 62 | |
| 63 | """ |
| 64 | |
| 65 | # Constants acceptable to be passed for the `rec_mode` parameter |
| 66 | # to power_on(). |
| 67 | # |
| 68 | # REC_ON: Boot the DUT in recovery mode, i.e. boot from USB or |
| 69 | # SD card. |
| 70 | # REC_OFF: Boot in normal mode, i.e. boot from internal storage. |
| 71 | |
| 72 | REC_ON = 'rec' |
| 73 | REC_OFF = 'on' |
Shelley Chen | 6593862 | 2018-05-16 07:45:54 -0700 | [diff] [blame] | 74 | REC_ON_FORCE_MRC = 'rec_force_mrc' |
J. Richard Barnette | 0c9c588 | 2014-06-11 15:27:05 -0700 | [diff] [blame] | 75 | |
| 76 | # Delay in seconds needed between asserting and de-asserting |
| 77 | # warm reset. |
| 78 | _RESET_HOLD_TIME = 0.5 |
| 79 | |
| 80 | def __init__(self, servo): |
| 81 | """Initialize the power state control. |
| 82 | |
| 83 | @param servo Servo object providing the underlying `set` and `get` |
| 84 | methods for the target controls. |
| 85 | |
| 86 | """ |
| 87 | self._servo = servo |
| 88 | |
| 89 | def reset(self): |
| 90 | """Force the DUT to reset. |
| 91 | |
| 92 | The DUT is guaranteed to be on at the end of this call, |
| 93 | regardless of its previous state, provided that there is |
| 94 | working OS software. This also guarantees that the EC has |
| 95 | been restarted. |
| 96 | |
| 97 | """ |
| 98 | self._servo.set_nocheck('power_state', 'reset') |
| 99 | |
| 100 | def warm_reset(self): |
| 101 | """Apply warm reset to the DUT. |
| 102 | |
| 103 | This asserts, then de-asserts the 'warm_reset' signal. |
| 104 | Generally, this causes the board to restart. |
| 105 | |
| 106 | """ |
Ravutappa | 951ca43 | 2019-05-15 09:52:52 -0700 | [diff] [blame] | 107 | # TODO: warm_reset support has added to power_state.py. Once it |
| 108 | # available to labstation remove fallback method. |
| 109 | try: |
| 110 | self._servo.set_nocheck('power_state', 'warm_reset') |
| 111 | except error.TestFail as err: |
| 112 | logging.info("Fallback to warm_reset control method") |
| 113 | self._servo.set_get_all(['warm_reset:on', |
J. Richard Barnette | 0c9c588 | 2014-06-11 15:27:05 -0700 | [diff] [blame] | 114 | 'sleep:%.4f' % self._RESET_HOLD_TIME, |
| 115 | 'warm_reset:off']) |
| 116 | |
J. Richard Barnette | 0c9c588 | 2014-06-11 15:27:05 -0700 | [diff] [blame] | 117 | def power_off(self): |
| 118 | """Force the DUT to power off. |
| 119 | |
| 120 | The DUT is guaranteed to be off at the end of this call, |
| 121 | regardless of its previous state, provided that there is |
| 122 | working EC and boot firmware. There is no requirement for |
| 123 | working OS software. |
| 124 | |
| 125 | """ |
| 126 | self._servo.set_nocheck('power_state', 'off') |
| 127 | |
| 128 | def power_on(self, rec_mode=REC_OFF): |
| 129 | """Force the DUT to power on. |
| 130 | |
| 131 | Prior to calling this function, the DUT must be powered off, |
| 132 | e.g. with a call to `power_off()`. |
| 133 | |
| 134 | At power on, recovery mode is set as specified by the |
| 135 | corresponding argument. When booting with recovery mode on, it |
| 136 | is the caller's responsibility to unplug/plug in a bootable |
| 137 | external storage device. |
| 138 | |
| 139 | If the DUT requires a delay after powering on but before |
| 140 | processing inputs such as USB stick insertion, the delay is |
| 141 | handled by this method; the caller is not responsible for such |
| 142 | delays. |
| 143 | |
| 144 | @param rec_mode Setting of recovery mode to be applied at |
| 145 | power on. default: REC_OFF aka 'off' |
| 146 | |
| 147 | """ |
| 148 | self._servo.set_nocheck('power_state', rec_mode) |
| 149 | |
| 150 | |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 151 | class _Uart(object): |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 152 | """Class to capture UART streams of CPU, EC, Cr50, etc.""" |
| 153 | _UartToCapture = ('cpu', 'ec', 'cr50', 'servo_v4', 'servo_micro', 'usbpd') |
| 154 | |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 155 | def __init__(self, servo): |
| 156 | self._servo = servo |
| 157 | self._streams = [] |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 158 | self.logs_dir = None |
Congbin Guo | fe4d4e8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 159 | |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 160 | def _start_stop_capture(self, uart, start): |
| 161 | """Helper function to start/stop capturing on specified UART. |
| 162 | |
| 163 | @param uart: The UART name to start/stop capturing. |
| 164 | @param start: True to start capturing, otherwise stop. |
| 165 | |
Ruben Rodriguez Buchillon | ecb525f | 2019-09-03 14:52:14 -0700 | [diff] [blame] | 166 | @returns True if the operation completes successfully. |
| 167 | False if the UART capturing is not supported or failed due to |
| 168 | an error. |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 169 | """ |
| 170 | logging.debug('%s capturing %s UART.', 'Start' if start else 'Stop', |
| 171 | uart) |
Ruben Rodriguez Buchillon | b0e2a9f | 2019-08-12 12:40:44 -0700 | [diff] [blame] | 172 | uart_cmd = '%s_uart_capture' % uart |
Ruben Rodriguez Buchillon | ecb525f | 2019-09-03 14:52:14 -0700 | [diff] [blame] | 173 | target_level = 'on' if start else 'off' |
| 174 | level = None |
Ruben Rodriguez Buchillon | b0e2a9f | 2019-08-12 12:40:44 -0700 | [diff] [blame] | 175 | if self._servo.has_control(uart_cmd): |
Ruben Rodriguez Buchillon | 9f48564 | 2019-08-21 14:32:22 -0700 | [diff] [blame] | 176 | # Do our own implementation of set() here as not_applicable |
| 177 | # should also count as a valid control. |
Ruben Rodriguez Buchillon | ecb525f | 2019-09-03 14:52:14 -0700 | [diff] [blame] | 178 | logging.debug('Trying to set %s to %s.', uart_cmd, target_level) |
| 179 | try: |
| 180 | self._servo.set_nocheck(uart_cmd, target_level) |
| 181 | level = self._servo.get(uart_cmd) |
| 182 | except error.TestFail as e: |
| 183 | # Any sort of test failure here should not stop the test. This |
| 184 | # is just to capture more output. Log and move on. |
| 185 | logging.warning('Failed to set %s to %s. %s. Ignoring.', |
| 186 | uart_cmd, target_level, str(e)) |
| 187 | if level == target_level: |
| 188 | logging.debug('Managed to set %s to %s.', uart_cmd, level) |
| 189 | else: |
| 190 | logging.debug('Failed to set %s to %s. Got %s.', uart_cmd, |
| 191 | target_level, level) |
| 192 | return level == target_level |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 193 | |
| 194 | def start_capture(self): |
| 195 | """Start capturing UART streams.""" |
| 196 | for uart in self._UartToCapture: |
| 197 | if self._start_stop_capture(uart, True): |
| 198 | self._streams.append(('%s_uart_stream' % uart, '%s_uart.log' % |
| 199 | uart)) |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 200 | |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 201 | def dump(self): |
| 202 | """Dump UART streams to log files accordingly.""" |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 203 | if not self.logs_dir: |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 204 | return |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 205 | |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 206 | for stream, logfile in self._streams: |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 207 | logfile_fullname = os.path.join(self.logs_dir, logfile) |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 208 | try: |
| 209 | content = self._servo.get(stream) |
| 210 | except Exception as err: |
| 211 | logging.warn('Failed to get UART log for %s: %s', stream, err) |
| 212 | continue |
| 213 | |
Kuang-che Wu | 12192fc | 2019-08-31 09:55:00 +0800 | [diff] [blame] | 214 | if content == 'not_applicable': |
| 215 | logging.warn('%s is not applicable', stream) |
| 216 | continue |
| 217 | |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 218 | # The UART stream may contain non-printable characters, and servo |
| 219 | # returns it in string representation. We use `ast.leteral_eval` |
| 220 | # to revert it back. |
| 221 | with open(logfile_fullname, 'a') as fd: |
Kuang-che Wu | 12192fc | 2019-08-31 09:55:00 +0800 | [diff] [blame] | 222 | try: |
| 223 | fd.write(ast.literal_eval(content)) |
| 224 | except ValueError: |
| 225 | logging.exception('Invalid value for %s: %r', stream, |
| 226 | content) |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 227 | |
| 228 | def stop_capture(self): |
| 229 | """Stop capturing UART streams.""" |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 230 | for uart in self._UartToCapture: |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 231 | try: |
Congbin Guo | 0f00be8 | 2019-04-18 17:51:14 -0700 | [diff] [blame] | 232 | self._start_stop_capture(uart, False) |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 233 | except Exception as err: |
| 234 | logging.warn('Failed to stop UART logging for %s: %s', uart, |
| 235 | err) |
| 236 | |
| 237 | |
J. Richard Barnette | 384056b | 2012-04-16 11:04:46 -0700 | [diff] [blame] | 238 | class Servo(object): |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 239 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 240 | """Manages control of a Servo board. |
| 241 | |
| 242 | Servo is a board developed by hardware group to aide in the debug and |
| 243 | control of various partner devices. Servo's features include the simulation |
| 244 | of pressing the power button, closing the lid, and pressing Ctrl-d. This |
| 245 | class manages setting up and communicating with a servo demon (servod) |
| 246 | process. It provides both high-level functions for common servo tasks and |
| 247 | low-level functions for directly setting and reading gpios. |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 248 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 249 | """ |
| 250 | |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 251 | # Power button press delays in seconds. |
J. Richard Barnette | d2e4cbd | 2012-06-29 12:18:40 -0700 | [diff] [blame] | 252 | # |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 253 | # The EC specification says that 8.0 seconds should be enough |
| 254 | # for the long power press. However, some platforms need a bit |
| 255 | # more time. Empirical testing has found these requirements: |
| 256 | # Alex: 8.2 seconds |
| 257 | # ZGB: 8.5 seconds |
| 258 | # The actual value is set to the largest known necessary value. |
| 259 | # |
| 260 | # TODO(jrbarnette) Being generous is the right thing to do for |
| 261 | # existing platforms, but if this code is to be used for |
| 262 | # qualification of new hardware, we should be less generous. |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 263 | SHORT_DELAY = 0.1 |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 264 | |
Todd Broch | 31c8250 | 2011-08-29 08:14:39 -0700 | [diff] [blame] | 265 | # Maximum number of times to re-read power button on release. |
Todd Broch | cf7c665 | 2012-02-24 13:03:59 -0800 | [diff] [blame] | 266 | GET_RETRY_MAX = 10 |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 267 | |
J. Richard Barnette | 5383f07 | 2012-07-26 17:35:40 -0700 | [diff] [blame] | 268 | # Delays to deal with DUT state transitions. |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 269 | SLEEP_DELAY = 6 |
| 270 | BOOT_DELAY = 10 |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 271 | |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 272 | # Default minimum time interval between 'press' and 'release' |
| 273 | # keyboard events. |
Vic Yang | 0aca1c2 | 2012-11-19 18:33:56 -0800 | [diff] [blame] | 274 | SERVO_KEY_PRESS_DELAY = 0.1 |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 275 | |
Tom Wai-Hong Tam | 93b5c09 | 2015-05-14 02:50:43 +0800 | [diff] [blame] | 276 | # Time to toggle recovery switch on and off. |
| 277 | REC_TOGGLE_DELAY = 0.1 |
| 278 | |
Tom Wai-Hong Tam | f9ded09 | 2015-05-20 05:37:22 +0800 | [diff] [blame] | 279 | # Time to toggle development switch on and off. |
| 280 | DEV_TOGGLE_DELAY = 0.1 |
| 281 | |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 282 | # Time between an usb disk plugged-in and detected in the system. |
| 283 | USB_DETECTION_DELAY = 10 |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 284 | # Time to keep USB power off before and after USB mux direction is changed |
| 285 | USB_POWEROFF_DELAY = 2 |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 286 | |
Simran Basi | b7850bb | 2013-07-24 12:33:42 -0700 | [diff] [blame] | 287 | # Time to wait before timing out on servo initialization. |
| 288 | INIT_TIMEOUT_SECS = 10 |
Simran Basi | 5933134 | 2013-07-12 12:06:29 -0700 | [diff] [blame] | 289 | |
J. Richard Barnette | 67ccb87 | 2012-04-19 16:34:56 -0700 | [diff] [blame] | 290 | |
Ricky Liang | 0dd379c | 2014-04-23 16:29:08 +0800 | [diff] [blame] | 291 | def __init__(self, servo_host, servo_serial=None): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 292 | """Sets up the servo communication infrastructure. |
| 293 | |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 294 | @param servo_host: A ServoHost object representing |
| 295 | the host running servod. |
Dana Goyette | a2f00ea | 2019-06-26 16:14:12 -0700 | [diff] [blame] | 296 | @type servo_host: autotest_lib.server.hosts.servo_host.ServoHost |
Ricky Liang | 0dd379c | 2014-04-23 16:29:08 +0800 | [diff] [blame] | 297 | @param servo_serial: Serial number of the servo board. |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 298 | """ |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 299 | # TODO(fdeng): crbug.com/298379 |
| 300 | # We should move servo_host object out of servo object |
| 301 | # to minimize the dependencies on the rest of Autotest. |
| 302 | self._servo_host = servo_host |
Ricky Liang | 0dd379c | 2014-04-23 16:29:08 +0800 | [diff] [blame] | 303 | self._servo_serial = servo_serial |
Richard Barnette | 180efe6 | 2016-12-02 23:20:44 +0000 | [diff] [blame] | 304 | self._server = servo_host.get_servod_server_proxy() |
J. Richard Barnette | 0c9c588 | 2014-06-11 15:27:05 -0700 | [diff] [blame] | 305 | self._power_state = _PowerStateController(self) |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 306 | self._uart = _Uart(self) |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 307 | self._usb_state = None |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 308 | self._programmer = None |
Dana Goyette | 4dc0adc | 2019-05-06 14:51:53 -0700 | [diff] [blame] | 309 | self._prev_log_inode = None |
| 310 | self._prev_log_size = 0 |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 311 | |
Ricky Liang | 0dd379c | 2014-04-23 16:29:08 +0800 | [diff] [blame] | 312 | @property |
| 313 | def servo_serial(self): |
| 314 | """Returns the serial number of the servo board.""" |
| 315 | return self._servo_serial |
| 316 | |
Dana Goyette | 6006ead | 2019-10-04 17:12:24 +0000 | [diff] [blame] | 317 | def fetch_servod_log(self, filename=None, skip_old=False): |
| 318 | """Save the servod log into the given local file. |
Dana Goyette | 4dc0adc | 2019-05-06 14:51:53 -0700 | [diff] [blame] | 319 | |
Dana Goyette | 6006ead | 2019-10-04 17:12:24 +0000 | [diff] [blame] | 320 | @param filename: save the contents into a file with the given name. |
| 321 | @param skip_old: if True, skip past the old data in the log file. |
| 322 | @type filename: str |
| 323 | @type skip_old: bool |
| 324 | @rtype: None |
Dana Goyette | 4dc0adc | 2019-05-06 14:51:53 -0700 | [diff] [blame] | 325 | """ |
Dana Goyette | 6006ead | 2019-10-04 17:12:24 +0000 | [diff] [blame] | 326 | return self._servo_host.fetch_servod_log(filename, skip_old) |
Ricky Liang | 0dd379c | 2014-04-23 16:29:08 +0800 | [diff] [blame] | 327 | |
Tom Wai-Hong Tam | 22ee0e5 | 2013-04-03 13:36:39 +0800 | [diff] [blame] | 328 | def get_power_state_controller(self): |
J. Richard Barnette | 75136b3 | 2013-03-26 13:38:44 -0700 | [diff] [blame] | 329 | """Return the power state controller for this Servo. |
| 330 | |
| 331 | The power state controller provides board-independent |
| 332 | interfaces for reset, power-on, power-off operations. |
| 333 | |
| 334 | """ |
| 335 | return self._power_state |
| 336 | |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 337 | |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 338 | def initialize_dut(self, cold_reset=False): |
| 339 | """Initializes a dut for testing purposes. |
| 340 | |
| 341 | This sets various servo signals back to default values |
| 342 | appropriate for the target board. By default, if the DUT |
| 343 | is already on, it stays on. If the DUT is powered off |
| 344 | before initialization, its state afterward is unspecified. |
| 345 | |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 346 | Rationale: Basic initialization of servo sets the lid open, |
| 347 | when there is a lid. This operation won't affect powered on |
| 348 | units; however, setting the lid open may power on a unit |
J. Richard Barnette | 75136b3 | 2013-03-26 13:38:44 -0700 | [diff] [blame] | 349 | that's off, depending on the board type and previous state |
| 350 | of the device. |
| 351 | |
J. Richard Barnette | 4b6af0d | 2014-06-05 09:57:20 -0700 | [diff] [blame] | 352 | If `cold_reset` is a true value, the DUT and its EC will be |
| 353 | reset, and the DUT rebooted in normal mode. |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 354 | |
| 355 | @param cold_reset If True, cold reset the device after |
| 356 | initialization. |
| 357 | """ |
Dana Goyette | a2f00ea | 2019-06-26 16:14:12 -0700 | [diff] [blame] | 358 | try: |
| 359 | self._server.hwinit() |
| 360 | except socket.error as e: |
| 361 | e.filename = '%s:%s' % (self._servo_host.hostname, |
| 362 | self._servo_host.servo_port) |
| 363 | raise |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 364 | self.set('usb_mux_oe1', 'on') |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 365 | self._usb_state = None |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 366 | self.switch_usbkey('off') |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 367 | self._uart.start_capture() |
J. Richard Barnette | b613397 | 2012-07-19 17:13:55 -0700 | [diff] [blame] | 368 | if cold_reset: |
J. Richard Barnette | 4b6af0d | 2014-06-05 09:57:20 -0700 | [diff] [blame] | 369 | self._power_state.reset() |
J. Richard Barnette | 1777f5d | 2014-09-03 15:18:19 -0700 | [diff] [blame] | 370 | logging.debug('Servo initialized, version is %s', |
| 371 | self._server.get_version()) |
Ruben Rodriguez Buchillon | b0e2a9f | 2019-08-12 12:40:44 -0700 | [diff] [blame] | 372 | if self.has_control('init_keyboard'): |
| 373 | # This indicates the servod version does not |
| 374 | # have explicit keyboard initialization yet. |
| 375 | # Ignore this. |
Ruben Rodriguez Buchillon | 0529824 | 2019-05-20 11:29:06 -0700 | [diff] [blame] | 376 | # TODO(coconutruben): change this back to set() about a month |
| 377 | # after crrev.com/c/1586239 has been merged (or whenever that |
| 378 | # logic is in the labstation images). |
| 379 | self.set_nocheck('init_keyboard','on') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 380 | |
| 381 | |
Tom Wai-Hong Tam | 1c86c7a | 2012-10-22 10:08:24 +0800 | [diff] [blame] | 382 | def is_localhost(self): |
| 383 | """Is the servod hosted locally? |
| 384 | |
| 385 | Returns: |
| 386 | True if local hosted; otherwise, False. |
| 387 | """ |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 388 | return self._servo_host.is_localhost() |
Tom Wai-Hong Tam | 1c86c7a | 2012-10-22 10:08:24 +0800 | [diff] [blame] | 389 | |
| 390 | |
Mary Ruthven | ecf1271 | 2019-06-26 17:36:21 -0700 | [diff] [blame] | 391 | def get_os_version(self): |
| 392 | """Returns the chromeos release version.""" |
| 393 | lsb_release_content = self.system_output('cat /etc/lsb-release', |
| 394 | ignore_status=True) |
| 395 | return lsbrelease_utils.get_chromeos_release_builder_path( |
| 396 | lsb_release_content=lsb_release_content) |
| 397 | |
| 398 | |
Mary Ruthven | 83bb595 | 2019-06-27 12:34:05 -0700 | [diff] [blame] | 399 | def get_servod_version(self): |
| 400 | """Returns the servod version.""" |
| 401 | result = self._servo_host.run('servod --version') |
| 402 | # TODO: use system_output once servod --version prints to stdout |
| 403 | stdout = result.stdout.strip() |
| 404 | return stdout if stdout else result.stderr.strip() |
| 405 | |
| 406 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 407 | def power_long_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 408 | """Simulate a long power button press.""" |
J. Richard Barnette | f12bff2 | 2012-07-18 14:41:06 -0700 | [diff] [blame] | 409 | # After a long power press, the EC may ignore the next power |
| 410 | # button press (at least on Alex). To guarantee that this |
| 411 | # won't happen, we need to allow the EC one second to |
| 412 | # collect itself. |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 413 | # long_press is defined as 8.5s in servod |
| 414 | self.set_nocheck('power_key', 'long_press') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 415 | |
| 416 | |
| 417 | def power_normal_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 418 | """Simulate a normal power button press.""" |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 419 | # press is defined as 1.2s in servod |
| 420 | self.set_nocheck('power_key', 'press') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 421 | |
| 422 | |
| 423 | def power_short_press(self): |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 424 | """Simulate a short power button press.""" |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 425 | # tab is defined as 0.2s in servod |
| 426 | self.set_nocheck('power_key', 'tab') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 427 | |
| 428 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 429 | def power_key(self, press_secs='tab'): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 430 | """Simulate a power button press. |
| 431 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 432 | @param press_secs: int, float, str; time to press key in seconds or |
| 433 | known shorthand: 'tab' 'press' 'long_press' |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 434 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 435 | self.set_nocheck('power_key', press_secs) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 436 | |
| 437 | |
Ruben Zakarian | 47c1d4f | 2019-09-30 14:17:41 -0700 | [diff] [blame^] | 438 | def pwr_button(self, action='press'): |
| 439 | """Simulate a power button press. |
| 440 | |
| 441 | @param action: str; could be press or could be release. |
| 442 | """ |
| 443 | self.set_nocheck('pwr_button', action) |
| 444 | |
| 445 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 446 | def lid_open(self): |
Yuli Huang | 7b82dcf | 2015-05-13 17:58:52 +0800 | [diff] [blame] | 447 | """Simulate opening the lid and raise exception if all attempts fail""" |
| 448 | self.set('lid_open', 'yes') |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 449 | |
| 450 | |
| 451 | def lid_close(self): |
Yuli Huang | 7b82dcf | 2015-05-13 17:58:52 +0800 | [diff] [blame] | 452 | """Simulate closing the lid and raise exception if all attempts fail |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 453 | |
| 454 | Waits 6 seconds to ensure the device is fully asleep before returning. |
| 455 | """ |
Yuli Huang | 7b82dcf | 2015-05-13 17:58:52 +0800 | [diff] [blame] | 456 | self.set('lid_open', 'no') |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 457 | time.sleep(Servo.SLEEP_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 458 | |
Ruben Zakarian | 47c1d4f | 2019-09-30 14:17:41 -0700 | [diff] [blame^] | 459 | |
| 460 | def vbus_power_get(self): |
| 461 | """Get current vbus_power.""" |
| 462 | return self.get('vbus_power') |
| 463 | |
| 464 | |
Shelley Chen | c26575a | 2015-09-18 10:56:16 -0700 | [diff] [blame] | 465 | def volume_up(self, timeout=300): |
Kevin Cheng | e448a8b | 2016-09-09 10:18:11 -0700 | [diff] [blame] | 466 | """Simulate pushing the volume down button. |
| 467 | |
| 468 | @param timeout: Timeout for setting the volume. |
| 469 | """ |
Shelley Chen | c26575a | 2015-09-18 10:56:16 -0700 | [diff] [blame] | 470 | self.set_get_all(['volume_up:yes', |
| 471 | 'sleep:%.4f' % self.SERVO_KEY_PRESS_DELAY, |
| 472 | 'volume_up:no']) |
| 473 | # we need to wait for commands to take effect before moving on |
| 474 | time_left = float(timeout) |
| 475 | while time_left > 0.0: |
| 476 | value = self.get('volume_up') |
| 477 | if value == 'no': |
| 478 | return |
| 479 | time.sleep(self.SHORT_DELAY) |
| 480 | time_left = time_left - self.SHORT_DELAY |
| 481 | raise error.TestFail("Failed setting volume_up to no") |
| 482 | |
| 483 | def volume_down(self, timeout=300): |
Kevin Cheng | e448a8b | 2016-09-09 10:18:11 -0700 | [diff] [blame] | 484 | """Simulate pushing the volume down button. |
| 485 | |
| 486 | @param timeout: Timeout for setting the volume. |
| 487 | """ |
Shelley Chen | c26575a | 2015-09-18 10:56:16 -0700 | [diff] [blame] | 488 | self.set_get_all(['volume_down:yes', |
| 489 | 'sleep:%.4f' % self.SERVO_KEY_PRESS_DELAY, |
| 490 | 'volume_down:no']) |
| 491 | # we need to wait for commands to take effect before moving on |
| 492 | time_left = float(timeout) |
| 493 | while time_left > 0.0: |
| 494 | value = self.get('volume_down') |
| 495 | if value == 'no': |
| 496 | return |
| 497 | time.sleep(self.SHORT_DELAY) |
| 498 | time_left = time_left - self.SHORT_DELAY |
| 499 | raise error.TestFail("Failed setting volume_down to no") |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 500 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 501 | def ctrl_d(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 502 | """Simulate Ctrl-d simultaneous button presses. |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 503 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 504 | @param press_secs: int, float, str; time to press key in seconds or |
| 505 | known shorthand: 'tab' 'press' 'long_press' |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 506 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 507 | self.set_nocheck('ctrl_d', press_secs) |
Gediminas Ramanauskas | 9da80f2 | 2012-11-14 12:59:43 -0800 | [diff] [blame] | 508 | |
Gediminas Ramanauskas | ba352ad | 2012-11-09 09:43:32 -0800 | [diff] [blame] | 509 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 510 | def ctrl_u(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 511 | """Simulate Ctrl-u simultaneous button presses. |
| 512 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 513 | @param press_secs: int, float, str; time to press key in seconds or |
| 514 | known shorthand: 'tab' 'press' 'long_press' |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 515 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 516 | self.set_nocheck('ctrl_u', press_secs) |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 517 | |
| 518 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 519 | def ctrl_enter(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 520 | """Simulate Ctrl-enter simultaneous button presses. |
| 521 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 522 | @param press_secs: int, float, str; time to press key in seconds or |
| 523 | known shorthand: 'tab' 'press' 'long_press' |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 524 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 525 | self.set_nocheck('ctrl_enter', press_secs) |
Gediminas Ramanauskas | 3297d4f | 2012-09-10 15:30:10 -0700 | [diff] [blame] | 526 | |
| 527 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 528 | def ctrl_key(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 529 | """Simulate Enter key button press. |
| 530 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 531 | @param press_secs: int, float, str; time to press key in seconds or |
| 532 | known shorthand: 'tab' 'press' 'long_press' |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 533 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 534 | self.set_nocheck('ctrl_key', press_secs) |
Todd Broch | 9dfc3a8 | 2011-11-01 08:09:28 -0700 | [diff] [blame] | 535 | |
| 536 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 537 | def enter_key(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 538 | """Simulate Enter key button press. |
| 539 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 540 | @param press_secs: int, float, str; time to press key in seconds or |
| 541 | known shorthand: 'tab' 'press' 'long_press' |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 542 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 543 | self.set_nocheck('enter_key', press_secs) |
Todd Broch | 9753bd4 | 2012-03-21 10:15:08 -0700 | [diff] [blame] | 544 | |
| 545 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 546 | def refresh_key(self, press_secs='tab'): |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 547 | """Simulate Refresh key (F3) button press. |
| 548 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 549 | @param press_secs: int, float, str; time to press key in seconds or |
| 550 | known shorthand: 'tab' 'press' 'long_press' |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 551 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 552 | self.set_nocheck('refresh_key', press_secs) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 553 | |
| 554 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 555 | def ctrl_refresh_key(self, press_secs='tab'): |
Tom Wai-Hong Tam | 9e61e66 | 2012-08-01 15:10:07 +0800 | [diff] [blame] | 556 | """Simulate Ctrl and Refresh (F3) simultaneous press. |
| 557 | |
| 558 | This key combination is an alternative of Space key. |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 559 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 560 | @param press_secs: int, float, str; time to press key in seconds or |
| 561 | known shorthand: 'tab' 'press' 'long_press' |
Tom Wai-Hong Tam | 9e61e66 | 2012-08-01 15:10:07 +0800 | [diff] [blame] | 562 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 563 | self.set_nocheck('ctrl_refresh_key', press_secs) |
Tom Wai-Hong Tam | 9e61e66 | 2012-08-01 15:10:07 +0800 | [diff] [blame] | 564 | |
| 565 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 566 | def imaginary_key(self, press_secs='tab'): |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 567 | """Simulate imaginary key button press. |
| 568 | |
| 569 | Maps to a key that doesn't physically exist. |
Yusuf Mohsinally | 103441a | 2014-01-14 15:25:44 -0800 | [diff] [blame] | 570 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 571 | @param press_secs: int, float, str; time to press key in seconds or |
| 572 | known shorthand: 'tab' 'press' 'long_press' |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 573 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 574 | self.set_nocheck('imaginary_key', press_secs) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 575 | |
| 576 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 577 | def sysrq_x(self, press_secs='tab'): |
Vincent Palatin | e7dc928 | 2016-07-14 11:31:58 +0200 | [diff] [blame] | 578 | """Simulate Alt VolumeUp X simulataneous press. |
| 579 | |
| 580 | This key combination is the kernel system request (sysrq) X. |
| 581 | |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 582 | @param press_secs: int, float, str; time to press key in seconds or |
| 583 | known shorthand: 'tab' 'press' 'long_press' |
Vincent Palatin | e7dc928 | 2016-07-14 11:31:58 +0200 | [diff] [blame] | 584 | """ |
Ruben Rodriguez Buchillon | 84eba75 | 2018-07-27 17:59:48 +0800 | [diff] [blame] | 585 | self.set_nocheck('sysrq_x', press_secs) |
Vincent Palatin | e7dc928 | 2016-07-14 11:31:58 +0200 | [diff] [blame] | 586 | |
| 587 | |
Tom Wai-Hong Tam | 93b5c09 | 2015-05-14 02:50:43 +0800 | [diff] [blame] | 588 | def toggle_recovery_switch(self): |
| 589 | """Toggle recovery switch on and off.""" |
| 590 | self.enable_recovery_mode() |
| 591 | time.sleep(self.REC_TOGGLE_DELAY) |
| 592 | self.disable_recovery_mode() |
| 593 | |
| 594 | |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 595 | def enable_recovery_mode(self): |
| 596 | """Enable recovery mode on device.""" |
| 597 | self.set('rec_mode', 'on') |
| 598 | |
| 599 | |
| 600 | def disable_recovery_mode(self): |
| 601 | """Disable recovery mode on device.""" |
| 602 | self.set('rec_mode', 'off') |
| 603 | |
| 604 | |
Tom Wai-Hong Tam | f9ded09 | 2015-05-20 05:37:22 +0800 | [diff] [blame] | 605 | def toggle_development_switch(self): |
| 606 | """Toggle development switch on and off.""" |
| 607 | self.enable_development_mode() |
| 608 | time.sleep(self.DEV_TOGGLE_DELAY) |
| 609 | self.disable_development_mode() |
| 610 | |
| 611 | |
Craig Harrison | 6b36b12 | 2011-06-28 17:58:43 -0700 | [diff] [blame] | 612 | def enable_development_mode(self): |
| 613 | """Enable development mode on device.""" |
| 614 | self.set('dev_mode', 'on') |
| 615 | |
| 616 | |
| 617 | def disable_development_mode(self): |
| 618 | """Disable development mode on device.""" |
| 619 | self.set('dev_mode', 'off') |
| 620 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 621 | def boot_devmode(self): |
| 622 | """Boot a dev-mode device that is powered off.""" |
Tom Wai-Hong Tam | 2386910 | 2012-01-17 15:41:30 +0800 | [diff] [blame] | 623 | self.power_short_press() |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 624 | self.pass_devmode() |
| 625 | |
| 626 | |
| 627 | def pass_devmode(self): |
| 628 | """Pass through boot screens in dev-mode.""" |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 629 | time.sleep(Servo.BOOT_DELAY) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 630 | self.ctrl_d() |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 631 | time.sleep(Servo.BOOT_DELAY) |
Craig Harrison | 4899726 | 2011-06-27 14:31:10 -0700 | [diff] [blame] | 632 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 633 | |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 634 | def get_board(self): |
Wai-Hong Tam | 0f90400 | 2017-09-19 15:52:22 -0700 | [diff] [blame] | 635 | """Get the board connected to servod.""" |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 636 | return self._server.get_board() |
| 637 | |
| 638 | |
Wai-Hong Tam | 0f90400 | 2017-09-19 15:52:22 -0700 | [diff] [blame] | 639 | def get_base_board(self): |
| 640 | """Get the board of the base connected to servod.""" |
Wai-Hong Tam | 7f6169e | 2017-09-29 09:23:48 -0700 | [diff] [blame] | 641 | try: |
| 642 | return self._server.get_base_board() |
| 643 | except xmlrpclib.Fault as e: |
| 644 | # TODO(waihong): Remove the following compatibility check when |
| 645 | # the new versions of hdctools are deployed. |
| 646 | if 'not supported' in str(e): |
| 647 | logging.warning('The servod is too old that get_base_board ' |
| 648 | 'not supported.') |
| 649 | return '' |
| 650 | raise |
Wai-Hong Tam | 0f90400 | 2017-09-19 15:52:22 -0700 | [diff] [blame] | 651 | |
| 652 | |
Wai-Hong Tam | cc399ee | 2017-12-08 12:43:28 -0800 | [diff] [blame] | 653 | def get_ec_active_copy(self): |
| 654 | """Get the active copy of the EC image.""" |
| 655 | return self.get('ec_active_copy') |
| 656 | |
| 657 | |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 658 | def _get_xmlrpclib_exception(self, xmlexc): |
| 659 | """Get meaningful exception string from xmlrpc. |
| 660 | |
| 661 | Args: |
| 662 | xmlexc: xmlrpclib.Fault object |
| 663 | |
| 664 | xmlrpclib.Fault.faultString has the following format: |
| 665 | |
| 666 | <type 'exception type'>:'actual error message' |
| 667 | |
| 668 | Parse and return the real exception from the servod side instead of the |
| 669 | less meaningful one like, |
| 670 | <Fault 1: "<type 'exceptions.AttributeError'>:'tca6416' object has no |
| 671 | attribute 'hw_driver'"> |
| 672 | |
| 673 | Returns: |
| 674 | string of underlying exception raised in servod. |
| 675 | """ |
| 676 | return re.sub('^.*>:', '', xmlexc.faultString) |
| 677 | |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 678 | def has_control(self, control): |
| 679 | """Query servod server to determine if |control| is a valid control. |
| 680 | |
| 681 | @param control: str, control name to query |
| 682 | |
| 683 | @returns: true if |control| is a known control, false otherwise. |
| 684 | """ |
| 685 | assert control |
| 686 | try: |
| 687 | # If the control exists, doc() will work. |
| 688 | self._server.doc(control) |
| 689 | return True |
| 690 | except xmlrpclib.Fault as e: |
| 691 | if re.search('No control %s' % control, |
| 692 | self._get_xmlrpclib_exception(e)): |
| 693 | return False |
| 694 | raise e |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 695 | |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 696 | def get(self, gpio_name): |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 697 | """Get the value of a gpio from Servod. |
| 698 | |
| 699 | @param gpio_name Name of the gpio. |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 700 | |
| 701 | @returns: server response to |gpio_name| request. |
| 702 | |
| 703 | @raise ControlUnavailableError: if |gpio_name| not a known control. |
| 704 | @raise error.TestFail: for all other failures doing get(). |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 705 | """ |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 706 | assert gpio_name |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 707 | try: |
Simran Basi | 1cbc5f2 | 2013-07-17 14:23:58 -0700 | [diff] [blame] | 708 | return self._server.get(gpio_name) |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 709 | except xmlrpclib.Fault as e: |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 710 | err_str = self._get_xmlrpclib_exception(e) |
| 711 | err_msg = "Getting '%s' :: %s" % (gpio_name, err_str) |
| 712 | unknown_ctrl = re.findall(NO_CONTROL_RE, err_str) |
| 713 | if unknown_ctrl: |
| 714 | raise ControlUnavailableError('No control named %r' % |
| 715 | unknown_ctrl[0]) |
| 716 | else: |
| 717 | logging.error(err_msg) |
| 718 | raise error.TestFail(err_msg) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 719 | |
| 720 | |
| 721 | def set(self, gpio_name, gpio_value): |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 722 | """Set and check the value of a gpio using Servod. |
| 723 | |
| 724 | @param gpio_name Name of the gpio. |
| 725 | @param gpio_value New setting for the gpio. |
| 726 | """ |
Chrome Bot | 9a1137d | 2011-07-19 14:35:00 -0700 | [diff] [blame] | 727 | self.set_nocheck(gpio_name, gpio_value) |
Todd Broch | cf7c665 | 2012-02-24 13:03:59 -0800 | [diff] [blame] | 728 | retry_count = Servo.GET_RETRY_MAX |
| 729 | while gpio_value != self.get(gpio_name) and retry_count: |
Ilja H. Friedel | 04be2bd | 2014-05-07 21:29:59 -0700 | [diff] [blame] | 730 | logging.warning("%s != %s, retry %d", gpio_name, gpio_value, |
Todd Broch | cf7c665 | 2012-02-24 13:03:59 -0800 | [diff] [blame] | 731 | retry_count) |
| 732 | retry_count -= 1 |
| 733 | time.sleep(Servo.SHORT_DELAY) |
| 734 | if not retry_count: |
| 735 | assert gpio_value == self.get(gpio_name), \ |
| 736 | 'Servo failed to set %s to %s' % (gpio_name, gpio_value) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 737 | |
| 738 | |
| 739 | def set_nocheck(self, gpio_name, gpio_value): |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 740 | """Set the value of a gpio using Servod. |
| 741 | |
| 742 | @param gpio_name Name of the gpio. |
| 743 | @param gpio_value New setting for the gpio. |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 744 | |
| 745 | @raise ControlUnavailableError: if |gpio_name| not a known control. |
| 746 | @raise error.TestFail: for all other failures doing set(). |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 747 | """ |
Ruben Rodriguez Buchillon | 1c0219c | 2019-06-25 12:30:44 -0700 | [diff] [blame] | 748 | # The real danger here is to pass a None value through the xmlrpc. |
| 749 | assert gpio_name and gpio_value is not None |
Mary Ruthven | dfa4534 | 2019-06-25 10:10:17 -0700 | [diff] [blame] | 750 | logging.debug('Setting %s to %r', gpio_name, gpio_value) |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 751 | try: |
Simran Basi | 1cbc5f2 | 2013-07-17 14:23:58 -0700 | [diff] [blame] | 752 | self._server.set(gpio_name, gpio_value) |
Todd Broch | efe72cb | 2012-07-11 19:58:53 -0700 | [diff] [blame] | 753 | except xmlrpclib.Fault as e: |
Ruben Rodriguez Buchillon | 2cba8e4 | 2019-08-12 11:31:53 -0700 | [diff] [blame] | 754 | err_str = self._get_xmlrpclib_exception(e) |
| 755 | err_msg = "Setting '%s' :: %s" % (gpio_name, err_str) |
| 756 | unknown_ctrl = re.findall(NO_CONTROL_RE, err_str) |
| 757 | if unknown_ctrl: |
| 758 | raise ControlUnavailableError('No control named %r' % |
| 759 | unknown_ctrl[0]) |
| 760 | else: |
| 761 | logging.error(err_msg) |
| 762 | raise error.TestFail(err_msg) |
Craig Harrison | 2b6c6fc | 2011-06-23 10:34:02 -0700 | [diff] [blame] | 763 | |
| 764 | |
Tom Wai-Hong Tam | 92569bb | 2013-03-26 14:25:10 +0800 | [diff] [blame] | 765 | def set_get_all(self, controls): |
| 766 | """Set &| get one or more control values. |
| 767 | |
| 768 | @param controls: list of strings, controls to set &| get. |
| 769 | |
| 770 | @raise: error.TestError in case error occurs setting/getting values. |
| 771 | """ |
| 772 | rv = [] |
| 773 | try: |
Mary Ruthven | dfa4534 | 2019-06-25 10:10:17 -0700 | [diff] [blame] | 774 | logging.debug('Set/get all: %s', str(controls)) |
Tom Wai-Hong Tam | 92569bb | 2013-03-26 14:25:10 +0800 | [diff] [blame] | 775 | rv = self._server.set_get_all(controls) |
| 776 | except xmlrpclib.Fault as e: |
| 777 | # TODO(waihong): Remove the following backward compatibility when |
| 778 | # the new versions of hdctools are deployed. |
| 779 | if 'not supported' in str(e): |
| 780 | logging.warning('The servod is too old that set_get_all ' |
| 781 | 'not supported. Use set and get instead.') |
| 782 | for control in controls: |
| 783 | if ':' in control: |
| 784 | (name, value) = control.split(':') |
| 785 | if name == 'sleep': |
| 786 | time.sleep(float(value)) |
| 787 | else: |
| 788 | self.set_nocheck(name, value) |
| 789 | rv.append(True) |
| 790 | else: |
| 791 | rv.append(self.get(name)) |
| 792 | else: |
| 793 | err_msg = "Problem with '%s' :: %s" % \ |
| 794 | (controls, self._get_xmlrpclib_exception(e)) |
| 795 | raise error.TestFail(err_msg) |
| 796 | return rv |
| 797 | |
| 798 | |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 799 | # TODO(waihong) It may fail if multiple servo's are connected to the same |
| 800 | # host. Should look for a better way, like the USB serial name, to identify |
| 801 | # the USB device. |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 802 | # TODO(sbasi) Remove this code from autoserv once firmware tests have been |
| 803 | # updated. |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 804 | def probe_host_usb_dev(self, timeout=_USB_PROBE_TIMEOUT): |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 805 | """Probe the USB disk device plugged-in the servo from the host side. |
| 806 | |
Kevin Cheng | eb06fe7 | 2016-08-22 15:26:32 -0700 | [diff] [blame] | 807 | It uses servod to discover if there is a usb device attached to it. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 808 | |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 809 | @param timeout The timeout period when probing for the usb host device. |
| 810 | |
| 811 | @return: String of USB disk path (e.g. '/dev/sdb') or None. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 812 | """ |
Ruben Rodriguez Buchillon | 9a4bfc3 | 2018-10-16 20:46:25 +0800 | [diff] [blame] | 813 | # Set up Servo's usb mux. |
| 814 | self.switch_usbkey('host') |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 815 | return self._server.probe_host_usb_dev(timeout) or None |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 816 | |
| 817 | |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 818 | def image_to_servo_usb(self, image_path=None, |
| 819 | make_image_noninteractive=False): |
| 820 | """Install an image to the USB key plugged into the servo. |
| 821 | |
| 822 | This method may copy any image to the servo USB key including a |
| 823 | recovery image or a test image. These images are frequently used |
| 824 | for test purposes such as restoring a corrupted image or conducting |
| 825 | an upgrade of ec/fw/kernel as part of a test of a specific image part. |
| 826 | |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 827 | @param image_path Path on the host to the recovery image. |
| 828 | @param make_image_noninteractive Make the recovery image |
| 829 | noninteractive, therefore the DUT |
| 830 | will reboot automatically after |
| 831 | installation. |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 832 | """ |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 833 | # We're about to start plugging/unplugging the USB key. We |
| 834 | # don't know the state of the DUT, or what it might choose |
| 835 | # to do to the device after hotplug. To avoid surprises, |
| 836 | # force the DUT to be off. |
| 837 | self._server.hwinit() |
Ruben Rodriguez Buchillon | b0e2a9f | 2019-08-12 12:40:44 -0700 | [diff] [blame] | 838 | if self.has_control('init_keyboard'): |
| 839 | # This indicates the servod version does not |
| 840 | # have explicit keyboard initialization yet. |
| 841 | # Ignore this. |
Ruben Rodriguez Buchillon | bd3b74f | 2019-08-08 16:18:27 -0700 | [diff] [blame] | 842 | # TODO(coconutruben): change this back to set() about a month |
| 843 | # after crrev.com/c/1586239 has been merged (or whenever that |
| 844 | # logic is in the labstation images). |
| 845 | self.set_nocheck('init_keyboard','on') |
J. Richard Barnette | 41320ee | 2013-03-11 13:00:13 -0700 | [diff] [blame] | 846 | self._power_state.power_off() |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 847 | |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 848 | if image_path: |
Garry Wang | d265681 | 2019-08-07 17:29:16 -0700 | [diff] [blame] | 849 | # Set up Servo's usb mux. |
| 850 | self.switch_usbkey('host') |
Tom Wai-Hong Tam | 42f136d | 2012-10-26 11:11:23 +0800 | [diff] [blame] | 851 | logging.info('Searching for usb device and copying image to it. ' |
| 852 | 'Please wait a few minutes...') |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 853 | if not self._server.download_image_to_usb(image_path): |
| 854 | logging.error('Failed to transfer requested image to USB. ' |
| 855 | 'Please take a look at Servo Logs.') |
| 856 | raise error.AutotestError('Download image to usb failed.') |
| 857 | if make_image_noninteractive: |
| 858 | logging.info('Making image noninteractive') |
| 859 | if not self._server.make_image_noninteractive(): |
| 860 | logging.error('Failed to make image noninteractive. ' |
| 861 | 'Please take a look at Servo Logs.') |
| 862 | |
Kalin Stoyanov | b3c11f3 | 2018-05-11 09:02:00 -0700 | [diff] [blame] | 863 | def boot_in_recovery_mode(self): |
| 864 | """Boot host DUT in recovery mode.""" |
| 865 | self._power_state.power_on(rec_mode=self._power_state.REC_ON) |
| 866 | self.switch_usbkey('dut') |
| 867 | |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 868 | |
Simran Basi | 741b5d4 | 2012-05-18 11:27:15 -0700 | [diff] [blame] | 869 | def install_recovery_image(self, image_path=None, |
J. Richard Barnette | b6de7e3 | 2013-02-14 13:28:04 -0800 | [diff] [blame] | 870 | make_image_noninteractive=False): |
Dan Shi | c67f133 | 2016-04-06 12:38:06 -0700 | [diff] [blame] | 871 | """Install the recovery image specified by the path onto the DUT. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 872 | |
| 873 | This method uses google recovery mode to install a recovery image |
| 874 | onto a DUT through the use of a USB stick that is mounted on a servo |
Tom Wai-Hong Tam | a07115e | 2012-01-09 12:27:01 +0800 | [diff] [blame] | 875 | board specified by the usb_dev. If no image path is specified |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 876 | we use the recovery image already on the usb image. |
| 877 | |
Dan Shi | c67f133 | 2016-04-06 12:38:06 -0700 | [diff] [blame] | 878 | @param image_path: Path on the host to the recovery image. |
| 879 | @param make_image_noninteractive: Make the recovery image |
| 880 | noninteractive, therefore the DUT will reboot automatically |
| 881 | after installation. |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 882 | """ |
Mike Truty | 49153d8 | 2012-08-21 22:27:30 -0500 | [diff] [blame] | 883 | self.image_to_servo_usb(image_path, make_image_noninteractive) |
Garry Wang | d265681 | 2019-08-07 17:29:16 -0700 | [diff] [blame] | 884 | # Give the DUT some time to power_off if we skip |
| 885 | # download image to usb. (crbug.com/982993) |
| 886 | if not image_path: |
| 887 | time.sleep(10) |
Kalin Stoyanov | b3c11f3 | 2018-05-11 09:02:00 -0700 | [diff] [blame] | 888 | self.boot_in_recovery_mode() |
Jon Salz | c88e5b6 | 2011-11-30 14:38:54 +0800 | [diff] [blame] | 889 | |
| 890 | |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 891 | def _scp_image(self, image_path): |
| 892 | """Copy image to the servo host. |
| 893 | |
| 894 | When programming a firmware image on the DUT, the image must be |
| 895 | located on the host to which the servo device is connected. Sometimes |
| 896 | servo is controlled by a remote host, in this case the image needs to |
| 897 | be transferred to the remote host. |
| 898 | |
| 899 | @param image_path: a string, name of the firmware image file to be |
| 900 | transferred. |
| 901 | @return: a string, full path name of the copied file on the remote. |
| 902 | """ |
| 903 | |
| 904 | dest_path = os.path.join('/tmp', os.path.basename(image_path)) |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 905 | self._servo_host.send_file(image_path, dest_path) |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 906 | return dest_path |
| 907 | |
| 908 | |
Dan Shi | fecdaf4 | 2015-07-28 10:17:26 -0700 | [diff] [blame] | 909 | def system(self, command, timeout=3600): |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 910 | """Execute the passed in command on the servod host. |
| 911 | |
| 912 | @param command Command to be executed. |
Dan Shi | fecdaf4 | 2015-07-28 10:17:26 -0700 | [diff] [blame] | 913 | @param timeout Maximum number of seconds of runtime allowed. Default to |
| 914 | 1 hour. |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 915 | """ |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 916 | logging.info('Will execute on servo host: %s', command) |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 917 | self._servo_host.run(command, timeout=timeout) |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 918 | |
| 919 | |
Dan Shi | fecdaf4 | 2015-07-28 10:17:26 -0700 | [diff] [blame] | 920 | def system_output(self, command, timeout=3600, |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 921 | ignore_status=False, args=()): |
| 922 | """Execute the passed in command on the servod host, return stdout. |
| 923 | |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 924 | @param command a string, the command to execute |
| 925 | @param timeout an int, max number of seconds to wait til command |
Dan Shi | fecdaf4 | 2015-07-28 10:17:26 -0700 | [diff] [blame] | 926 | execution completes. Default to 1 hour. |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 927 | @param ignore_status a Boolean, if true - ignore command's nonzero exit |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 928 | status, otherwise an exception will be thrown |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 929 | @param args a tuple of strings, each becoming a separate command line |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 930 | parameter for the command |
J. Richard Barnette | cdd1edf | 2015-07-24 11:39:46 -0700 | [diff] [blame] | 931 | @return command's stdout as a string. |
Vadim Bendebury | 89ec24e | 2012-12-17 12:54:18 -0800 | [diff] [blame] | 932 | """ |
Fang Deng | 5d518f4 | 2013-08-02 14:04:32 -0700 | [diff] [blame] | 933 | return self._servo_host.run(command, timeout=timeout, |
| 934 | ignore_status=ignore_status, |
| 935 | args=args).stdout.strip() |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 936 | |
| 937 | |
Mary Ruthven | 38d90af | 2019-08-16 13:13:31 -0700 | [diff] [blame] | 938 | def get_servo_version(self, active=False): |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 939 | """Get the version of the servo, e.g., servo_v2 or servo_v3. |
| 940 | |
Mary Ruthven | 38d90af | 2019-08-16 13:13:31 -0700 | [diff] [blame] | 941 | @param active: Only return the servo type with the active device. |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 942 | @return: The version of the servo. |
| 943 | |
| 944 | """ |
Mary Ruthven | 38d90af | 2019-08-16 13:13:31 -0700 | [diff] [blame] | 945 | servo_type = self._server.get_version() |
| 946 | if '_and_' not in servo_type or not active: |
| 947 | return servo_type |
| 948 | |
| 949 | # If servo v4 is using ccd and servo micro, modify the servo type to |
| 950 | # reflect the active device. |
| 951 | active_device = self.get('active_v4_device') |
| 952 | if active_device in servo_type: |
| 953 | logging.info('%s is active', active_device) |
| 954 | return 'servo_v4_with_' + active_device |
| 955 | |
| 956 | logging.warn("%s is active even though it's not in servo type", |
| 957 | active_device) |
| 958 | return servo_type |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 959 | |
| 960 | |
Mary Ruthven | 2724ee6 | 2019-07-16 11:16:59 -0700 | [diff] [blame] | 961 | def running_through_ccd(self): |
| 962 | """Returns True if the setup is using ccd to run.""" |
| 963 | servo = self._server.get_version() |
| 964 | return 'ccd_cr50' in servo and 'servo_micro' not in servo |
| 965 | |
| 966 | |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 967 | def _initialize_programmer(self, rw_only=False): |
| 968 | """Initialize the firmware programmer. |
| 969 | |
| 970 | @param rw_only: True to initialize a programmer which only |
| 971 | programs the RW portions. |
| 972 | """ |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 973 | if self._programmer: |
| 974 | return |
| 975 | # Initialize firmware programmer |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 976 | servo_version = self.get_servo_version() |
Dan Shi | 9cb0eec | 2014-06-03 09:04:50 -0700 | [diff] [blame] | 977 | if servo_version.startswith('servo_v2'): |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 978 | self._programmer = firmware_programmer.ProgrammerV2(self) |
Wai-Hong Tam | c36c4d2 | 2016-09-09 10:39:45 -0700 | [diff] [blame] | 979 | self._programmer_rw = firmware_programmer.ProgrammerV2RwOnly(self) |
Kevin Cheng | df2e29f | 2016-09-09 02:31:22 -0700 | [diff] [blame] | 980 | # Both servo v3 and v4 use the same programming methods so just leverage |
| 981 | # ProgrammerV3 for servo v4 as well. |
| 982 | elif (servo_version.startswith('servo_v3') or |
| 983 | servo_version.startswith('servo_v4')): |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 984 | self._programmer = firmware_programmer.ProgrammerV3(self) |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 985 | self._programmer_rw = firmware_programmer.ProgrammerV3RwOnly(self) |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 986 | else: |
| 987 | raise error.TestError( |
| 988 | 'No firmware programmer for servo version: %s' % |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 989 | servo_version) |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 990 | |
| 991 | |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 992 | def program_bios(self, image, rw_only=False): |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 993 | """Program bios on DUT with given image. |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 994 | |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 995 | @param image: a string, file name of the BIOS image to program |
| 996 | on the DUT. |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 997 | @param rw_only: True to only program the RW portion of BIOS. |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 998 | |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 999 | """ |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 1000 | self._initialize_programmer() |
Ricky Liang | c31aab3 | 2014-07-03 16:23:29 +0800 | [diff] [blame] | 1001 | if not self.is_localhost(): |
| 1002 | image = self._scp_image(image) |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 1003 | if rw_only: |
| 1004 | self._programmer_rw.program_bios(image) |
| 1005 | else: |
| 1006 | self._programmer.program_bios(image) |
Vadim Bendebury | b80ba59 | 2012-12-07 15:02:34 -0800 | [diff] [blame] | 1007 | |
| 1008 | |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 1009 | def program_ec(self, image, rw_only=False): |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 1010 | """Program ec on DUT with given image. |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 1011 | |
Yusuf Mohsinally | 6c078ae | 2013-11-21 11:06:42 -0800 | [diff] [blame] | 1012 | @param image: a string, file name of the EC image to program |
| 1013 | on the DUT. |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 1014 | @param rw_only: True to only program the RW portion of EC. |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 1015 | |
Vadim Bendebury | 1a7ec63 | 2013-02-17 16:22:09 -0800 | [diff] [blame] | 1016 | """ |
J. Richard Barnette | 8f19b39 | 2014-08-11 14:05:39 -0700 | [diff] [blame] | 1017 | self._initialize_programmer() |
Ricky Liang | c31aab3 | 2014-07-03 16:23:29 +0800 | [diff] [blame] | 1018 | if not self.is_localhost(): |
| 1019 | image = self._scp_image(image) |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 1020 | if rw_only: |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1021 | self._programmer_rw.program_ec(image) |
Tom Wai-Hong Tam | 4ac7898 | 2016-01-08 02:34:37 +0800 | [diff] [blame] | 1022 | else: |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1023 | self._programmer.program_ec(image) |
| 1024 | |
| 1025 | |
| 1026 | def _reprogram(self, tarball_path, firmware_name, image_candidates, |
| 1027 | rw_only): |
| 1028 | """Helper function to reprogram firmware for EC or BIOS. |
| 1029 | |
| 1030 | @param tarball_path: The path of the downloaded build tarball. |
| 1031 | @param: firmware_name: either 'EC' or 'BIOS'. |
| 1032 | @param image_candidates: A tuple of the paths of image candidates. |
| 1033 | @param rw_only: True to only install firmware to its RW portions. Keep |
| 1034 | the RO portions unchanged. |
| 1035 | |
| 1036 | @raise: TestError if cannot extract firmware from the tarball. |
| 1037 | """ |
Mary Ruthven | 771b201 | 2019-08-19 12:18:49 -0700 | [diff] [blame] | 1038 | dest_dir = os.path.join(os.path.dirname(tarball_path), firmware_name) |
| 1039 | # Create the firmware_name subdirectory if it doesn't exist. |
| 1040 | if not os.path.exists(dest_dir): |
| 1041 | os.mkdir(dest_dir) |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1042 | image = _extract_image_from_tarball(tarball_path, dest_dir, |
| 1043 | image_candidates) |
| 1044 | if not image: |
| 1045 | if firmware_name == 'EC': |
| 1046 | logging.info('Not a Chrome EC, ignore re-programming it') |
| 1047 | return |
| 1048 | else: |
| 1049 | raise error.TestError('Failed to extract the %s image from ' |
| 1050 | 'tarball' % firmware_name) |
| 1051 | |
| 1052 | logging.info('Will re-program %s %snow', firmware_name, |
| 1053 | 'RW ' if rw_only else '') |
| 1054 | |
| 1055 | if firmware_name == 'EC': |
| 1056 | self.program_ec(os.path.join(dest_dir, image), rw_only) |
| 1057 | else: |
| 1058 | self.program_bios(os.path.join(dest_dir, image), rw_only) |
| 1059 | |
| 1060 | |
Shelley Chen | ac61d5a | 2019-06-24 15:35:46 -0700 | [diff] [blame] | 1061 | def program_firmware(self, board, model, tarball_path, rw_only=False): |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1062 | """Program firmware (EC, if applied, and BIOS) of the DUT. |
| 1063 | |
Shelley Chen | ac61d5a | 2019-06-24 15:35:46 -0700 | [diff] [blame] | 1064 | @param board: The DUT board name. |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1065 | @param model: The DUT model name. |
| 1066 | @param tarball_path: The path of the downloaded build tarball. |
| 1067 | @param rw_only: True to only install firmware to its RW portions. Keep |
| 1068 | the RO portions unchanged. |
| 1069 | """ |
Shelley Chen | ac61d5a | 2019-06-24 15:35:46 -0700 | [diff] [blame] | 1070 | ap_image_candidates = ('image.bin', 'image-%s.bin' % model, |
| 1071 | 'image-%s.bin' % board) |
| 1072 | ec_image_candidates = ('ec.bin', '%s/ec.bin' % model, |
| 1073 | '%s/ec.bin' % board) |
Congbin Guo | 4242761 | 2019-02-12 10:22:06 -0800 | [diff] [blame] | 1074 | |
| 1075 | self._reprogram(tarball_path, 'EC', ec_image_candidates, rw_only) |
| 1076 | self._reprogram(tarball_path, 'BIOS', ap_image_candidates, rw_only) |
| 1077 | |
| 1078 | self.get_power_state_controller().reset() |
| 1079 | time.sleep(Servo.BOOT_DELAY) |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1080 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1081 | |
| 1082 | def _switch_usbkey_power(self, power_state, detection_delay=False): |
| 1083 | """Switch usbkey power. |
| 1084 | |
| 1085 | This function switches usbkey power by setting the value of |
| 1086 | 'prtctl4_pwren'. If the power is already in the |
| 1087 | requested state, this function simply returns. |
| 1088 | |
| 1089 | @param power_state: A string, 'on' or 'off'. |
| 1090 | @param detection_delay: A boolean value, if True, sleep |
| 1091 | for |USB_DETECTION_DELAY| after switching |
| 1092 | the power on. |
| 1093 | """ |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 1094 | # TODO(kevcheng): Forgive me for this terrible hack. This is just to |
| 1095 | # handle beaglebones that haven't yet updated and have the |
| 1096 | # safe_switch_usbkey_power RPC. I'll remove this once all beaglebones |
| 1097 | # have been updated and also think about a better way to handle |
| 1098 | # situations like this. |
| 1099 | try: |
| 1100 | self._server.safe_switch_usbkey_power(power_state) |
| 1101 | except Exception: |
| 1102 | self.set('prtctl4_pwren', power_state) |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1103 | if power_state == 'off': |
| 1104 | time.sleep(self.USB_POWEROFF_DELAY) |
| 1105 | elif detection_delay: |
| 1106 | time.sleep(self.USB_DETECTION_DELAY) |
| 1107 | |
| 1108 | |
| 1109 | def switch_usbkey(self, usb_state): |
| 1110 | """Connect USB flash stick to either host or DUT, or turn USB port off. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1111 | |
| 1112 | This function switches the servo multiplexer to provide electrical |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1113 | connection between the USB port J3 and either host or DUT side. It |
| 1114 | can also be used to turn the USB port off. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1115 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1116 | Switching to 'dut' or 'host' is accompanied by powercycling |
| 1117 | of the USB stick, because it sometimes gets wedged if the mux |
| 1118 | is switched while the stick power is on. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1119 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1120 | @param usb_state: A string, one of 'dut', 'host', or 'off'. |
| 1121 | 'dut' and 'host' indicate which side the |
| 1122 | USB flash device is required to be connected to. |
| 1123 | 'off' indicates turning the USB port off. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1124 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1125 | @raise: error.TestError in case the parameter is not 'dut' |
| 1126 | 'host', or 'off'. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1127 | """ |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1128 | if self.get_usbkey_direction() == usb_state: |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1129 | return |
| 1130 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1131 | if usb_state == 'off': |
Dan Shi | a5fef05 | 2015-05-18 23:28:47 -0700 | [diff] [blame] | 1132 | self._switch_usbkey_power('off') |
| 1133 | self._usb_state = usb_state |
| 1134 | return |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1135 | elif usb_state == 'host': |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1136 | mux_direction = 'servo_sees_usbkey' |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1137 | elif usb_state == 'dut': |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1138 | mux_direction = 'dut_sees_usbkey' |
| 1139 | else: |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1140 | raise error.TestError('Unknown USB state request: %s' % usb_state) |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1141 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1142 | self._switch_usbkey_power('off') |
Kevin Cheng | a22c4a8 | 2016-10-07 14:13:25 -0700 | [diff] [blame] | 1143 | # TODO(kevcheng): Forgive me for this terrible hack. This is just to |
| 1144 | # handle beaglebones that haven't yet updated and have the |
| 1145 | # safe_switch_usbkey RPC. I'll remove this once all beaglebones have |
| 1146 | # been updated and also think about a better way to handle situations |
| 1147 | # like this. |
| 1148 | try: |
| 1149 | self._server.safe_switch_usbkey(mux_direction) |
| 1150 | except Exception: |
| 1151 | self.set('usb_mux_sel1', mux_direction) |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1152 | time.sleep(self.USB_POWEROFF_DELAY) |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1153 | self._switch_usbkey_power('on', usb_state == 'host') |
| 1154 | self._usb_state = usb_state |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1155 | |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1156 | |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1157 | def get_usbkey_direction(self): |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1158 | """Get which side USB is connected to or 'off' if usb power is off. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1159 | |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1160 | @return: A string, one of 'dut', 'host', or 'off'. |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1161 | """ |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1162 | if not self._usb_state: |
| 1163 | if self.get('prtctl4_pwren') == 'off': |
| 1164 | self._usb_state = 'off' |
| 1165 | elif self.get('usb_mux_sel1').startswith('dut'): |
| 1166 | self._usb_state = 'dut' |
Vadim Bendebury | e7bd936 | 2012-12-19 14:35:20 -0800 | [diff] [blame] | 1167 | else: |
Fang Deng | afb8814 | 2013-05-30 17:44:31 -0700 | [diff] [blame] | 1168 | self._usb_state = 'host' |
| 1169 | return self._usb_state |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 1170 | |
| 1171 | |
Wai-Hong Tam | 6037726 | 2018-03-01 10:55:39 -0800 | [diff] [blame] | 1172 | def set_servo_v4_role(self, role): |
| 1173 | """Set the power role of servo v4, either 'src' or 'snk'. |
| 1174 | |
| 1175 | It does nothing if not a servo v4. |
| 1176 | |
| 1177 | @param role: Power role for DUT port on servo v4, either 'src' or 'snk'. |
| 1178 | """ |
| 1179 | servo_version = self.get_servo_version() |
| 1180 | if servo_version.startswith('servo_v4'): |
| 1181 | value = self.get('servo_v4_role') |
| 1182 | if value != role: |
| 1183 | self.set_nocheck('servo_v4_role', role) |
| 1184 | else: |
| 1185 | logging.debug('Already in the role: %s.', role) |
| 1186 | else: |
| 1187 | logging.debug('Not a servo v4, unable to set role to %s.', role) |
| 1188 | |
| 1189 | |
Mary Ruthven | 739b292 | 2019-08-22 11:16:06 -0700 | [diff] [blame] | 1190 | def set_servo_v4_dts_mode(self, state): |
| 1191 | """Set servo v4 dts mode to off or on. |
| 1192 | |
| 1193 | It does nothing if not a servo v4. Disable the ccd watchdog if we're |
| 1194 | disabling dts mode. CCD will disconnect. The watchdog only allows CCD |
| 1195 | to disconnect for 10 seconds until it kills servod. Disable the |
| 1196 | watchdog, so CCD can stay disconnected indefinitely. |
| 1197 | |
| 1198 | @param state: Set servo v4 dts mode 'off' or 'on'. |
| 1199 | """ |
| 1200 | servo_version = self.get_servo_version() |
| 1201 | if not servo_version.startswith('servo_v4'): |
| 1202 | logging.debug('Not a servo v4, unable to set dts mode %s.', state) |
| 1203 | return |
| 1204 | |
| 1205 | # TODO(mruthven): remove watchdog check once the labstation has been |
| 1206 | # updated to have support for modifying the watchdog. |
| 1207 | set_watchdog = self.has_control('watchdog') and 'ccd' in servo_version |
| 1208 | enable_watchdog = state == 'on' |
| 1209 | |
| 1210 | if set_watchdog and not enable_watchdog: |
| 1211 | self.set_nocheck('watchdog_remove', 'ccd') |
| 1212 | |
| 1213 | self.set_nocheck('servo_v4_dts_mode', state) |
| 1214 | |
| 1215 | if set_watchdog and enable_watchdog: |
| 1216 | self.set_nocheck('watchdog_add', 'ccd') |
| 1217 | |
| 1218 | |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 1219 | @property |
| 1220 | def uart_logs_dir(self): |
| 1221 | """Return the directory to save UART logs.""" |
| 1222 | return self._uart.logs_dir if self._uart else "" |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 1223 | |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 1224 | |
| 1225 | @uart_logs_dir.setter |
| 1226 | def uart_logs_dir(self, logs_dir): |
| 1227 | """Set directory to save UART logs. |
| 1228 | |
| 1229 | @param logs_dir String of directory name.""" |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 1230 | if self._uart: |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 1231 | self._uart.logs_dir = logs_dir |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 1232 | |
| 1233 | |
| 1234 | def close(self): |
| 1235 | """Close the servo object.""" |
| 1236 | if self._uart: |
| 1237 | self._uart.stop_capture() |
Congbin Guo | fc3b896 | 2019-03-22 17:38:46 -0700 | [diff] [blame] | 1238 | self._uart.dump() |
Congbin Guo | a1f9cba | 2018-07-03 11:36:59 -0700 | [diff] [blame] | 1239 | self._uart = None |