VirtualBox

Ignore:
Timestamp:
Apr 14, 2016 10:33:11 AM (9 years ago)
Author:
vboxsync
Message:

ValidationKit/usb: Fixes

Location:
trunk/src/VBox/ValidationKit/tests/usb
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/usb/Makefile.kmk

    r56295 r60488  
    3434ValidationKitTestsUsb_EXEC_SOURCES := \
    3535        $(PATH_SUB_CURRENT)/tdUsb1.py \
    36         $(PATH_SUB_CURRENT)/usbgadget.py
     36        $(PATH_SUB_CURRENT)/usbgadget.py \
     37        $(PATH_SUB_CURRENT)/usbgadget2.py
    3738
    3839VBOX_VALIDATIONKIT_PYTHON_SOURCES += $(ValidationKitTestsUsb_EXEC_SOURCES)
  • trunk/src/VBox/ValidationKit/tests/usb/tdUsb1.py

    r59884 r60488  
    4949
    5050# USB gadget control import
    51 import usbgadget;
     51import usbgadget2;
    5252
    5353class tdUsbBenchmark(vbox.TestDriver):                                      # pylint: disable=R0902
     
    6565    kdGadgetParams = {
    6666        # The following is for local testing and not for the test lab.
     67        #'adaris': {
     68        #    'Low':   ('beaglebone',),
     69        #    'Full':  ('beaglebone',),
     70        #    'High':  ('beaglebone',),
     71        #    'Super': ('odroidxu3',)
     72        #},
    6773        'adaris': {
    68             'Low':   ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    69             'Full':  ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    70             'High':  ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    71             'Super': ('odroidxu3',  usbgadget.g_ksGadgetTypeODroidXu3)
    72         },
    73         'archusb': {
    74             'Low':   ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    75             'Full':  ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    76             'High':  ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
    77             'Super': ('odroidxu3',  usbgadget.g_ksGadgetTypeODroidXu3)
     74            'Low':   ('127.0.0.1', 0),
     75            'Full':  ('127.0.0.1', 0),
     76            'High':  ('127.0.0.1', 0),
     77            'Super': ('127.0.0.1', 0)
    7878        },
    7979    };
     
    105105        self.cUsbReattachCycles    = self.cUsbReattachCyclesDef;
    106106        self.sHostname             = socket.gethostname().lower();
    107         self.fUseTxs               = True;
    108107
    109108    #
     
    132131        reporter.log('  --usb-reattach-cycles <cycles>');
    133132        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');
    137133        return rc;
    138134
     
    200196                raise base.InvalidOption('The "--usb-reattach-cycles" value "%s" is zero or negative.' \
    201197                    % (self.cUsbReattachCycles,));
    202         elif asArgs[iArg] == '--local':
    203             self.fUseTxs = False;
    204198        else:
    205199            return vbox.TestDriver.parseOption(self, asArgs, iArg);
     
    294288        """
    295289        # Get configured USB test devices from hostname we are running on
    296         if self.fUseTxs is True:
    297             sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed);
    298         else:
    299             sGadgetHost = 'dummy';
    300             sGadgetType = usbgadget.g_ksGadgetTypeDummyHcd;
    301 
    302         # Create device filter
    303         fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
     290        sGadgetHost, _ = self.getGadgetParams(self.sHostname, sSpeed);
     291
     292        oUsbGadget = usbgadget2.UsbGadget();
     293        reporter.log('Connecting to UTS: ' + sGadgetHost);
     294        fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost);
    304295        if fRc is True:
    305             oUsbGadget = usbgadget.UsbGadget();
    306             reporter.log('Connecting to gadget: ' + sGadgetType);
    307             fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost);
     296            reporter.log('Connect succeeded');
     297            self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost, [], []);
     298
     299            # Create device filter
     300            fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
    308301            if fRc is True:
    309                 reporter.log('Connect succeeded');
    310                 fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
     302                fRc = oUsbGadget.impersonate(usbgadget2.g_ksGadgetImpersonationTest);
    311303                if fRc is True:
    312304
    313305                    # Wait a moment to let the USB device appear
    314                     self.sleep(3);
     306                    self.sleep(10);
    315307
    316308                    tupCmdLine = ('UsbTest', );
     
    329321                oUsbGadget.disconnectFrom();
    330322            else:
    331                 reporter.testFailure('Failed to connect to USB gadget');
     323                reporter.testFailure('Failed to create USB device filter');
     324
     325            self.oVBox.host.removeUSBDeviceSource(sGadgetHost);
    332326        else:
    333             reporter.testFailure('Failed to create USB device filter');
     327            reporter.testFailure('Failed to connect to USB gadget');
    334328
    335329        return fRc;
     
    340334        """
    341335        # Get configured USB test devices from hostname we are running on
    342         if self.fUseTxs is True:
    343             sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed);
    344         else:
    345             sGadgetHost = 'dummy';
    346             sGadgetType = usbgadget.g_ksGadgetTypeDummyHcd;
    347 
    348         # Create device filter
    349         fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
     336        sGadgetHost, _ = self.getGadgetParams(self.sHostname, sSpeed);
     337
     338        oUsbGadget = usbgadget2.UsbGadget();
     339        reporter.log('Connecting to UTS: ' + sGadgetHost);
     340        fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost);
    350341        if fRc is True:
    351             oUsbGadget = usbgadget.UsbGadget();
    352             reporter.log('Connecting to gadget: ' + sGadgetType);
    353             fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost);
     342            reporter.log('Connect succeeded');
     343            self.oVBox.host.addUSBDeviceSource('USBIP', sGadgetHost, sGadgetHost, [], []);
     344
     345            # Create device filter
     346            fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
    354347            if fRc is True:
    355                 reporter.log('Connect succeeded');
    356                 fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
     348                fRc = oUsbGadget.impersonate(usbgadget2.g_ksGadgetImpersonationTest);
    357349                if fRc is True:
    358350
  • trunk/src/VBox/ValidationKit/tests/usb/usbgadget.py

    r59884 r60488  
    3030__version__ = "$Revision$"
    3131
     32import time;
    3233
    3334# Validation Kit imports.
     
    150151        sPath = '/sys/class/udc/' + sUdcFile + '/soft_connect';
    151152
    152         return self._execLocallyOrThroughTxs('/usr/bin/sh', ('-c', 'echo' + sAction + ' > ' + sPath));
     153        return self._execLocallyOrThroughTxs('/usr/bin/sh', ('-c', 'echo ' + sAction + ' > ' + sPath));
    153154
    154155    def _prepareGadget(self):
     
    192193        self.sImpersonation = sImpersonation;
    193194
    194         if sImpersonation == g_ksGadgetImpersonationInvalid:
    195             return False;
    196         elif sImpersonation == g_ksGadgetImpersonationTest:
    197             return self._loadModule('g_zero');
     195        fRc = False;
     196        if sImpersonation == g_ksGadgetImpersonationTest:
     197            fRc = self._loadModule('g_zero');
    198198        elif sImpersonation == g_ksGadgetImpersonationMsd:
    199199            # @todo: Not complete
    200             return self._loadModule('g_mass_storage');
     200            fRc = self._loadModule('g_mass_storage');
    201201        elif sImpersonation == g_ksGadgetImpersonationWebcam:
    202202            # @todo: Not complete
    203             return self._loadModule('g_webcam');
     203            fRc = self._loadModule('g_webcam');
    204204        elif sImpersonation == g_ksGadgetImpersonationEther:
    205             return self._loadModule('g_ether');
     205            fRc = self._loadModule('g_ether');
    206206        else:
    207207            reporter.log('Invalid impersonation');
    208208
    209         return False;
     209        if fRc and self.sGadgetType is g_ksGadgetTypeDummyHcd and self.oTxsSession is not None:
     210            time.sleep(2); # Fudge
     211            # For the dummy HCD over USB/IP case we have to bind the device to the USB/IP server
     212            self._execLocallyOrThroughTxs('/usr/bin/sh', ('-c', '/usr/bin/usbip bind -b 3-1'));
     213
     214        return fRc;
    210215
    211216    def connectTo(self, cMsTimeout, sGadgetType, fUseTxs, sHostname, uPort = None):
  • trunk/src/VBox/ValidationKit/tests/usb/usbgadget2.py

    r60429 r60488  
    7171#
    7272
     73def getU64(abData, off):
     74    """Get a U64 field."""
     75    return abData[off] \
     76         + abData[off + 1] * 256 \
     77         + abData[off + 2] * 65536 \
     78         + abData[off + 3] * 16777216 \
     79         + abData[off + 4] * 4294967296 \
     80         + abData[off + 5] * 1099511627776 \
     81         + abData[off + 6] * 281474976710656 \
     82         + abData[off + 7] * 72057594037927936;
     83
    7384def getU32(abData, off):
    7485    """Get a U32 field."""
     
    7788         + abData[off + 2] * 65536 \
    7889         + abData[off + 3] * 16777216;
     90
     91def getU16(abData, off):
     92    """Get a U16 field."""
     93    return abData[off] \
     94         + abData[off + 1] * 256;
     95
     96def getU8(abData, off):
     97    """Get a U8 field."""
     98    return abData[off];
    7999
    80100def getSZ(abData, off, sDefault = None):
     
    150170def u8ToByteArray(u8):
    151171    """Encodes the u8 value as a little endian byte (B) array."""
    152     return array.array('B', (u8 % 256);
     172    return array.array('B', (u8 % 256));
     173
     174def zeroByteArray(cb):
     175    """Returns an array with the given size containing 0."""
     176    abArray = array.array('B', (0, ));
     177    cb = cb - 1;
     178    for i in range(cb):
     179        abArray.append(0);
     180    return abArray;
    153181
    154182class TransportBase(object):
     
    693721    def taskGreet(self, cMsIdleFudge):
    694722        """Greets the UTS"""
    695         rc = self.sendMsg("HOWDY", ());
     723        sHostname = socket.gethostname().lower();
     724        cbFill = 68 - len(sHostname) - 1;
     725        rc = self.sendMsg("HOWDY", (long((1 << 16) | 0), long(0x1), long(len(sHostname)), sHostname, zeroByteArray(cbFill)));
    696726        if rc is True:
    697727            rc = self.recvAckLogged("HOWDY", self.fTryConnect);
     
    718748    def taskGadgetCreate(self, iGadgetType, iGadgetAccess):
    719749        """Creates a new gadget on UTS"""
    720         fRc = self.senfMsg("GDGTCRT", (iGadgetType, iGadgetAccess, 0));
     750        fRc = self.sendMsg("GDGTCRT", (iGadgetType, iGadgetAccess, 0));
    721751        if fRc is True:
    722752            fRc = self.recvAckLogged("GDGTCRT");
     
    725755    def taskGadgetDestroy(self, iGadgetId):
    726756        """Destroys the given gadget handle on UTS"""
    727         fRc = self.senfMsg("GDGTDTOR", (iGadgetId, ));
     757        fRc = self.sendMsg("GDGTDTOR", (iGadgetId, ));
    728758        if fRc is True:
    729759            fRc = self.recvAckLogged("GDGTDTOR");
     
    732762    def taskGadgetConnect(self, iGadgetId):
    733763        """Connects the given gadget handle on UTS"""
    734         fRc = self.senfMsg("GDGTCNCT", (iGadgetId, ));
     764        fRc = self.sendMsg("GDGTCNCT", (iGadgetId, ));
    735765        if fRc is True:
    736766            fRc = self.recvAckLogged("GDGTCNCT");
     
    739769    def taskGadgetDisconnect(self, iGadgetId):
    740770        """Disconnects the given gadget handle from UTS"""
    741         fRc = self.senfMsg("GDGTDCNT", (iGadgetId, ));
     771        fRc = self.sendMsg("GDGTDCNT", (iGadgetId, ));
    742772        if fRc is True:
    743773            fRc = self.recvAckLogged("GDGTDCNT");
     
    805835    #
    806836
    807     def
     837    def asyncGadgetCreate(self, iGadgetType, iGadgetAccess, cMsTimeout = 30000, fIgnoreErrors = False):
     838        """
     839        Initiates a gadget create task.
     840
     841        Returns True on success, False on failure (logged).
     842
     843        The task returns True on success and False on failure.
     844        """
     845        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetCreate", self.taskGadgetCreate, \
     846                              (long(iGadgetType), long(iGadgetAccess)));
     847
     848    def syncGadgetCreate(self, iGadgetType, iGadgetAccess, cMsTimeout = 30000, fIgnoreErrors = False):
     849        """Synchronous version."""
     850        return self.asyncToSync(self.asyncGadgetCreate, iGadgetType, iGadgetAccess, cMsTimeout, fIgnoreErrors);
     851
     852    def asyncGadgetDestroy(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     853        """
     854        Initiates a gadget destroy task.
     855
     856        Returns True on success, False on failure (logged).
     857
     858        The task returns True on success and False on failure.
     859        """
     860        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetDestroy", self.taskGadgetDestroy, \
     861                              (long(iGadgetId), ));
     862
     863    def syncGadgetDestroy(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     864        """Synchronous version."""
     865        return self.asyncToSync(self.asyncGadgetDestroy, iGadgetId, cMsTimeout, fIgnoreErrors);
     866
     867    def asyncGadgetConnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     868        """
     869        Initiates a gadget connect task.
     870
     871        Returns True on success, False on failure (logged).
     872
     873        The task returns True on success and False on failure.
     874        """
     875        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetConnect", self.taskGadgetConnect, \
     876                              (long(iGadgetId), ));
     877
     878    def syncGadgetConnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     879        """Synchronous version."""
     880        return self.asyncToSync(self.asyncGadgetConnect, iGadgetId, cMsTimeout, fIgnoreErrors);
     881
     882    def asyncGadgetDisconnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     883        """
     884        Initiates a gadget disconnect task.
     885
     886        Returns True on success, False on failure (logged).
     887
     888        The task returns True on success and False on failure.
     889        """
     890        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetDisconnect", self.taskGadgetDisconnect, \
     891                              (long(iGadgetId), ));
     892
     893    def syncGadgetDisconnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     894        """Synchronous version."""
     895        return self.asyncToSync(self.asyncGadgetDisconnect, iGadgetId, cMsTimeout, fIgnoreErrors);
    808896
    809897
     
    12031291        self.oUtsSession    = None;
    12041292        self.sImpersonation = g_ksGadgetImpersonationInvalid;
    1205         self.sGadgetType    = g_ksGadgetTypeInvalid;
    12061293        self.idGadget       = None;
     1294        self.iUsbIpPort     = None;
    12071295
    12081296    def _clearImpersonation(self):
     
    12471335        return fRc;
    12481336
    1249     def connectTo(self, cMsTimeout, sHostname, uPort = None):
     1337    def getUsbIpPort(self):
     1338        """
     1339        Returns the port the USB/IP server is listening on if requested,
     1340        None if USB/IP is not supported.
     1341        """
     1342        return self.iUsbIpPort;
     1343
     1344    def connectTo(self, cMsTimeout, sHostname, uPort = None, fUsbIpSupport = True, cMsIdleFudge = 0):
    12501345        """
    12511346        Connects to the specified target device.
     
    12701365            else:
    12711366                fRc = False;
    1272 
    1273             if fRc:
    1274                 fRc = self._prepareGadget();
    12751367        except:
    12761368            reporter.errorXcpt(None, 15);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette