Changeset 65461 in vbox for trunk/src/VBox/ValidationKit/tests/usb
- Timestamp:
- Jan 26, 2017 4:59:23 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 113086
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/usb/tdUsb1.py
r60898 r65461 108 108 self.sGadgetHostnameDef = 'usbtest.de.oracle.com'; 109 109 self.uGadgetPortDef = None; 110 self.sUsbCapturePathDef = self.sScratchPath; 111 self.sUsbCapturePath = self.sUsbCapturePathDef; 112 self.fUsbCapture = False; 110 113 111 114 # … … 140 143 reporter.log(' --default-gadget-port <port>'); 141 144 reporter.log(' Default: %s' % (6042)); 145 reporter.log(' --usb-capture-path <path>'); 146 reporter.log(' Default: %s' % (self.sUsbCapturePathDef)); 147 reporter.log(' --usb-capture'); 148 reporter.log(' Whether to capture the USB traffic for each test'); 142 149 return rc; 143 150 … … 222 229 raise base.InvalidOption('The "--default-gadget-port" value "%s" is zero or negative.' \ 223 230 % (self.uGadgetPortDef,)); 231 elif asArgs[iArg] == '--usb-capture-path': 232 if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-capture-path" takes a path argument'); 233 self.sUsbCapturePath = asArgs[iArg]; 234 elif asArgs[iArg] == '--usb-capture': 235 self.fUsbCapture = True; 224 236 else: 225 237 return vbox.TestDriver.parseOption(self, asArgs, iArg); … … 306 318 return (self.sGadgetHostnameDef, self.uGadgetPortDef); 307 319 320 def getCaptureFilePath(self, sUsbCtrl, sSpeed): 321 """ 322 Returns capture filename from the given data. 323 """ 324 325 return '%s/%s-%s.pcap' % (self.sUsbCapturePath, sUsbCtrl, sSpeed); 326 327 def attachUsbDeviceToVm(self, oSession, sVendorId, sProductId, iBusId, 328 sCaptureFile = None): 329 """ 330 Attaches the given USB device to the VM either via a filter 331 or directly if capturing the USB traffic is enabled. 332 333 Returns True on success, False on failure. 334 """ 335 fRc = False; 336 if sCaptureFile is None: 337 fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = sVendorId, sProductId = sProductId, \ 338 sPort = format(iBusId, 'x')); 339 else: 340 # Search for the correct device in the USB device list waiting for some time 341 # to let it appear. 342 iVendorId = int(sVendorId, 16); 343 iProductId = int(sProductId, 16); 344 345 # Try a few times to give VBoxSVC a chance to detect the new device. 346 for _ in xrange(5): 347 fFound = False; 348 aoUsbDevs = self.oVBoxMgr.getArray(self.oVBox.host, 'USBDevices'); 349 for oUsbDev in aoUsbDevs: 350 if oUsbDev.vendorId == iVendorId \ 351 and oUsbDev.productId == iProductId \ 352 and oUsbDev.port == iBusId: 353 fFound = True; 354 fRc = oSession.attachUsbDevice(oUsbDev.id, sCaptureFile); 355 break; 356 357 if fFound: 358 break; 359 360 # Wait a moment until the next try. 361 self.sleep(1); 362 363 if fRc: 364 # Wait a moment to let the USB device appear 365 self.sleep(3); 366 367 return fRc; 368 308 369 # 309 370 # Test execution helpers. 310 371 # 311 def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed ):372 def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile = None): 312 373 """ 313 374 Test VirtualBoxs USB stack in a VM. … … 331 392 if fRc is True: 332 393 iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); 333 fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ 334 sPort = format(iBusId, 'x')); 394 fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile); 335 395 if fRc is True: 336 337 # Wait a moment to let the USB device appear338 self.sleep(3);339 340 396 tupCmdLine = ('UsbTest', ); 341 397 # Exclude a few tests which hang and cause a timeout, need investigation. … … 362 418 return fRc; 363 419 364 def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed ): # pylint: disable=W0613420 def testUsbReattach(self, oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile = None): # pylint: disable=W0613 365 421 """ 366 422 Tests that rapid connect/disconnect cycles work. … … 383 439 if fRc is True: 384 440 iBusId, _ = oUsbGadget.getGadgetBusAndDevId(); 385 fRc = oSession.addUsbDeviceFilter('Compliance device', sVendorId = '0525', sProductId = 'a4a0', \ 386 sPort = str(iBusId)); 441 fRc = self.attachUsbDeviceToVm(oSession, '0525', 'a4a0', iBusId, sCaptureFile); 387 442 if fRc is True: 388 443 … … 456 511 self.sleep(5); 457 512 513 sCaptureFile = None; 514 if self.fUsbCapture: 515 sCaptureFile = self.getCaptureFilePath(sUsbCtrl, sSpeed); 516 458 517 if sUsbTest == 'Compliance': 459 fRc = self.testUsbCompliance(oSession, oTxsSession, sUsbCtrl, sSpeed );518 fRc = self.testUsbCompliance(oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile); 460 519 elif sUsbTest == 'Reattach': 461 fRc = self.testUsbReattach(oSession, oTxsSession, sUsbCtrl, sSpeed );520 fRc = self.testUsbReattach(oSession, oTxsSession, sUsbCtrl, sSpeed, sCaptureFile); 462 521 463 522 # cleanup. 464 523 self.removeTask(oTxsSession); 465 524 self.terminateVmBySession(oSession) 525 526 # Add the traffic dump if it exists and the test failed 527 if reporter.testErrorCount() > 0 \ 528 and sCaptureFile is not None \ 529 and os.path.exists(sCaptureFile): 530 reporter.addLogFile(sCaptureFile, 'misc/other', 'USB traffic dump'); 466 531 else: 467 532 fRc = False; … … 472 537 Runs one VM thru the various configurations. 473 538 """ 539 fRc = False; 474 540 reporter.testStart(sVmName); 475 541 for sUsbCtrl in self.asUsbCtrls:
Note:
See TracChangeset
for help on using the changeset viewer.