def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile=None): """ Test VirtualBoxs USB stack in a VM. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams( self.sHostname, sSpeed) oUsbGadget = usbgadget.UsbGadget() reporter.log('Connecting to UTS: ' + sGadgetHost) fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort=uGadgetPort) if fRc is True: reporter.log('Connect succeeded') self.oVBox.host.addUSBDeviceSource( 'USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []) fSuperSpeed = False if sSpeed == 'Super': fSuperSpeed = True # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed) if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId() fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile) if fRc is True: tupCmdLine = ('UsbTest', ) # Exclude a few tests which hang and cause a timeout, need investigation. lstTestsExclude = self.kdUsbTestsDisabled.get(sSpeed) for iTestExclude in lstTestsExclude: tupCmdLine = tupCmdLine + ('--exclude', str(iTestExclude)) fRc = self.txsRunTest(oTxsSession, 'UsbTest', 3600 * 1000, \ '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', tupCmdLine) if not fRc: reporter.testFailure('Running USB test utility failed') else: reporter.testFailure('Failed to attach USB device to VM') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to impersonate test device') self.oVBox.host.removeUSBDeviceSource(sGadgetHost) else: reporter.testFailure('Failed to connect to USB gadget') _ = sUsbCtrl return fRc
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed): # pylint: disable=W0613 """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams( self.sHostname, sSpeed) oUsbGadget = usbgadget.UsbGadget() reporter.log('Connecting to UTS: ' + sGadgetHost) fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort=uGadgetPort) if fRc is True: self.oVBox.host.addUSBDeviceSource( 'USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []) fSuperSpeed = False if sSpeed == 'Super': fSuperSpeed = True # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed) if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId() fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ sPort = str(iBusId)) if fRc is True: # Wait a moment to let the USB device appear self.sleep(3) # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange(0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb() fRc = fRc and oUsbGadget.connectUsb() if not fRc: reporter.testFailure( 'Reattach cycle %s failed on the gadget device' % (iCycle)) break self.sleep(1) else: reporter.testFailure('Failed to impersonate test device') oUsbGadget.disconnectFrom() else: reporter.testFailure('Failed to connect to USB gadget') else: reporter.testFailure('Failed to create USB device filter') return fRc
def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile = None): # pylint: disable=unused-argument """ Tests that rapid connect/disconnect cycles work. """ # Get configured USB test devices from hostname we are running on sGadgetHost, uGadgetPort = self.getGadgetParams(self.sHostname, sSpeed); oUsbGadget = usbgadget.UsbGadget(); reporter.log('Connecting to UTS: ' + sGadgetHost); fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort = uGadgetPort, fTryConnect = True); if fRc is True: self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost + (':%s' % oUsbGadget.getUsbIpPort()), [], []); fSuperSpeed = False; if sSpeed == 'Super': fSuperSpeed = True; # Create test device gadget and a filter to attach the device automatically. fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, fSuperSpeed); if fRc is True: iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile); if fRc is True: # Wait a moment to let the USB device appear self.sleep(3); # Do a rapid disconnect reconnect cycle. Wait a second before disconnecting # again or it will happen so fast that the VM can't attach the new device. # @todo: Get rid of the constant wait and use an event to get notified when # the device was attached. for iCycle in xrange (0, self.cUsbReattachCycles): fRc = oUsbGadget.disconnectUsb(); fRc = fRc and oUsbGadget.connectUsb(); if not fRc: reporter.testFailure('Reattach cycle %s failed on the gadget device' % (iCycle)); break; self.sleep(1); else: reporter.testFailure('Failed to create USB device filter'); oUsbGadget.disconnectFrom(); else: reporter.testFailure('Failed to impersonate test device'); else: reporter.log('warning: Failed to connect to USB gadget'); fRc = None return fRc;
def main(asArgs): # pylint: disable=C0111,R0914,R0915 cMsTimeout = long(30 * 1000) sAddress = 'localhost' uPort = None fStdTests = True i = 1 while i < len(asArgs): if asArgs[i] == '--hostname': sAddress = asArgs[i + 1] i = i + 2 elif asArgs[i] == '--port': uPort = int(asArgs[i + 1]) i = i + 2 elif asArgs[i] == '--timeout': cMsTimeout = long(asArgs[i + 1]) i = i + 2 elif asArgs[i] == '--help': print( 'tst-utsgadget.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>]' ) return 0 else: print('Unknown argument: %s' % (asArgs[i], )) return 2 oGadget = usbgadget.UsbGadget() if uPort is None: rc = oGadget.connectTo(cMsTimeout, sAddress) else: rc = oGadget.connectTo(cMsTimeout, sAddress, uPort=uPort) if rc is False: print('connectTo failed') return 1 if fStdTests: rc = oGadget.getUsbIpPort() is not None print('%s: getUsbIpPort() -> %s' % ( boolRes(rc), oGadget.getUsbIpPort(), )) rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest) print('%s: impersonate()' % (boolRes(rc), )) rc = oGadget.disconnectUsb() print('%s: disconnectUsb()' % (boolRes(rc), )) rc = oGadget.connectUsb() print('%s: connectUsb()' % (boolRes(rc), )) rc = oGadget.clearImpersonation() print('%s: clearImpersonation()' % (boolRes(rc), )) # Test super speed (and therefore passing configuration items) rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, True) print('%s: impersonate(, True)' % (boolRes(rc), )) rc = oGadget.clearImpersonation() print('%s: clearImpersonation()' % (boolRes(rc), )) # Done rc = oGadget.disconnectFrom() print('%s: disconnectFrom() -> %s' % ( boolRes(rc), rc, )) if g_cFailures != 0: print('tst-utsgadget.py: %u out of %u test failed' % ( g_cFailures, g_cTests, )) return 1 print('tst-utsgadget.py: all %u tests passed!' % (g_cTests, )) return 0
def main(asArgs): # pylint: disable=missing-docstring,too-many-locals,too-many-statements cMsTimeout = long(30*1000); sAddress = 'localhost'; uPort = None; fStdTests = True; i = 1; while i < len(asArgs): if asArgs[i] == '--hostname': sAddress = asArgs[i + 1]; i = i + 2; elif asArgs[i] == '--port': uPort = int(asArgs[i + 1]); i = i + 2; elif asArgs[i] == '--timeout': cMsTimeout = long(asArgs[i + 1]); i = i + 2; elif asArgs[i] == '--help': print('tst-utsgadget.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>]'); return 0; else: print('Unknown argument: %s' % (asArgs[i],)); return 2; oGadget = usbgadget.UsbGadget(); if uPort is None: rc = oGadget.connectTo(cMsTimeout, sAddress); else: rc = oGadget.connectTo(cMsTimeout, sAddress, uPort = uPort); if rc is False: print('connectTo failed'); return 1; if fStdTests: rc = oGadget.getUsbIpPort() is not None; print('%s: getUsbIpPort() -> %s' % (boolRes(rc), oGadget.getUsbIpPort(),)); rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest); print('%s: impersonate()' % (boolRes(rc),)); rc = oGadget.disconnectUsb(); print('%s: disconnectUsb()' % (boolRes(rc),)); rc = oGadget.connectUsb(); print('%s: connectUsb()' % (boolRes(rc),)); rc = oGadget.clearImpersonation(); print('%s: clearImpersonation()' % (boolRes(rc),)); # Test super speed (and therefore passing configuration items) rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, True); print('%s: impersonate(, True)' % (boolRes(rc),)); rc = oGadget.clearImpersonation(); print('%s: clearImpersonation()' % (boolRes(rc),)); # Done rc = oGadget.disconnectFrom(); print('%s: disconnectFrom() -> %s' % (boolRes(rc), rc,)); if g_cFailures != 0: print('tst-utsgadget.py: %u out of %u test failed' % (g_cFailures, g_cTests,)); return 1; print('tst-utsgadget.py: all %u tests passed!' % (g_cTests,)); return 0;