Beispiel #1
0
 def setUp(self):
     self._usb_device = usb_device.UsbDevice(
         vid='vid',
         pid='pid',
         product='product',
         interfaces=['a', 'b'],
         bus=1,
         level=1,
         port=2)
 def test_assert_usb_device_collector_matching_predicate(self):
     spec = usb_device_spec.UsbDeviceSpec('vid', 'pid', 'product',
                                          ['iface'])
     device = usb_device.UsbDevice('v', 'p', 'prod', ['if'], 1, 2, 1)
     self.usb_device_collector_mock.get_devices_by_spec = mock.Mock(
         return_value=[device])
     action = actions.AssertUsbDevices([spec],
                                       lambda x: x[0].product_id == 'p')
     action.execute(self.context_with_mocks)
 def test_power_cycle_usb_port(self):
     device = usb_device.UsbDevice('v', 'p', 'prod', ['if'], 1, 2, 1)
     self.usb_device_collector_mock.get_devices_by_spec = mock.Mock(
         side_effect=[[device, device], [device], [device, device]])
     action = actions.PowerCycleUsbPort([USB_DEVICE_SPEC], 0,
                                        lambda x: [x[0]])
     action.execute(self.context_with_mocks)
     self.usb_port_manager_mock.set_port_power.assert_has_calls(
         [mock.call([(1, 2)], False),
          mock.call([(1, 2)], True)])
Beispiel #4
0
 def test_get_parent(self):
     child = usb_device.UsbDevice(
         vid='vid1',
         pid='pid1',
         product='product',
         interfaces=['a', 'b'],
         bus=1,
         level=2,
         port=2,
         parent=self._usb_device)
     self.assertEquals(child.get_parent(1).vid_pid, 'vid:pid')
 def _create_usb_device(self, usbdata):
     return usb_device.UsbDevice(
         vid=usbdata['Vendor'],
         pid=usbdata['ProdID'],
         product=usbdata.get('Product', 'Not available'),
         interfaces=usbdata['intdriver'],
         bus=int(usbdata['Bus']),
         level=int(usbdata['Lev']),
         # We increment here by 1 because usb-devices reports 0-indexed port
         # numbers where as lsusb reports 1-indexed. We opted to follow the
         # the lsusb standard.
         port=int(usbdata['Port']) + 1)
import mock
import unittest

from autotest_lib.client.common_lib.cros.cfm.usb import usb_device
from autotest_lib.client.common_lib.cros.cfm.usb import usb_device_spec
from autotest_lib.server.cros.cfm.configurable_test import actions
from autotest_lib.server.cros.cfm.configurable_test import action_context
from autotest_lib.server.cros.cfm.configurable_test import scenario

# Constants to use in case the actual values are irrelevant.
USB_DEVICE_SPEC = usb_device_spec.UsbDeviceSpec('vid', 'pid', 'product',
                                                ['iface'])

USB_DEVICE = usb_device.UsbDevice('v', 'p', 'prod', ['if'], 1, 2, 1)


# Test, disable missing-docstring
# pylint: disable=missing-docstring
class TestActions(unittest.TestCase):
    """
    Tests for the available actions for configurable CFM tests to run.
    """
    def setUp(self):
        self.host_mock = mock.MagicMock()
        self.cfm_facade_mock = mock.MagicMock()
        self.usb_device_collector_mock = mock.MagicMock()
        self.usb_port_manager_mock = mock.MagicMock()
        self.crash_detector_mock = mock.MagicMock()
        self.metrics_collector_mock = mock.MagicMock()
        self.context_with_mocks = action_context.ActionContext(
            host=self.host_mock,