VirtualBox

Changeset 59884 in vbox


Ignore:
Timestamp:
Mar 1, 2016 11:27:30 AM (9 years ago)
Author:
vboxsync
Message:

ValidationKit/usb: Add a new gadget type using the dummy_hcd module to use gadgets on the machine executing the test

Location:
trunk/src/VBox/ValidationKit/tests/usb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/tests/usb/tdUsb1.py

    r59813 r59884  
    99__copyright__ = \
    1010"""
    11 Copyright (C) 2014-2015 Oracle Corporation
     11Copyright (C) 2014-2016 Oracle Corporation
    1212
    1313This file is part of VirtualBox Open Source Edition (OSE), as
     
    105105        self.cUsbReattachCycles    = self.cUsbReattachCyclesDef;
    106106        self.sHostname             = socket.gethostname().lower();
     107        self.fUseTxs               = True;
    107108
    108109    #
     
    112113        rc = vbox.TestDriver.showUsage(self);
    113114        reporter.log('');
    114         reporter.log('tdStorageBenchmark1 Options:');
     115        reporter.log('tdUsb1 Options:');
    115116        reporter.log('  --virt-modes    <m1[:m2[:]]');
    116117        reporter.log('      Default: %s' % (':'.join(self.asVirtModesDef)));
     
    131132        reporter.log('  --usb-reattach-cycles <cycles>');
    132133        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');
    133137        return rc;
    134138
     
    196200                raise base.InvalidOption('The "--usb-reattach-cycles" value "%s" is zero or negative.' \
    197201                    % (self.cUsbReattachCycles,));
     202        elif asArgs[iArg] == '--local':
     203            self.fUseTxs = False;
    198204        else:
    199205            return vbox.TestDriver.parseOption(self, asArgs, iArg);
     
    288294        """
    289295        # 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;
    291301
    292302        # Create device filter
     
    295305            oUsbGadget = usbgadget.UsbGadget();
    296306            reporter.log('Connecting to gadget: ' + sGadgetType);
    297             fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost);
     307            fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost);
    298308            if fRc is True:
    299309                reporter.log('Connect succeeded');
     
    330340        """
    331341        # 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;
    333347
    334348        # Create device filter
     
    337351            oUsbGadget = usbgadget.UsbGadget();
    338352            reporter.log('Connecting to gadget: ' + sGadgetType);
    339             fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost);
     353            fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, self.fUseTxs, sGadgetHost);
    340354            if fRc is True:
    341355                reporter.log('Connect succeeded');
  • trunk/src/VBox/ValidationKit/tests/usb/usbgadget.py

    r58937 r59884  
    99__copyright__ = \
    1010"""
    11 Copyright (C) 2014-2015 Oracle Corporation
     11Copyright (C) 2014-2016 Oracle Corporation
    1212
    1313This file is part of VirtualBox Open Source Edition (OSE), as
     
    3434import testdriver.txsclient as txsclient;
    3535import testdriver.reporter as reporter;
     36from common import utils;
    3637
    3738## @name USB gadget type string constants.
     
    4041g_ksGadgetTypeBeaglebone  = 'BeagleBone';
    4142g_ksGadgetTypeODroidXu3   = 'ODroidXu3';
     43g_ksGadgetTypeDummyHcd    = 'DummyHcd';
     44## @}
     45
     46## @name USB gadget configurations.
     47## @{
     48g_kdGadgetCfgs = {
     49    g_ksGadgetTypeBeaglebone: ('musb-hdrc.0.auto'),
     50    g_ksGadgetTypeODroidXu3:  ('12400000.dwc3'),
     51    g_ksGadgetTypeDummyHcd:   ('dummy_udc.0')
     52};
    4253## @}
    4354
     
    5970
    6071    def __init__(self):
    61         self.oTxsSession = None;
     72        self.oTxsSession    = None;
    6273        self.sImpersonation = g_ksGadgetImpersonationInvalid;
    6374        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;
    64105
    65106    def _loadModule(self, sModule):
     
    69110        Returns False otherwise.
    70111        """
    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, ));
    76113
    77114    def _unloadModule(self, sModule):
     
    81118        Returns False otherwise.
    82119        """
    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, ));
    89121
    90122    def _clearImpersonation(self):
     
    111143        return False;
    112144
     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
    113172    def disconnectUsb(self):
    114173        """
     
    116175        connection used for control)
    117176        """
    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');
    125178
    126179    def connectUsb(self):
     
    128181        Connect the USB gadget to the host.
    129182        """
    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');
    137184
    138185    def impersonate(self, sImpersonation):
     
    162209        return False;
    163210
    164     def connectTo(self, cMsTimeout, sGadgetType, sHostname, uPort = None):
     211    def connectTo(self, cMsTimeout, sGadgetType, fUseTxs, sHostname, uPort = None):
    165212        """
    166213        Connects to the specified target device.
     
    168215        Returns False otherwise.
    169216        """
    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();
    186241
    187242        return fRc;
     
    193248        fRc = True;
    194249
    195         if self.oTxsSession is not None:
     250        if self.sGadgetType is not g_ksGadgetTypeInvalid:
    196251            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.

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