VirtualBox

Changeset 36995 in vbox


Ignore:
Timestamp:
May 6, 2011 10:49:41 PM (14 years ago)
Author:
vboxsync
Message:

Main/linux/usb: more readable test code

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp

    r36994 r36995  
    114114     * available we fall back to USBFS.
    115115     * In the event of both failing, an appropriate error will be returned.
     116     * The user may also specify a method and root using the VBOX_USB and
     117     * VBOX_USB_ROOT environment variables.  In this case we don't check
     118     * the root they provide for validity.
    116119     */
    117120    bool fUsbfsChosen = false, fSysfsChosen = false;
  • trunk/src/VBox/Main/testcase/tstUSBProxyLinux.cpp

    r36994 r36995  
    8282    bool fUsbfsAccessible;
    8383    int rcMethodInit;
    84     int rcExpected;
    8584    const char *pcszDevicesRootExpected;
    8685    bool fUsingUsbfsExpected;
     86    int rcExpected;
    8787} s_testEnvironment[] =
    8888{
    89     { "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", false },
    90     { "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", false },
    91     { "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", false },
    92     { "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", false },
    93     { "sysfs", NULL, "/dev/vboxusb", true, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/vboxusb", false },
    94     { "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", true },
    95     { "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", true },
    96     { "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, VINF_SUCCESS, "/dev/bus/usb", true },
    97     { "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/bus/usb", true },
    98     { "usbfs", NULL, NULL, false, "/proc/bus/usb", true, VINF_SUCCESS, VINF_SUCCESS, "/proc/bus/usb", true },
    99     { NULL, NULL, "/dev/vboxusb", false, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_VUSB_USB_DEVICE_PERMISSION, "", true },
    100     { NULL, NULL, "/dev/vboxusb", true, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_NO_MEMORY, "/dev/vboxusb", false },
    101     { NULL, NULL, NULL, false, "/proc/bus/usb", false, VERR_NO_MEMORY, VERR_VUSB_USBFS_PERMISSION, "", true },
    102     { NULL, NULL, NULL, false, "/proc/bus/usb", true, VERR_NO_MEMORY, VERR_NO_MEMORY, "/proc/bus/usb", true }
     89    /* "sysfs" and root in the environment */
     90    { "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, "/dev/bus/usb", false, VINF_SUCCESS },
     91    /* "sysfs" and root in the environment, method-specific init failed */
     92    { "sysfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, "/dev/bus/usb", false, VERR_NO_MEMORY },
     93    /* "sysfs" and bad root in the environment (should succeed as we don't
     94     * do checks if the user specifies everything) */
     95    { "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, "/dev/bus/usb", false, VINF_SUCCESS },
     96    /* "sysfs" and bad root in the environment, method-specific init failed */
     97    { "sysfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, "/dev/bus/usb", false, VERR_NO_MEMORY },
     98    /* "sysfs" and no root in the environment */
     99    { "sysfs", NULL, "/dev/vboxusb", true, NULL, false, VINF_SUCCESS, "/dev/vboxusb", false, VINF_SUCCESS },
     100    /* "usbfs" and root in the environment */
     101    { "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VINF_SUCCESS, "/dev/bus/usb", true, VINF_SUCCESS },
     102    /* "usbfs" and root in the environment, method-specific init failed */
     103    { "usbfs", "/dev/bus/usb", NULL, false, NULL, false, VERR_NO_MEMORY, "/dev/bus/usb", true, VERR_NO_MEMORY },
     104    /* "usbfs" and bad root in the environment (should succeed as we don't
     105     * do checks if the user specifies everything) */
     106    { "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VINF_SUCCESS, "/dev/bus/usb", true, VINF_SUCCESS },
     107    /* "usbfs" and bad root in the environment, method-specific init failed */
     108    { "usbfs", "/dev/bus/usb", "/dev/usbvbox", false, "/proc/usb/bus", false, VERR_NO_MEMORY, "/dev/bus/usb", true, VERR_NO_MEMORY },
     109    /* "usbfs" and no root in the environment */
     110    { "usbfs", NULL, NULL, false, "/proc/bus/usb", true, VINF_SUCCESS, "/proc/bus/usb", true, VINF_SUCCESS },
     111    /* No environment, sysfs and usbfs available but without access
     112     * permissions. */
     113    { NULL, NULL, "/dev/vboxusb", false, "/proc/bus/usb", false, VERR_NO_MEMORY, "", true, VERR_VUSB_USB_DEVICE_PERMISSION },
     114    /* No environment, sysfs and usbfs available, access permissions for sysfs,
     115     * method-specific init failed. */
     116    { NULL, NULL, "/dev/vboxusb", true, "/proc/bus/usb", false, VERR_NO_MEMORY, "/dev/vboxusb", false, VERR_NO_MEMORY },
     117    /* No environment, usbfs available but without access permissions. */
     118    { NULL, NULL, NULL, false, "/proc/bus/usb", false, VERR_NO_MEMORY, "", true, VERR_VUSB_USBFS_PERMISSION },
     119    /* No environment, usbfs available with access permissions, method-specific
     120     * init failed. */
     121    { NULL, NULL, NULL, false, "/proc/bus/usb", true, VERR_NO_MEMORY, "/proc/bus/usb", true, VERR_NO_MEMORY }
    103122};
    104123
     
    118137        HRESULT hrc = test.init();
    119138        RTTESTI_CHECK_MSG(hrc == S_OK,
    120                            ("init() returned 0x%x on line %i!\n", hrc, i));
     139                           ("init() returned 0x%x (test index %i)!\n", hrc, i));
    121140        int rc = test.getLastError();
    122141        RTTESTI_CHECK_MSG(rc == s_testEnvironment[i].rcExpected,
    123                           ("getLastError() returned %Rrc on line %i instead of %Rrc!\n",
     142                          ("getLastError() returned %Rrc (test index %i) instead of %Rrc!\n",
    124143                           rc, i, s_testEnvironment[i].rcExpected));
    125144        const char *pcszDevicesRoot = test.testGetDevicesRoot();
    126145        RTTESTI_CHECK_MSG(!RTStrCmp(pcszDevicesRoot,
    127146                               s_testEnvironment[i].pcszDevicesRootExpected),
    128                           ("testGetDevicesRoot() returned %s on line %i instead of %s!\n",
     147                          ("testGetDevicesRoot() returned %s (test index %i) instead of %s!\n",
    129148                           pcszDevicesRoot, i,
    130149                           s_testEnvironment[i].pcszDevicesRootExpected));
     
    132151        RTTESTI_CHECK_MSG(   fUsingUsbfs
    133152                          == s_testEnvironment[i].fUsingUsbfsExpected,
    134                           ("testGetUsingUsbfs() returned %RTbool on line %i instead of %RTbool!\n",
     153                          ("testGetUsingUsbfs() returned %RTbool (test index %i) instead of %RTbool!\n",
    135154                           fUsingUsbfs, i,
    136155                           s_testEnvironment[i].fUsingUsbfsExpected));
     
    147166} s_testCheckDeviceRoot[] =
    148167{
     168    /* /dev/vboxusb accessible -> device nodes method available */
    149169    { { NULL }, { "/dev/vboxusb" }, "/dev/vboxusb", true, true },
     170    /* /dev/vboxusb present but not accessible -> device nodes method not
     171     * available */
    150172    { { NULL }, { NULL }, "/dev/vboxusb", true, false },
     173    /* /proc/bus/usb available but empty -> usbfs method available (we can't
     174     * really check in this case) */
    151175    { { NULL }, { NULL }, "/proc/bus/usb", false, true },
     176    /* /proc/bus/usb available, one inaccessible device -> usbfs method not
     177     * available */
    152178    { { "/proc/bus/usb/001/001" }, { NULL }, "/proc/bus/usb", false, false },
     179    /* /proc/bus/usb available, one device of two inaccessible -> usbfs method
     180     * not available */
    153181    { { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
    154182      { "/proc/bus/usb/001/001" }, "/proc/bus/usb", false, false },
     183    /* /proc/bus/usb available, two accessible devices -> usbfs method
     184     * available */
    155185    { { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
    156186      { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
     
    172202        RTTESTI_CHECK_MSG(   fAvailable
    173203                          == s_testCheckDeviceRoot[i].fAvailableExpected,
    174                            ("USBProxyLinuxCheckDeviceRoot() returned %RTbool on line %i instead of %RTbool!\n",
     204                           ("USBProxyLinuxCheckDeviceRoot() returned %RTbool (test index %i) instead of %RTbool!\n",
    175205                            fAvailable, i,
    176206                            s_testCheckDeviceRoot[i].fAvailableExpected));
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