Changeset 59884 in vbox
- Timestamp:
- Mar 1, 2016 11:27:30 AM (9 years ago)
- Location:
- trunk/src/VBox/ValidationKit/tests/usb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/tests/usb/tdUsb1.py
r59813 r59884 9 9 __copyright__ = \ 10 10 """ 11 Copyright (C) 2014-201 5Oracle Corporation11 Copyright (C) 2014-2016 Oracle Corporation 12 12 13 13 This file is part of VirtualBox Open Source Edition (OSE), as … … 105 105 self.cUsbReattachCycles = self.cUsbReattachCyclesDef; 106 106 self.sHostname = socket.gethostname().lower(); 107 self.fUseTxs = True; 107 108 108 109 # … … 112 113 rc = vbox.TestDriver.showUsage(self); 113 114 reporter.log(''); 114 reporter.log('td StorageBenchmark1 Options:');115 reporter.log('tdUsb1 Options:'); 115 116 reporter.log(' --virt-modes <m1[:m2[:]]'); 116 117 reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef))); … … 131 132 reporter.log(' --usb-reattach-cycles <cycles>'); 132 133 reporter.log(' Default: %s' % (self.cUsbReattachCyclesDef)); 134 reporter.log(' --local'); 135 reporter.log(' Don\'t use TXS for communication with the gadget but do everything'); 136 reporter.log(' on this host'); 133 137 return rc; 134 138 … … 196 200 raise base.InvalidOption('The "--usb-reattach-cycles" value "%s" is zero or negative.' \ 197 201 % (self.cUsbReattachCycles,)); 202 elif asArgs[iArg] == '--local': 203 self.fUseTxs = False; 198 204 else: 199 205 return vbox.TestDriver.parseOption(self, asArgs, iArg); … … 288 294 """ 289 295 # Get configured USB test devices from hostname we are running on 290 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); 296 if self.fUseTxs is True: 297 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); 298 else: 299 sGadgetHost = 'dummy'; 300 sGadgetType = usbgadget.g_ksGadgetTypeDummyHcd; 291 301 292 302 # Create device filter … … 295 305 oUsbGadget = usbgadget.UsbGadget(); 296 306 reporter.log('Connecting to gadget: ' + sGadgetType); 297 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, s GadgetHost);307 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost); 298 308 if fRc is True: 299 309 reporter.log('Connect succeeded'); … … 330 340 """ 331 341 # Get configured USB test devices from hostname we are running on 332 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); 342 if self.fUseTxs is True: 343 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed); 344 else: 345 sGadgetHost = 'dummy'; 346 sGadgetType = usbgadget.g_ksGadgetTypeDummyHcd; 333 347 334 348 # Create device filter … … 337 351 oUsbGadget = usbgadget.UsbGadget(); 338 352 reporter.log('Connecting to gadget: ' + sGadgetType); 339 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, s GadgetHost);353 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost); 340 354 if fRc is True: 341 355 reporter.log('Connect succeeded'); -
trunk/src/VBox/ValidationKit/tests/usb/usbgadget.py
r58937 r59884 9 9 __copyright__ = \ 10 10 """ 11 Copyright (C) 2014-201 5Oracle Corporation11 Copyright (C) 2014-2016 Oracle Corporation 12 12 13 13 This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 import testdriver.txsclient as txsclient; 35 35 import testdriver.reporter as reporter; 36 from common import utils; 36 37 37 38 ## @name USB gadget type string constants. … … 40 41 g_ksGadgetTypeBeaglebone = 'BeagleBone'; 41 42 g_ksGadgetTypeODroidXu3 = 'ODroidXu3'; 43 g_ksGadgetTypeDummyHcd = 'DummyHcd'; 44 ## @} 45 46 ## @name USB gadget configurations. 47 ## @{ 48 g_kdGadgetCfgs = { 49 g_ksGadgetTypeBeaglebone: ('musb-hdrc.0.auto'), 50 g_ksGadgetTypeODroidXu3: ('12400000.dwc3'), 51 g_ksGadgetTypeDummyHcd: ('dummy_udc.0') 52 }; 42 53 ## @} 43 54 … … 59 70 60 71 def __init__(self): 61 self.oTxsSession = None;72 self.oTxsSession = None; 62 73 self.sImpersonation = g_ksGadgetImpersonationInvalid; 63 74 self.sGadgetType = g_ksGadgetTypeInvalid; 75 76 def _sudoExecuteSync(self, asArgs): 77 """ 78 Executes a sudo child process synchronously. 79 Returns a tuple [True, 0] if the process executed successfully 80 and returned 0, otherwise [False, rc] is returned. 81 """ 82 reporter.log('Executing [sudo]: %s' % (asArgs, )); 83 reporter.flushall(); 84 iRc = 0; 85 try: 86 iRc = utils.sudoProcessCall(asArgs, shell = False, close_fds = False); 87 except: 88 reporter.errorXcpt(); 89 return (False, 0); 90 reporter.log('Exit code [sudo]: %s (%s)' % (iRc, asArgs)); 91 return (iRc is 0, iRc); 92 93 def _execLocallyOrThroughTxs(self, sExec, asArgs): 94 """ 95 Executes the given program locally or through TXS based on the 96 current config. 97 """ 98 fRc = False; 99 100 if self.oTxsSession is not None: 101 fRc = self.oTxsSession.syncExecEx(sExec, (sExec,) + asArgs); 102 else: 103 fRc, _ = self._sudoExecuteSync([sExec, ] + list(asArgs)); 104 return fRc; 64 105 65 106 def _loadModule(self, sModule): … … 69 110 Returns False otherwise. 70 111 """ 71 fRc = False; 72 if self.oTxsSession is not None: 73 fRc = self.oTxsSession.syncExecEx('/usr/bin/modprobe', ('/usr/bin/modprobe', sModule)); 74 fRc = fRc and self.connectUsb(); 75 return fRc; 112 return self._execLocallyOrThroughTxs('/usr/bin/modprobe', (sModule, )); 76 113 77 114 def _unloadModule(self, sModule): … … 81 118 Returns False otherwise. 82 119 """ 83 fRc = False; 84 if self.oTxsSession is not None: 85 self.disconnectUsb(); 86 fRc = self.oTxsSession.syncExecEx('/usr/bin/rmmod', ('/usr/bin/rmmod', sModule)); 87 88 return fRc; 120 return self._execLocallyOrThroughTxs('/usr/bin/rmmod', (sModule, )); 89 121 90 122 def _clearImpersonation(self): … … 111 143 return False; 112 144 145 def _doSoftConnect(self, sAction): 146 """ 147 Does a softconnect/-disconnect based on the given action. 148 """ 149 sUdcFile = g_kdGadgetCfgs.get(self.sGadgetType); 150 sPath = '/sys/class/udc/' + sUdcFile + '/soft_connect'; 151 152 return self._execLocallyOrThroughTxs('/usr/bin/sh', ('-c', 'echo' + sAction + ' > ' + sPath)); 153 154 def _prepareGadget(self): 155 """ 156 Prepares the gadget for use in testing. 157 """ 158 fRc = True; 159 if self.sGadgetType is g_ksGadgetTypeDummyHcd: 160 fRc = self._loadModule('dummy_hcd'); 161 return fRc; 162 163 def _cleanupGadget(self): 164 """ 165 Cleans up the gadget to the default state. 166 """ 167 fRc = True; 168 if self.sGadgetType is g_ksGadgetTypeDummyHcd: 169 fRc = self._unloadModule('dummy_hcd'); 170 return fRc; 171 113 172 def disconnectUsb(self): 114 173 """ … … 116 175 connection used for control) 117 176 """ 118 if self.sGadgetType == g_ksGadgetTypeODroidXu3: 119 fRc = self.oTxsSession.syncExecEx('/usr/bin/sh', \ 120 ('/usr/bin/sh', '-c', 'echo disconnect > /sys/class/udc/12400000.dwc3/soft_connect')); 121 elif self.sGadgetType == g_ksGadgetTypeBeaglebone: 122 fRc = self.oTxsSession.syncExecEx('/usr/bin/sh', \ 123 ('/usr/bin/sh', '-c', 'echo disconnect > /sys/class/udc/musb-hdrc.0.auto/soft_connect')); 124 return fRc; 177 return self._doSoftConnect('disconnect'); 125 178 126 179 def connectUsb(self): … … 128 181 Connect the USB gadget to the host. 129 182 """ 130 if self.sGadgetType == g_ksGadgetTypeODroidXu3: 131 fRc = self.oTxsSession.syncExecEx('/usr/bin/sh', \ 132 ('/usr/bin/sh', '-c', 'echo connect > /sys/class/udc/12400000.dwc3/soft_connect')); 133 elif self.sGadgetType == g_ksGadgetTypeBeaglebone: 134 fRc = self.oTxsSession.syncExecEx('/usr/bin/sh', \ 135 ('/usr/bin/sh', '-c', 'echo connect > /sys/class/udc/musb-hdrc.0.auto/soft_connect')); 136 return fRc; 183 return self._doSoftConnect('connect'); 137 184 138 185 def impersonate(self, sImpersonation): … … 162 209 return False; 163 210 164 def connectTo(self, cMsTimeout, sGadgetType, sHostname, uPort = None):211 def connectTo(self, cMsTimeout, sGadgetType, fUseTxs, sHostname, uPort = None): 165 212 """ 166 213 Connects to the specified target device. … … 168 215 Returns False otherwise. 169 216 """ 170 if uPort is None: 171 self.oTxsSession = txsclient.openTcpSession(cMsTimeout, sHostname); 172 else: 173 self.oTxsSession = txsclient.openTcpSession(cMsTimeout, sHostname, uPort = uPort); 174 if self.oTxsSession is None: 175 return False; 176 177 fDone = self.oTxsSession.waitForTask(30*1000); 178 print 'connect: waitForTask -> %s, result %s' % (fDone, self.oTxsSession.getResult()); 179 if fDone is True and self.oTxsSession.isSuccess(): 180 fRc = True; 181 else: 182 fRc = False; 183 184 if fRc is True: 185 self.sGadgetType = sGadgetType; 217 fRc = True; 218 219 if fUseTxs: 220 if uPort is None: 221 self.oTxsSession = txsclient.openTcpSession(cMsTimeout, sHostname); 222 else: 223 self.oTxsSession = txsclient.openTcpSession(cMsTimeout, sHostname, uPort = uPort); 224 if self.oTxsSession is None: 225 return False; 226 227 fDone = self.oTxsSession.waitForTask(30*1000); 228 print 'connect: waitForTask -> %s, result %s' % (fDone, self.oTxsSession.getResult()); 229 if fDone is True and self.oTxsSession.isSuccess(): 230 fRc = True; 231 else: 232 fRc = False; 233 234 if fRc is True: 235 self.sGadgetType = sGadgetType; 236 else: 237 self.sGadgetType = g_ksGadgetTypeInvalid; 238 239 if fRc: 240 fRc = self._prepareGadget(); 186 241 187 242 return fRc; … … 193 248 fRc = True; 194 249 195 if self. oTxsSession is not None:250 if self.sGadgetType is not g_ksGadgetTypeInvalid: 196 251 self._clearImpersonation(); 197 fRc = self.oTxsSession.syncDisconnect(); 198 199 return fRc; 252 self._cleanupGadget(); 253 if self.oTxsSession is not None: 254 fRc = self.oTxsSession.syncDisconnect(); 255 256 return fRc;
Note:
See TracChangeset
for help on using the changeset viewer.