VirtualBox

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/utils/usb
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • 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.

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