blob: 35fd059ae7dc69683f74b808e49184086bdff8d2 [file] [log] [blame]
Craig Harrison2b6c6fc2011-06-23 10:34:02 -07001# Copyright (c) 2011 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#
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
Jon Salzc88e5b62011-11-30 14:38:54 +08008import logging, os, subprocess, time, xmlrpclib
9from autotest_lib.client.bin import utils as client_utils
10from autotest_lib.server import utils
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070011
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070012class Servo:
13 """Manages control of a Servo board.
14
15 Servo is a board developed by hardware group to aide in the debug and
16 control of various partner devices. Servo's features include the simulation
17 of pressing the power button, closing the lid, and pressing Ctrl-d. This
18 class manages setting up and communicating with a servo demon (servod)
19 process. It provides both high-level functions for common servo tasks and
20 low-level functions for directly setting and reading gpios.
21 """
22
23 _server = None
24 _servod = None
25
Chrome Bot9a1137d2011-07-19 14:35:00 -070026 # Power button press delays in seconds.
27 LONG_DELAY = 8
28 SHORT_DELAY = 0.1
29 NORMAL_TRANSITION_DELAY = 1.2
Todd Broch31c82502011-08-29 08:14:39 -070030 # Maximum number of times to re-read power button on release.
31 RELEASE_RETRY_MAX = 5
Todd Brochcf7c6652012-02-24 13:03:59 -080032 GET_RETRY_MAX = 10
Chrome Bot9a1137d2011-07-19 14:35:00 -070033
34 # Delays to deal with computer transitions.
35 SLEEP_DELAY = 6
36 BOOT_DELAY = 10
Jon Salzc88e5b62011-11-30 14:38:54 +080037 RECOVERY_BOOT_DELAY = 30
38 RECOVERY_INSTALL_DELAY = 180
Chrome Bot9a1137d2011-07-19 14:35:00 -070039
40 # Servo-specific delays.
41 MAX_SERVO_STARTUP_DELAY = 10
42 SERVO_SEND_SIGNAL_DELAY = 0.5
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070043
Jon Salzc88e5b62011-11-30 14:38:54 +080044 # Time between an usb disk plugged-in and detected in the system.
45 USB_DETECTION_DELAY = 10
46
Tom Wai-Hong Tam5fc2c792011-11-03 13:05:39 +080047 def __init__(self, servo_host=None, servo_port=None,
48 xml_config=['servo.xml'], servo_vid=None, servo_pid=None,
49 servo_serial=None, cold_reset=False):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070050 """Sets up the servo communication infrastructure.
51
52 Args:
Todd Brochf24d2782011-08-19 10:55:41 -070053 servo_host: Host the servod process should listen on.
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070054 servo_port: Port the servod process should listen on.
Tom Wai-Hong Tam5fc2c792011-11-03 13:05:39 +080055 xml_config: A list of configuration XML files for servod.
Todd Broch5fd6bc02011-07-20 15:53:37 -070056 servo_vid: USB vendor id of servo.
57 servo_pid: USB product id of servo.
58 servo_serial: USB serial id in device descriptor to host to
59 distinguish and control multiple servos. Note servo's EEPROM must
60 be programmed to use this feature.
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070061 cold_reset: If True, cold reset device and boot during init,
62 otherwise perform init with device running.
63 """
64 # launch servod
Todd Brochf24d2782011-08-19 10:55:41 -070065 self._servod = None
Todd Broch5fd6bc02011-07-20 15:53:37 -070066
Todd Broch96d83aa2011-08-29 14:37:38 -070067 if not servo_port:
68 servo_port = 9999
69 # TODO(tbroch) In case where servo h/w is not connected to the host
70 # running the autotest server, servod will need to be launched by
71 # another means (udev likely). For now we can assume servo_host ==
72 # localhost as one hueristic way of determining this.
73 if not servo_host or servo_host == 'localhost':
74 servo_host = 'localhost'
75 self._launch_servod(servo_host, servo_port, xml_config, servo_vid,
76 servo_pid, servo_serial)
77 else:
78 logging.info('servod should already be running on host = %s',
79 servo_host)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070080
Chrome Bot9a1137d2011-07-19 14:35:00 -070081 self._do_cold_reset = cold_reset
Todd Brochf24d2782011-08-19 10:55:41 -070082 self._connect_servod(servo_host, servo_port)
Chrome Bot9a1137d2011-07-19 14:35:00 -070083
84
85 def initialize_dut(self):
86 """Initializes a dut for testing purposes."""
87 if self._do_cold_reset:
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070088 self._init_seq_cold_reset_devmode()
89 else:
90 self._init_seq()
91
92
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070093 def power_long_press(self):
Chrome Bot9a1137d2011-07-19 14:35:00 -070094 """Simulate a long power button press."""
95 self.power_key(Servo.LONG_DELAY)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -070096
97
98 def power_normal_press(self):
Chrome Bot9a1137d2011-07-19 14:35:00 -070099 """Simulate a normal power button press."""
100 self.power_key()
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700101
102
103 def power_short_press(self):
Chrome Bot9a1137d2011-07-19 14:35:00 -0700104 """Simulate a short power button press."""
105 self.power_key(Servo.SHORT_DELAY)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700106
107
Chrome Bot9a1137d2011-07-19 14:35:00 -0700108 def power_key(self, secs=NORMAL_TRANSITION_DELAY):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700109 """Simulate a power button press.
110
111 Args:
112 secs: Time in seconds to simulate the keypress.
113 """
Craig Harrison6b36b122011-06-28 17:58:43 -0700114 self.set_nocheck('pwr_button', 'press')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700115 time.sleep(secs)
Todd Broch31c82502011-08-29 08:14:39 -0700116 self.set_nocheck('pwr_button', 'release')
117 # TODO(tbroch) Different systems have different release times on the
118 # power button that this loop addresses. Longer term we may want to
119 # make this delay platform specific.
120 retry = 1
121 while True:
122 value = self.get('pwr_button')
123 if value == 'release' or retry > Servo.RELEASE_RETRY_MAX:
124 break
125 logging.info('Waiting for pwr_button to release, retry %d.' % retry)
126 retry += 1
127 time.sleep(Servo.SHORT_DELAY)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700128
129
130 def lid_open(self):
131 """Simulate opening the lid."""
Craig Harrison48997262011-06-27 14:31:10 -0700132 self.set_nocheck('lid_open', 'yes')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700133
134
135 def lid_close(self):
Craig Harrison48997262011-06-27 14:31:10 -0700136 """Simulate closing the lid.
137
138 Waits 6 seconds to ensure the device is fully asleep before returning.
139 """
140 self.set_nocheck('lid_open', 'no')
Chrome Bot9a1137d2011-07-19 14:35:00 -0700141 time.sleep(Servo.SLEEP_DELAY)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700142
143
Todd Broch9dfc3a82011-11-01 08:09:28 -0700144 def _press_and_release_keys(self, m1, m2, press_secs=None):
145 """Simulate button presses."""
146 if press_secs is None:
147 press_secs = Servo.SERVO_SEND_SIGNAL_DELAY
148
149 self.set_nocheck('kbd_en', 'on')
150 self.set_nocheck('kbd_m1', m1)
151 self.set_nocheck('kbd_m2', m2)
152 time.sleep(press_secs)
153 self.set_nocheck('kbd_en', 'off')
154
155
Chrome Bot9a1137d2011-07-19 14:35:00 -0700156 def ctrl_d(self):
157 """Simulate Ctrl-d simultaneous button presses."""
Todd Broch9dfc3a82011-11-01 08:09:28 -0700158 self._press_and_release_keys('d', 'ctrl')
159
160
161 def d_key(self):
162 """Simulate Enter key button press."""
163 self._press_and_release_keys('d', 'none')
164
165
166 def ctrl_key(self):
167 """Simulate Enter key button press."""
168 self._press_and_release_keys('none', 'ctrl')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700169
170
Chrome Bot9a1137d2011-07-19 14:35:00 -0700171 def enter_key(self):
172 """Simulate Enter key button press."""
Todd Broch9dfc3a82011-11-01 08:09:28 -0700173 self._press_and_release_keys('enter', 'none')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700174
175
Chrome Bot9a1137d2011-07-19 14:35:00 -0700176 def refresh_key(self):
177 """Simulate Refresh key (F3) button press."""
Todd Broch9dfc3a82011-11-01 08:09:28 -0700178 self._press_and_release_keys('none', 'refresh')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700179
180
Chrome Bot9a1137d2011-07-19 14:35:00 -0700181 def imaginary_key(self):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700182 """Simulate imaginary key button press.
183
184 Maps to a key that doesn't physically exist.
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700185 """
Todd Broch9dfc3a82011-11-01 08:09:28 -0700186 self._press_and_release_keys('none', 'unused')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700187
188
Craig Harrison6b36b122011-06-28 17:58:43 -0700189 def enable_recovery_mode(self):
190 """Enable recovery mode on device."""
191 self.set('rec_mode', 'on')
192
193
194 def disable_recovery_mode(self):
195 """Disable recovery mode on device."""
196 self.set('rec_mode', 'off')
197
198
199 def enable_development_mode(self):
200 """Enable development mode on device."""
201 self.set('dev_mode', 'on')
202
203
204 def disable_development_mode(self):
205 """Disable development mode on device."""
206 self.set('dev_mode', 'off')
207
Chris Sosa8ee1d592011-08-14 16:50:31 -0700208 def enable_usb_hub(self, host=False):
Craig Harrison86b1a572011-08-12 11:26:52 -0700209 """Enable Servo's USB/ethernet hub.
210
Chris Sosa8ee1d592011-08-14 16:50:31 -0700211 This is equivalent to plugging in the USB devices attached to Servo to
212 the host (if |host| is True) or dut (if |host| is False).
213 For host=False, requires that the USB out on the servo board is
214 connected to a USB in port on the target device. Servo's USB ports are
215 labeled DUT_HUB_USB1 and DUT_HUB_USB2. Servo's ethernet port is also
216 connected to this hub. Servo's USB port DUT_HUB_IN is the output of the
217 hub.
Craig Harrison86b1a572011-08-12 11:26:52 -0700218 """
219 self.set('dut_hub_pwren', 'on')
Chris Sosa8ee1d592011-08-14 16:50:31 -0700220 if host:
221 self.set('usb_mux_oe1', 'on')
222 self.set('usb_mux_sel1', 'servo_sees_usbkey')
223 else:
224 self.set('dut_hub_sel', 'dut_sees_hub')
225
Craig Harrison86b1a572011-08-12 11:26:52 -0700226 self.set('dut_hub_on', 'yes')
227
228
229 def disable_usb_hub(self):
230 """Disable Servo's USB/ethernet hub.
231
232 This is equivalent to unplugging the USB devices attached to Servo.
233 """
234 self.set('dut_hub_on', 'no')
235
236
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700237 def boot_devmode(self):
238 """Boot a dev-mode device that is powered off."""
Tom Wai-Hong Tam23869102012-01-17 15:41:30 +0800239 self.power_short_press()
Craig Harrison48997262011-06-27 14:31:10 -0700240 self.pass_devmode()
241
242
243 def pass_devmode(self):
244 """Pass through boot screens in dev-mode."""
Chrome Bot9a1137d2011-07-19 14:35:00 -0700245 time.sleep(Servo.BOOT_DELAY)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700246 self.ctrl_d()
Chrome Bot9a1137d2011-07-19 14:35:00 -0700247 time.sleep(Servo.BOOT_DELAY)
Craig Harrison48997262011-06-27 14:31:10 -0700248
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700249
Craig Harrison6b36b122011-06-28 17:58:43 -0700250 def cold_reset(self):
251 """Perform a cold reset of the EC.
252
Chris Sosa8ee1d592011-08-14 16:50:31 -0700253 Has the side effect of shutting off the device. Device is guaranteed
254 to be off at the end of this call.
Craig Harrison6b36b122011-06-28 17:58:43 -0700255 """
256 self.set('cold_reset', 'on')
Chrome Bot9a1137d2011-07-19 14:35:00 -0700257 time.sleep(Servo.SERVO_SEND_SIGNAL_DELAY)
Craig Harrison6b36b122011-06-28 17:58:43 -0700258
259
260 def warm_reset(self):
261 """Perform a warm reset of the device.
262
263 Has the side effect of restarting the device.
264 """
265 self.set('warm_reset', 'on')
Chrome Bot9a1137d2011-07-19 14:35:00 -0700266 time.sleep(Servo.SERVO_SEND_SIGNAL_DELAY)
Craig Harrison6b36b122011-06-28 17:58:43 -0700267 self.set('warm_reset', 'off')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700268
269
270 def get(self, gpio_name):
271 """Get the value of a gpio from Servod."""
272 assert gpio_name
273 return self._server.get(gpio_name)
274
275
276 def set(self, gpio_name, gpio_value):
277 """Set and check the value of a gpio using Servod."""
Chrome Bot9a1137d2011-07-19 14:35:00 -0700278 self.set_nocheck(gpio_name, gpio_value)
Todd Brochcf7c6652012-02-24 13:03:59 -0800279 retry_count = Servo.GET_RETRY_MAX
280 while gpio_value != self.get(gpio_name) and retry_count:
281 logging.warn("%s != %s, retry %d", gpio_name, gpio_value,
282 retry_count)
283 retry_count -= 1
284 time.sleep(Servo.SHORT_DELAY)
285 if not retry_count:
286 assert gpio_value == self.get(gpio_name), \
287 'Servo failed to set %s to %s' % (gpio_name, gpio_value)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700288
289
290 def set_nocheck(self, gpio_name, gpio_value):
291 """Set the value of a gpio using Servod."""
292 assert gpio_name and gpio_value
Chrome Bot9a1137d2011-07-19 14:35:00 -0700293 logging.info('Setting %s to %s' % (gpio_name, gpio_value))
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700294 self._server.set(gpio_name, gpio_value)
295
296
Jon Salzc88e5b62011-11-30 14:38:54 +0800297 # TODO(waihong) It may fail if multiple servo's are connected to the same
298 # host. Should look for a better way, like the USB serial name, to identify
299 # the USB device.
300 def probe_host_usb_dev(self):
301 """Probe the USB disk device plugged-in the servo from the host side.
302
303 It tries to switch the USB mux to make the host unable to see the
304 USB disk and compares the result difference.
305
306 This only works if the servo is attached to the local host.
307
308 Returns:
309 A string of USB disk path, like '/dev/sdb', or None if not existed.
310 """
311 cmd = 'ls /dev/sd[a-z]'
312 original_value = self.get('usb_mux_sel1')
313
314 # Make the host unable to see the USB disk.
315 if original_value != 'dut_sees_usbkey':
316 self.set('usb_mux_sel1', 'dut_sees_usbkey')
317 time.sleep(self.USB_DETECTION_DELAY)
318 no_usb_set = set(utils.system_output(cmd, ignore_status=True).split())
319
320 # Make the host able to see the USB disk.
321 self.set('usb_mux_sel1', 'servo_sees_usbkey')
322 time.sleep(self.USB_DETECTION_DELAY)
323 has_usb_set = set(utils.system_output(cmd, ignore_status=True).split())
324
325 # Back to its original value.
326 if original_value != 'servo_sees_usbkey':
327 self.set('usb_mux_sel1', original_value)
328 time.sleep(self.USB_DETECTION_DELAY)
329
330 diff_set = has_usb_set - no_usb_set
331 if len(diff_set) == 1:
332 return diff_set.pop()
333 else:
334 return None
335
336
Tom Wai-Hong Tama07115e2012-01-09 12:27:01 +0800337 def install_recovery_image(self, image_path=None, usb_dev=None,
Jon Salzc88e5b62011-11-30 14:38:54 +0800338 wait_for_completion=True):
339 """Install the recovery image specied by the path onto the DUT.
340
341 This method uses google recovery mode to install a recovery image
342 onto a DUT through the use of a USB stick that is mounted on a servo
Tom Wai-Hong Tama07115e2012-01-09 12:27:01 +0800343 board specified by the usb_dev. If no image path is specified
Jon Salzc88e5b62011-11-30 14:38:54 +0800344 we use the recovery image already on the usb image.
345
346 Args:
347 image_path: Path on the host to the recovery image.
Tom Wai-Hong Tama07115e2012-01-09 12:27:01 +0800348 usb_dev: When servo_sees_usbkey is enabled, which dev
349 e.g. /dev/sdb will the usb key show up as.
350 If None, detects it automatically.
Jon Salzc88e5b62011-11-30 14:38:54 +0800351 wait_for_completion: Whether to wait for completion of the
352 factory install and disable the USB hub
353 before returning. Currently this is just
354 a hardcoded wait of RECOVERY_INSTALL_DELAY
355 (for the recovery process to complete).
356 """
357 # Set up Servo's usb mux.
358 self.set('prtctl4_pwren', 'on')
359 self.enable_usb_hub(host=True)
Tom Wai-Hong Tama07115e2012-01-09 12:27:01 +0800360 if image_path:
361 if not usb_dev:
362 usb_dev = self.probe_host_usb_dev()
363 logging.info('Installing image onto usb stick. '
364 'This takes a while...')
365 client_utils.poll_for_condition(
366 lambda: os.path.exists(usb_dev),
367 timeout=Servo.USB_DETECTION_DELAY,
368 desc="%s exists" % usb_dev)
369 utils.system(' '.join(
370 ['sudo', 'dd', 'if=%s' % image_path,
371 'of=%s' % usb_dev, 'bs=4M']))
Jon Salzc88e5b62011-11-30 14:38:54 +0800372
373 # Turn the device off.
374 self.power_normal_press()
375 time.sleep(Servo.SLEEP_DELAY)
376
377 # Boot in recovery mode.
378 try:
Jon Salzc88e5b62011-11-30 14:38:54 +0800379 self.enable_recovery_mode()
Tom Wai-Hong Tam23869102012-01-17 15:41:30 +0800380 self.power_short_press()
Jon Salzc88e5b62011-11-30 14:38:54 +0800381 time.sleep(Servo.RECOVERY_BOOT_DELAY)
Tom Wai-Hong Tam922ed052012-01-09 12:27:52 +0800382 self.set('usb_mux_sel1', 'dut_sees_usbkey')
Jon Salzc88e5b62011-11-30 14:38:54 +0800383 self.disable_recovery_mode()
384
385 if wait_for_completion:
386 # Enable recovery installation.
387 logging.info('Running the recovery process on the DUT. '
388 'Waiting %d seconds for recovery to complete ...',
389 Servo.RECOVERY_INSTALL_DELAY)
390 time.sleep(Servo.RECOVERY_INSTALL_DELAY)
391
392 # Go back into normal mode and reboot.
393 # Machine automatically reboots after the usb key is removed.
394 logging.info('Removing the usb key from the DUT.')
395 self.disable_usb_hub()
396 time.sleep(Servo.BOOT_DELAY)
397 except:
398 # In case anything went wrong we want to make sure to do a clean
399 # reset.
400 self.disable_recovery_mode()
401 self.warm_reset()
402 raise
403
404
Craig Harrison6b36b122011-06-28 17:58:43 -0700405 def _init_seq_cold_reset_devmode(self):
406 """Cold reset, init device, and boot in dev-mode."""
407 self.cold_reset()
408 self._init_seq()
409 self.set('dev_mode', 'on')
410 self.boot_devmode()
411
412
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700413 def __del__(self):
414 """Kill the Servod process."""
Todd Brochf24d2782011-08-19 10:55:41 -0700415 if not self._servod:
416 return
417
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700418 # kill servod one way or another
419 try:
420 # won't work without superuser privileges
421 self._servod.terminate()
422 except:
423 # should work without superuser privileges
424 assert subprocess.call(['sudo', 'kill', str(self._servod.pid)])
425
426
Todd Brochf24d2782011-08-19 10:55:41 -0700427 def _launch_servod(self, servo_host, servo_port, xml_config, servo_vid,
428 servo_pid, servo_serial):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700429 """Launch the servod process.
430
431 Args:
Todd Brochf24d2782011-08-19 10:55:41 -0700432 servo_host: Host to start servod listening on.
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700433 servo_port: Port to start servod listening on.
Tom Wai-Hong Tam5fc2c792011-11-03 13:05:39 +0800434 xml_config: A list of XML configuration files for servod.
Todd Broch5fd6bc02011-07-20 15:53:37 -0700435 servo_vid: USB vendor id of servo.
436 servo_pid: USB product id of servo.
437 servo_serial: USB serial id in device descriptor to host to
438 distinguish and control multiple servos. Note servo's EEPROM must
439 be programmed to use this feature.
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700440 """
Tom Wai-Hong Tam5fc2c792011-11-03 13:05:39 +0800441 cmdlist = ['sudo', 'servod']
442 for config in xml_config:
443 cmdlist += ['-c', str(config)]
Todd Broch96d83aa2011-08-29 14:37:38 -0700444 if servo_host is not None:
445 cmdlist.append('--host=%s' % str(servo_host))
446 if servo_port is not None:
447 cmdlist.append('--port=%s' % str(servo_port))
Todd Broch5fd6bc02011-07-20 15:53:37 -0700448 if servo_vid is not None:
Todd Brochf24d2782011-08-19 10:55:41 -0700449 cmdlist.append('--vendor=%s' % str(servo_vid))
Todd Broch5fd6bc02011-07-20 15:53:37 -0700450 if servo_pid is not None:
Todd Brochf24d2782011-08-19 10:55:41 -0700451 cmdlist.append('--product=%s' % str(servo_pid))
Todd Broch5fd6bc02011-07-20 15:53:37 -0700452 if servo_serial is not None:
Todd Brochf24d2782011-08-19 10:55:41 -0700453 cmdlist.append('--serialname=%s' % str(servo_serial))
Todd Broch5fd6bc02011-07-20 15:53:37 -0700454 logging.info('starting servod w/ cmd :: %s' % ' '.join(cmdlist))
455 self._servod = subprocess.Popen(cmdlist, 0, None, None, None,
456 subprocess.PIPE)
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700457 # wait for servod to initialize
Chrome Bot9a1137d2011-07-19 14:35:00 -0700458 timeout = Servo.MAX_SERVO_STARTUP_DELAY
459 while ('Listening' not in self._servod.stderr.readline() and
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700460 self._servod.returncode is None and timeout > 0):
461 time.sleep(1)
462 timeout -= 1
463 assert self._servod.returncode is None and timeout
464
465
466 def _init_seq(self):
467 """Initiate starting state for servo."""
468 self.set('tx_dir', 'input')
Todd Broch6ec29432011-12-19 14:32:02 -0800469 # TODO(tbroch) Investigate method to determine DUT's type so we can
470 # conditionally set lid if applicable
471 self.set_nocheck('lid_open', 'yes')
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700472 self.set('rec_mode', 'off')
473
474
Todd Brochf24d2782011-08-19 10:55:41 -0700475 def _connect_servod(self, servo_host, servo_port):
Craig Harrison2b6c6fc2011-06-23 10:34:02 -0700476 """Connect to the Servod process with XMLRPC.
477
478 Args:
479 servo_port: Port the Servod process is listening on.
480 """
Todd Brochf24d2782011-08-19 10:55:41 -0700481 remote = 'http://%s:%s' % (servo_host, servo_port)
Todd Broch96d83aa2011-08-29 14:37:38 -0700482 self._server = xmlrpclib.ServerProxy(remote)
Todd Brochf24d2782011-08-19 10:55:41 -0700483 try:
484 self._server.echo("ping-test")
Todd Broch96d83aa2011-08-29 14:37:38 -0700485 except:
486 logging.error('Connection to servod failed')
Todd Brochf24d2782011-08-19 10:55:41 -0700487 raise