def initialize(self, host, cfm_test): """ Initializes the test. @param host The host the test is run against @param cfm_test CfmTest instance to execute. """ (super(ConfigurableCfmTest, self) .initialize(host, cfm_test.configuration.run_test_only, cfm_test.configuration.skip_enrollment)) self.cfm_test = cfm_test device_collector = usb_device_collector.UsbDeviceCollector(host) port_manager = usb_port_manager.UsbPortManager(host) crash_file_detector = crash_detector.CrashDetector(host) # Call get_new_crash_files() once. This records the current crash # files so that subsequent calls only check the delta, i.e. # new crash files from here on. crash_file_detector.get_new_crash_files() # self.cfm_facade is inherited from CfmBaseTest. context = action_context.ActionContext( cfm_facade=self.cfm_facade, file_contents_collector=HostFileContentsCollector(host), host=host, usb_device_collector=device_collector, usb_port_manager=port_manager, crash_detector=crash_file_detector) self.test_runner = TestRunner(context)
def power_cycle_usb_vidpid(dut, board, vid, pid, pause=1): """ Power cycle a usb port on DUT via peripharel's VID and PID. When only the VID and PID of the peripharel is known, a search is needed to decide which port it connects to by its VID and PID and look up the gpio index according to the board and port number in the dictionary. Then the USB port is power cycled using the gpio number. @param dut: The handle of the device under test. @param board: Board name ('guado', etc.) @param vid: Vendor ID of the peripharel device. @param pid: Product ID of the peripharel device. @param pause: Time interval between power off and power on, unit is second. @raise KeyError if the target device wasn't found by given VID and PID. """ bus_idx, port_idx = get_port_number_from_vidpid(dut, vid, pid) if port_idx is None: raise KeyError('Couldn\'t find target device, {}:{}.'.format(vid, pid)) logging.info('found device bus {} port {}'.format(bus_idx, port_idx)) usb_manager = usb_port_manager.UsbPortManager(dut) port_id = [usb_port_manager.PortId(bus=bus_idx, port_number=port_idx)] usb_manager.set_port_power(port_id, 0) time.sleep(pause) usb_manager.set_port_power(port_id, 1)
def test_power_on_gpio_fizz(self): host = mock.Mock() host.get_board = mock.Mock(return_value='board: fizz') host.run = mock.Mock() port_manager = usb_port_manager.UsbPortManager(host) port_manager.set_port_power([(1, 2)], True) expected_runs = [ mock.call('ectool gpioset USB%s_ENABLE 1' % FIZZ_GPIO) ] host.run.assert_has_calls(expected_runs)
def test_power_on_gpio_exported_guado(self): host = mock.Mock() host.get_board = mock.Mock(return_value='board: guado') host.run = mock.Mock() host.path_exists = mock.Mock(return_value=True) port_manager = usb_port_manager.UsbPortManager(host) port_manager.set_port_power([(1, 2)], True) expected_runs = [ mock.call('echo out > %s/direction' % GUADO_GPIO_PATH), mock.call('echo 1 > %s/value' % GUADO_GPIO_PATH), ] host.run.assert_has_calls(expected_runs)
def test_power_off_gpio_unexported(self): host = mock.Mock() host.get_board = mock.Mock(return_value='board: guado') host.run = mock.Mock() host.path_exists = mock.Mock(return_value=False) port_manager = usb_port_manager.UsbPortManager(host) port_manager.set_port_power([(1, 2)], False) expected_runs = [ mock.call('echo %s > /sys/class/gpio/export' % GPIO), mock.call('echo out > %s/direction' % GPIO_PATH), mock.call('echo 0 > %s/value' % GPIO_PATH), mock.call('echo %s > /sys/class/gpio/unexport' % GPIO), ] host.run.assert_has_calls(expected_runs)