blob: 604746a907217b8b4433ba130e95333105a6c184 [file] [log] [blame]
# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# WARNING( This test is currently broken because the ability
# to run client tests in the background from a server-side test has been
# deleted.
import logging, time
from autotest_lib.server import autotest, test
from autotest_lib.client.common_lib import error
class power_USBHotplugInSuspend(test.test):
version = 1
def _switch_usbkey_power(self, on):
Turn on/off the power to the USB key.
@param on True to turn on, false otherwise.
if on:
self._host.servo.set('prtctl4_pwren', 'on')
self._host.servo.set('prtctl4_pwren', 'off')
def _get_usb_devices(self):
Get the USB device attached to the client.
Parses output from lsusb and returns the set of device IDs.
lines ='lsusb').stdout.strip().split('\n')
raise error.TestError('Failed to get list of USB devices.')
devices = set(line.split()[5] for line in lines)'USB Devices: %s' % (",".join(devices)))
return devices
def _suspend_client(self):
Start the client test power_KernelSuspend to suspend the client and
do not wait for it to finish.
client_at = autotest.Autotest(self._host)
# TODO(scottz): Add server side support to sys_power:
client_at.run_test('power_KernelSuspend', background=True,
def _suspend_and_hotplug(self, insert):
Suspend the client and add/remove the USB key. This assumes that a
USB key is plugged into the servo and is facing the DUT.
@param insert True to test insertion during suspend, False to test
# Initialize the USB key and get the set of USB devices before
# suspending.
self._switch_usbkey_power(not insert)
before_suspend = self._get_usb_devices()
# Suspend the client and wait for it to go down before powering on/off
# the usb key.
if not self._host.ping_wait_down(_SUSPEND_TIMEOUT):
raise error.TestError('Client failed to suspend.')
# Wait for the client to come back up (suspend time + some slack time).
# TODO(beeps): Combine the two timeouts in wait_up after
# is resolved.
if not self._host.wait_up(self._host.RESUME_TIMEOUT):
raise error.TestError('Client failed to resume.')
# Get the set of devices plugged in and make sure the change was
# detected.
after_suspend = self._get_usb_devices()
diff = after_suspend ^ before_suspend
if not diff:
raise error.TestFail('No USB changes detected after resuming.')
# Finally, make sure hotplug still works after resuming by switching
# the USB key's power once more.
self._switch_usbkey_power(not insert)
after_hotplug = self._get_usb_devices()
diff = after_hotplug ^ after_suspend
if not diff:
raise error.TestFail('No USB changes detected after hotplugging.')
def cleanup(self):
Reset the USB key to its initial state.
self._switch_usbkey_power(self._init_usbkey_power == 'on')
super(power_USBHotplugInSuspend, self).cleanup()
def run_once(self, host):
Tests adding and removing a USB device while the client is suspended.
self._host = host
self._init_usbkey_power = self._host.servo.get('prtctl4_pwren')
self._init_usbkey_direction = self._host.servo.get_usbkey_direction()
# Make sure the USB key is facing the DUT and is actually present.
before_insert = self._get_usb_devices()
after_insert = self._get_usb_devices()
diff = after_insert - before_insert'Inserted USB device(s): %s' % (",".join(diff)))
if not diff:
raise error.TestError('No new USB devices detected. Is a USB key '
'plugged into the servo?')'Testing insertion during suspend.')
self._suspend_and_hotplug(True)'Testing removal during suspend.')