VirtualBox

Changeset 60522 in vbox


Ignore:
Timestamp:
Apr 15, 2016 2:34:35 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106643
Message:

ValidationKit/usb: Fixes, basic compliance testing works finally

Location:
trunk/src/VBox/ValidationKit
Files:
7 edited

Legend:

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

    r60493 r60522  
    6464    # and the hardware type.
    6565    kdGadgetParams = {
    66         # 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         #},
    7366        'adaris': {
    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)
     67            'Low':   ('usbtest.de.oracle.com', None),
     68            'Full':  ('usbtest.de.oracle.com', None),
     69            'High':  ('usbtest.de.oracle.com', None),
     70            'Super': ('usbtest.de.oracle.com', None)
    7871        },
    7972    };
     
    10598        self.cUsbReattachCycles    = self.cUsbReattachCyclesDef;
    10699        self.sHostname             = socket.gethostname().lower();
     100        self.sGadgetHostnameDef    = 'usbtest.de.oracle.com';
     101        self.uGadgetPortDef        = None;
    107102
    108103    #
     
    131126        reporter.log('  --usb-reattach-cycles <cycles>');
    132127        reporter.log('      Default: %s' % (self.cUsbReattachCyclesDef));
     128        reporter.log('  --hostname: <hostname>');
     129        reporter.log('      Default: %s' % (self.sHostname));
     130        reporter.log('  --default-gadget-host <hostname>');
     131        reporter.log('      Default: %s' % (self.sGadgetHostnameDef));
     132        reporter.log('  --default-gadget-port <port>');
     133        reporter.log('      Default: %s' % (6042));
    133134        return rc;
    134135
     
    196197                raise base.InvalidOption('The "--usb-reattach-cycles" value "%s" is zero or negative.' \
    197198                    % (self.cUsbReattachCycles,));
     199        elif asArgs[iArg] == '--hostname':
     200            iArg += 1;
     201            if iArg >= len(asArgs): raise base.InvalidOption('The "--hostname" takes a hostname');
     202            self.sHostname = asArgs[iArg];
     203        elif asArgs[iArg] == '--default-gadget-host':
     204            iArg += 1;
     205            if iArg >= len(asArgs): raise base.InvalidOption('The "--default-gadget-host" takes a hostname');
     206            self.sGadgetHostnameDef = asArgs[iArg];
     207        elif asArgs[iArg] == '--default-gadget-port':
     208            iArg += 1;
     209            if iArg >= len(asArgs): raise base.InvalidOption('The "--default-gadget-port" takes port number');
     210            try:    self.uGadgetPortDef = int(asArgs[iArg]);
     211            except: raise base.InvalidOption('The "--default-gadget-port" value "%s" is not an integer' \
     212                    % (asArgs[iArg],));
     213            if self.uGadgetPortDef <= 0:
     214                raise base.InvalidOption('The "--default-gadget-port" value "%s" is zero or negative.' \
     215                    % (self.uGadgetPortDef,));
    198216        else:
    199217            return vbox.TestDriver.parseOption(self, asArgs, iArg);
     
    271289    def getGadgetParams(self, sHostname, sSpeed):
    272290        """
    273         Returns the gadget hostname and type from the
     291        Returns the gadget hostname and port from the
    274292        given hostname the test is running on and device speed we want to test.
    275293        """
     
    278296            return kdGadgetsConfigured.get(sSpeed);
    279297
    280         return (None, None);
     298        return (self.sGadgetHostnameDef, self.uGadgetPortDef);
    281299
    282300    #
     
    288306        """
    289307        # Get configured USB test devices from hostname we are running on
    290         sGadgetHost, _ = self.getGadgetParams(self.sHostname, sSpeed);
     308        sGadgetHost, uGadgetPort = self.getGadgetParams(self.sHostname, sSpeed);
    291309
    292310        oUsbGadget = usbgadget2.UsbGadget();
    293311        reporter.log('Connecting to UTS: ' + sGadgetHost);
    294         fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost);
     312        fRc = oUsbGadget.connectTo(30 * 1000, sGadgetHost, uPort = uGadgetPort);
    295313        if fRc is True:
    296314            reporter.log('Connect succeeded');
  • trunk/src/VBox/ValidationKit/tests/usb/tst-utsgadget.py

    r60488 r60522  
    3737sys.path.insert(0, '.');
    3838sys.path.insert(0, '..');
     39sys.path.insert(0, '../..');
    3940import usbgadget2 as usbgadget;
    4041import testdriver.reporter as reporter
     
    9899
    99100    if fStdTests:
     101        if oGadget.getUsbIpPort() is not None:
     102            rc = True;
     103        else:
     104            rc = False;
     105        print '%s: getUsbIpPort() -> %s' % (boolRes(rc), oGadget.getUsbIpPort());
    100106
     107        rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
     108        print '%s: impersonate()' % (boolRes(rc));
     109
     110        rc = oGadget.disconnectUsb();
     111        print '%s: disconnectUsb()' % (boolRes(rc));
     112
     113        rc = oGadget.connectUsb();
     114        print '%s: connectUsb()' % (boolRes(rc));
     115
     116        rc = oGadget.clearImpersonation();
     117        print '%s: clearImpersonation()' % (boolRes(rc));
    101118
    102119        # Done
    103120        rc = oGadget.disconnectFrom();
    104         print '%s: disconnect() -> %s' % (boolRes(rc), rc);
     121        print '%s: disconnectFrom() -> %s' % (boolRes(rc), rc);
    105122
    106123    if g_cFailures != 0:
  • trunk/src/VBox/ValidationKit/tests/usb/usbgadget2.py

    r60493 r60522  
    758758    def taskGadgetDestroy(self, iGadgetId):
    759759        """Destroys the given gadget handle on UTS"""
    760         fRc = self.sendMsg("GDGTDTOR", (iGadgetId, ));
     760        fRc = self.sendMsg("GDGTDTOR", (iGadgetId, zeroByteArray(12)));
    761761        if fRc is True:
    762762            fRc = self.recvAckLogged("GDGTDTOR");
     
    765765    def taskGadgetConnect(self, iGadgetId):
    766766        """Connects the given gadget handle on UTS"""
    767         fRc = self.sendMsg("GDGTCNCT", (iGadgetId, ));
     767        fRc = self.sendMsg("GDGTCNCT", (iGadgetId, zeroByteArray(12)));
    768768        if fRc is True:
    769769            fRc = self.recvAckLogged("GDGTCNCT");
     
    772772    def taskGadgetDisconnect(self, iGadgetId):
    773773        """Disconnects the given gadget handle from UTS"""
    774         fRc = self.sendMsg("GDGTDCNT", (iGadgetId, ));
     774        fRc = self.sendMsg("GDGTDCNT", (iGadgetId, zeroByteArray(12)));
    775775        if fRc is True:
    776776            fRc = self.recvAckLogged("GDGTDCNT");
     
    877877        """
    878878        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetConnect", self.taskGadgetConnect, \
    879                               (long(iGadgetId), ));
     879                              (iGadgetId, ));
    880880
    881881    def syncGadgetConnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     
    892892        """
    893893        return self.startTask(cMsTimeout, fIgnoreErrors, "GadgetDisconnect", self.taskGadgetDisconnect, \
    894                               (long(iGadgetId), ));
     894                              (iGadgetId, ));
    895895
    896896    def syncGadgetDisconnect(self, iGadgetId, cMsTimeout = 30000, fIgnoreErrors = False):
     
    12971297        self.iUsbIpPort     = None;
    12981298
    1299     def _clearImpersonation(self):
     1299    def clearImpersonation(self):
    13001300        """
    13011301        Removes the current impersonation of the gadget.
     
    13051305        if self.idGadget is not None:
    13061306            fRc = self.oUtsSession.syncGadgetDestroy(self.idGadget);
     1307            self.idGadget = None;
    13071308
    13081309        return fRc;
     
    13271328
    13281329        # Clear any previous impersonation
    1329         self._clearImpersonation();
     1330        self.clearImpersonation();
    13301331        self.sImpersonation = sImpersonation;
    13311332
    13321333        fRc = False;
    13331334        if sImpersonation == g_ksGadgetImpersonationTest:
    1334             fRc = self.oUtsSession.syncGadgetCreate(g_kiGadgetTypeTest, g_kiGadgetAccessUsbIp);
     1335            fDone = self.oUtsSession.syncGadgetCreate(g_kiGadgetTypeTest, g_kiGadgetAccessUsbIp);
     1336            if fDone is True and self.oUtsSession.isSuccess():
     1337                # Get the gadget ID.
     1338                _, _, abPayload = self.oUtsSession.getLastReply();
     1339
     1340                fRc = True;
     1341                self.idGadget = getU32(abPayload, 16);
    13351342        else:
    13361343            reporter.log('Invalid or unsupported impersonation');
     
    13881395        fRc = True;
    13891396
    1390         self._clearImpersonation();
     1397        self.clearImpersonation();
    13911398        if self.oUtsSession is not None:
    13921399            fRc = self.oUtsSession.syncDisconnect();
  • trunk/src/VBox/ValidationKit/utils/usb/UsbTest.cpp

    r58930 r60522  
    3030*   Header Files                                                                                                                 *
    3131*********************************************************************************************************************************/
     32#include <iprt/dir.h>
    3233#include <iprt/err.h>
     34#include <iprt/file.h>
    3335#include <iprt/getopt.h>
    3436#include <iprt/path.h>
     
    3840#include <iprt/string.h>
    3941#include <iprt/test.h>
    40 #include <iprt/file.h>
    4142
    4243#include <unistd.h>
     
    273274     * Assumption is that the path looks like /dev/bus/usb/%3d/%3d.
    274275     */
    275     uint8_t uBus = 1;
    276     bool fBusExists = false;
    277     char aszDevPath[64];
    278 
    279     RT_ZERO(aszDevPath);
    280 
    281     do
     276    char *pszDevPath = NULL;
     277
     278    PRTDIR pDirUsb = NULL;
     279    int rc = RTDirOpen(&pDirUsb, "/dev/bus/usb");
     280    if (RT_SUCCESS(rc))
    282281    {
    283         RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d", uBus);
    284 
    285         fBusExists = RTPathExists(aszDevPath);
    286 
    287         if (fBusExists)
     282        do
    288283        {
    289             /* Check every device. */
    290             bool fDevExists = false;
    291             uint8_t uDev = 1;
    292 
    293             do
     284            RTDIRENTRY DirUsbBus;
     285            rc = RTDirRead(pDirUsb, &DirUsbBus, NULL);
     286            if (RT_SUCCESS(rc))
    294287            {
    295                 RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d/%03d", uBus, uDev);
    296 
    297                 fDevExists = RTPathExists(aszDevPath);
    298 
    299                 if (fDevExists)
     288                char aszPath[RTPATH_MAX + 1];
     289                RTStrPrintf(&aszPath[0], RT_ELEMENTS(aszPath), "/dev/bus/usb/%s", DirUsbBus.szName);
     290
     291                PRTDIR pDirUsbBus = NULL;
     292                rc = RTDirOpen(&pDirUsbBus, &aszPath[0]);
     293                if (RT_SUCCESS(rc))
    300294                {
    301                     RTFILE hFileDev;
    302                     int rc = RTFileOpen(&hFileDev, aszDevPath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
    303                     if (RT_SUCCESS(rc))
     295                    do
    304296                    {
    305                         USBDEVDESC DevDesc;
    306 
    307                         rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL);
    308                         RTFileClose(hFileDev);
    309 
    310                         if (   RT_SUCCESS(rc)
    311                             && DevDesc.idVendor == 0x0525
    312                             && DevDesc.idProduct == 0xa4a0)
    313                             return RTStrDup(aszDevPath);
    314                     }
     297                        RTDIRENTRY DirUsbDev;
     298                        rc = RTDirRead(pDirUsbBus, &DirUsbDev, NULL);
     299                        if (RT_SUCCESS(rc))
     300                        {
     301                            char aszPathDev[RTPATH_MAX + 1];
     302                            RTStrPrintf(&aszPathDev[0], RT_ELEMENTS(aszPathDev), "/dev/bus/usb/%s/%s",
     303                                        DirUsbBus.szName, DirUsbDev.szName);
     304
     305                            RTFILE hFileDev;
     306                            rc = RTFileOpen(&hFileDev, aszPathDev, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE);
     307                            if (RT_SUCCESS(rc))
     308                            {
     309                                USBDEVDESC DevDesc;
     310
     311                                rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL);
     312                                RTFileClose(hFileDev);
     313
     314                                if (   RT_SUCCESS(rc)
     315                                    && DevDesc.idVendor == 0x0525
     316                                    && DevDesc.idProduct == 0xa4a0)
     317                                    pszDevPath = RTStrDup(aszPathDev);
     318                            }
     319
     320                            rc = VINF_SUCCESS;
     321                        }
     322                        else if (rc != VERR_NO_MORE_FILES)
     323                            rc = VINF_SUCCESS;
     324
     325                    } while (   RT_SUCCESS(rc)
     326                             && !pszDevPath);
     327
     328                    rc = VINF_SUCCESS;
     329                    RTDirClose(pDirUsbBus);
    315330                }
    316 
    317                 uDev++;
    318             } while (fDevExists);
    319         }
    320 
    321         uBus++;
    322     } while (fBusExists);
    323 
    324     return NULL;
     331            }
     332            else if (rc != VERR_NO_MORE_FILES)
     333                rc = VINF_SUCCESS;
     334        } while (   RT_SUCCESS(rc)
     335                 && !pszDevPath);
     336
     337        RTDirClose(pDirUsb);
     338    }
     339
     340    return pszDevPath;
    325341}
    326342
  • trunk/src/VBox/ValidationKit/utils/usb/UsbTestService.cpp

    r60517 r60522  
    832832        rc = utsDoGadgetCreate(pClient, pPktHdr);
    833833    else if (utsIsSameOpcode(pPktHdr, UTSPKT_OPCODE_GADGET_DESTROY))
    834         rc = utsDoGadgetCreate(pClient, pPktHdr);
     834        rc = utsDoGadgetDestroy(pClient, pPktHdr);
    835835    else if (utsIsSameOpcode(pPktHdr, UTSPKT_OPCODE_GADGET_CONNECT))
    836836        rc = utsDoGadgetConnect(pClient, pPktHdr);
  • trunk/src/VBox/ValidationKit/utils/usb/UsbTestServiceGadgetClassTest.cpp

    r60517 r60522  
    3232#include <iprt/string.h>
    3333#include <iprt/symlink.h>
     34#include <iprt/thread.h>
    3435#include <iprt/types.h>
    3536
     
    359360                    if (RT_SUCCESS(rc))
    360361                        rc = RTLinuxSysFsWriteStrFile(pClass->pszUdc, 0, NULL, "%s/UDC", pClass->pszGadgetPath);
     362                    if (RT_SUCCESS(rc))
     363                        RTThreadSleep(500); /* Fudge: Sleep a bit to give the device a chance to appear on the host so binding succeeds. */
    361364                }
    362365            }
     
    406409static DECLCALLBACK(int) utsGadgetClassTestConnect(PUTSGADGETCLASSINT pClass)
    407410{
    408     return RTLinuxSysFsWriteStrFile("connect", 0, NULL, "/sys/class/udc/%s/soft_connect", pClass->pszUdc);
     411    int rc = RTLinuxSysFsWriteStrFile("connect", 0, NULL, "/sys/class/udc/%s/soft_connect", pClass->pszUdc);
     412    if (RT_SUCCESS(rc))
     413        RTThreadSleep(500); /* Fudge: Sleep a bit to give the device a chance to appear on the host so binding succeeds. */
     414
     415    return rc;
    409416}
    410417
  • trunk/src/VBox/ValidationKit/utils/usb/UsbTestServicePlatform-linux.cpp

    r60518 r60522  
    178178                                        g_paDummyHcd[idxHcdCur].uBusId      = uBusId;
    179179                                        g_paDummyHcd[idxHcdCur].fAvailable  = true;
     180                                        idxHcdCur++;
    180181                                    }
    181182                                }
     
    300301        pszIdx++;
    301302        uint32_t idxHcd = 0;
    302         rc = RTStrToUInt32Ex(pszUdc, NULL, 10, &idxHcd);
     303        rc = RTStrToUInt32Ex(pszIdx, NULL, 10, &idxHcd);
    303304        if (RT_SUCCESS(rc))
    304305        {
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