VirtualBox

Changeset 36993 in vbox


Ignore:
Timestamp:
May 6, 2011 9:53:21 PM (14 years ago)
Author:
vboxsync
Message:

Main/linux/USB: unit tests for the code changed in r71554 and r71557

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/USBGetDevices.h

    r36958 r36993  
    8484                                         bool fIsDeviceNodes);
    8585
     86#ifdef UNIT_TEST
     87/**
     88 * Specify the list of devices that will appear to be available through
     89 * usbfs during unit testing (of USBProxyLinuxGetDevices)
     90 * @param  pacszDeviceAddresses  NULL terminated array of usbfs device addresses
     91 */
     92extern void TestUSBSetAvailableUsbfsDevices(const char **pacszDeviceAddresses);
     93/**
     94 * Specify the list of files that access will report as accessible (at present
     95 * we only do accessible or not accessible) during unit testing (of
     96 * USBProxyLinuxGetDevices)
     97 * @param  pacszAccessibleFiles  NULL terminated array of file paths to be
     98 *                               reported accessible
     99 */
     100extern void TestUSBSetAccessibleFiles(const char **pacszAccessibleFiles);
     101#endif
     102
    86103/**
    87104 * Get the list of USB devices supported by the system.  Should be freed using
  • trunk/src/VBox/Main/include/USBProxyService.h

    r36418 r36993  
    211211    virtual int releaseDevice(HostUSBDevice *aDevice);
    212212
    213 protected:
    214 #ifdef TESTCASE
    215     virtual
    216 #endif
     213#  ifdef UNIT_TEST
     214    /* Functions for setting our unit test mock functions.  Not quite sure if
     215     * it is good form to mix test and production code like this, but it seems
     216     * cleaner to me than tying the unit test to implementation details of the
     217     * class. */
     218    /** Select which access methods will be available to the @a init method
     219     * during unit testing, and (hack!) what return code it will see from
     220     * the access method-specific initialisation. */
     221    void testSetupInit(const char *pcszUsbfsRoot, bool fUsbfsAccessible,
     222                       const char *pcszDevicesRoot, bool fDevicesAccessible,
     223                       int rcMethodInitResult)
     224    {
     225        mpcszTestUsbfsRoot = pcszUsbfsRoot;
     226        mfTestUsbfsAccessible = fUsbfsAccessible;
     227        mpcszTestDevicesRoot = pcszDevicesRoot;
     228        mfTestDevicesAccessible = fDevicesAccessible;
     229        mrcTestMethodInitResult = rcMethodInitResult;
     230    }
     231    /** Specify the environment that the @a init method will see during unit
     232     * testing. */
     233    void testSetEnv(const char *pcszEnvUsb, const char *pcszEnvUsbRoot)
     234    {
     235        mpcszTestEnvUsb = pcszEnvUsb;
     236        mpcszTestEnvUsbRoot = pcszEnvUsbRoot;
     237    }
     238    bool testGetUsingUsbfs(void) { return mUsingUsbfsDevices; }
     239    const char *testGetDevicesRoot(void) { return mDevicesRoot.c_str(); }
     240#  endif
     241
     242protected:
    217243    int initUsbfs(void);
    218 #ifdef TESTCASE
    219     virtual
    220 #endif
    221244    int initSysfs(void);
    222245    void doUsbfsCleanupAsNeeded(void);
     
    248271    VBoxMainHotplugWaiter *mpWaiter;
    249272#  endif
     273#  ifdef UNIT_TEST
     274    /** The path we pretend the usbfs root is located at, or NULL. */
     275    const char *mpcszTestUsbfsRoot;
     276    /** Should usbfs be accessible to the current user? */
     277    bool mfTestUsbfsAccessible;
     278    /** The path we pretend the device node tree root is located at, or NULL. */
     279    const char *mpcszTestDevicesRoot;
     280    /** Should the device node tree be accessible to the current user? */
     281    bool mfTestDevicesAccessible;
     282    /** The result of the usbfs/inotify-specific init */
     283    int mrcTestMethodInitResult;
     284    /** The value of the VBOX_USB environment variable. */
     285    const char *mpcszTestEnvUsb;
     286    /** The value of the VBOX_USB_ROOT environment variable. */
     287    const char *mpcszTestEnvUsbRoot;
     288#  endif
    250289};
    251290# endif /* RT_OS_LINUX */
  • trunk/src/VBox/Main/src-server/USBProxyService.cpp

    r35368 r36993  
    2525#include "Logging.h"
    2626
     27#include <VBox/com/array.h>
    2728#include <VBox/err.h>
    2829#include <iprt/asm.h>
  • trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp

    r36958 r36993  
    13901390}
    13911391
     1392#ifdef UNIT_TEST
     1393/* Set up mock functions for USBProxyLinuxCheckDeviceRoot - here dlsym and close
     1394 * for the inotify presence check. */
     1395static int testInotifyInitGood(void) { return 0; }
     1396static int testInotifyInitBad(void) { return -1; }
     1397static bool s_fHaveInotifyLibC = true;
     1398static bool s_fHaveInotifyKernel = true;
     1399
     1400static void *testDLSym(void *handle, const char *symbol)
     1401{
     1402    Assert(handle == RTLD_DEFAULT);
     1403    Assert(!RTStrCmp(symbol, "inotify_init"));
     1404    if (!s_fHaveInotifyLibC)
     1405        return NULL;
     1406    if (s_fHaveInotifyKernel)
     1407        return (void *)testInotifyInitGood;
     1408    return (void *)testInotifyInitBad;
     1409}
     1410
     1411void TestUSBSetInotifyAvailable(bool fHaveInotifyLibC, bool fHaveInotifyKernel)
     1412{
     1413    s_fHaveInotifyLibC = fHaveInotifyLibC;
     1414    s_fHaveInotifyKernel = fHaveInotifyKernel;
     1415}
     1416# define dlsym testDLSym
     1417# define close(a) do {} while(0)
     1418#endif
     1419
    13921420/** Is inotify available and working on this system?  This is a requirement
    13931421 * for using USB with sysfs */
     
    14061434}
    14071435
     1436#ifdef UNIT_TEST
     1437# undef dlsym
     1438# undef close
     1439#endif
     1440
     1441#ifdef UNIT_TEST
     1442/** Unit test list of usbfs addresses of connected devices. */
     1443static const char **s_pacszUsbfsDeviceAddresses = NULL;
     1444
     1445static PUSBDEVICE testGetUsbfsDevices(const char *pcszUsbfsRoot, bool testfs)
     1446{
     1447    const char **pcsz;
     1448    PUSBDEVICE pList = NULL, pTail = NULL;
     1449    for (pcsz = s_pacszUsbfsDeviceAddresses; pcsz && *pcsz; ++pcsz)
     1450    {
     1451        PUSBDEVICE pNext = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE));
     1452        if (pNext)
     1453            pNext->pszAddress = RTStrDup(*pcsz);
     1454        if (!pNext || !pNext->pszAddress)
     1455        {
     1456            deviceListFree(&pList);
     1457            return NULL;
     1458        }
     1459        if (pTail)
     1460            pTail->pNext = pNext;
     1461        else
     1462            pList = pNext;
     1463        pTail = pNext;
     1464    }
     1465    return pList;
     1466}
     1467# define getDevicesFromUsbfs testGetUsbfsDevices
     1468
     1469void TestUSBSetAvailableUsbfsDevices(const char **pacszDeviceAddresses)
     1470{
     1471    s_pacszUsbfsDeviceAddresses = pacszDeviceAddresses;
     1472}
     1473
     1474/** Unit test list of files reported as accessible by access(3).  We only do
     1475 * accessible or not accessible. */
     1476static const char **s_pacszAccessibleFiles = NULL;
     1477
     1478static int testAccess(const char *pcszPath, int mode)
     1479{
     1480    const char **pcsz;
     1481    for (pcsz = s_pacszAccessibleFiles; pcsz && *pcsz; ++pcsz)
     1482        if (!RTStrCmp(pcszPath, *pcsz))
     1483            return 0;
     1484    return -1;
     1485}
     1486# define access testAccess
     1487
     1488void TestUSBSetAccessibleFiles(const char **pacszAccessibleFiles)
     1489{
     1490    s_pacszAccessibleFiles = pacszAccessibleFiles;
     1491}
     1492#endif
     1493
    14081494bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, bool fIsDeviceNodes)
    14091495{
     
    14311517}
    14321518
     1519#ifdef UNIT_TEST
     1520# undef getDevicesFromUsbfs
     1521# undef access
     1522#endif
    14331523
    14341524PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot,
  • trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp

    r36964 r36993  
    6363      mWakeupPipeW(NIL_RTFILE), mUsingUsbfsDevices(true /* see init */),
    6464      mUdevPolls(0), mpWaiter(NULL)
     65#ifdef UNIT_TEST
     66      , mpcszTestUsbfsRoot(NULL), mfTestUsbfsAccessible(false),
     67      mpcszTestDevicesRoot(NULL), mfTestDevicesAccessible(false),
     68      mrcTestMethodInitResult(VINF_SUCCESS), mpcszTestEnvUsb(NULL),
     69      mpcszTestEnvUsbRoot(NULL)
     70#endif
    6571{
    6672    LogFlowThisFunc(("aHost=%p\n", aHost));
    6773}
    6874
     75#ifdef UNIT_TEST
     76/* For testing we redefine anything that accesses the outside world to
     77 * return test values. */
     78# define RTEnvGet(a) \
     79    (  !RTStrCmp(a, "VBOX_USB") ? mpcszTestEnvUsb \
     80     : !RTStrCmp(a, "VBOX_USB_ROOT") ? mpcszTestEnvUsbRoot \
     81     : NULL)
     82# define USBProxyLinuxCheckDeviceRoot(pcszPath, fUseNodes) \
     83    (   ((fUseNodes) && mfTestDevicesAccessible \
     84                     && !RTStrCmp(pcszPath, mpcszTestDevicesRoot)) \
     85     || (!(fUseNodes) && mfTestUsbfsAccessible \
     86                      && !RTStrCmp(pcszPath, mpcszTestUsbfsRoot)))
     87# define RTDirExists(pcszDir) \
     88    (   (pcszDir) \
     89     && (   !RTStrCmp(pcszDir, mpcszTestDevicesRoot) \
     90         || !RTStrCmp(pcszDir, mpcszTestUsbfsRoot)))
     91# define RTFileExists(pcszFile) \
     92    (   (pcszFile) \
     93     && mpcszTestUsbfsRoot \
     94     && !RTStrNCmp(pcszFile, mpcszTestUsbfsRoot, strlen(mpcszTestUsbfsRoot)) \
     95     && !RTStrCmp(pcszFile + strlen(mpcszTestUsbfsRoot), "/devices"))
     96#endif
    6997
    7098/**
     
    131159        mUsingUsbfsDevices = !fUseSysfs;
    132160        mDevicesRoot = pcszUsbRoot;
     161#ifndef UNIT_TEST /* Hack for now */
    133162        int rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs();
     163#else
     164        int rc = mrcTestMethodInitResult;
     165#endif
    134166        /* For the day when we have VBoxSVC release logging... */
    135167        LogRel((RT_SUCCESS(rc) ? "Successfully initialised host USB using %s\n"
     
    145177}
    146178
     179#ifdef UNIT_TEST
     180# undef RTEnvGet
     181# undef USBProxyLinuxCheckDeviceRoot
     182# undef RTDirExists
     183# undef RTFileExists
     184#endif
    147185
    148186/**
  • trunk/src/VBox/Main/testcase/Makefile.kmk

    r36420 r36993  
    172172tstUSBProxyLinux_SOURCES   = \
    173173        tstUSBProxyLinux.cpp \
    174         ../src-server/linux/USBProxyServiceLinux.cpp
     174        ../src-server/linux/USBProxyServiceLinux.cpp \
     175        ../src-server/linux/USBGetDevices.cpp
    175176tstUSBProxyLinux_INCS      = \
    176177        . \
     
    180181        $(VBOX_PATH_SDK)/bindings/xpcom/include/xpcom
    181182tstUSBProxyLinux_DEFS      = \
    182         TESTCASE \
     183        UNIT_TEST \
     184        VBOX_WITH_USB \
    183185        VBOX_USB_WITH_SYSFS \
    184         VBOX_WITH_SYSFS_BY_DEFAULT \
    185186        VBOX_WITH_XPCOM
    186187tstUSBProxyLinux_DEPS     = \
    187188        $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h
     189tstUSBProxyLinux_LIBS     += \
     190        $(PATH_OUT)/lib/USBLib.a
    188191
    189192
  • trunk/src/VBox/Main/testcase/tstUSBProxyLinux.cpp

    r36958 r36993  
    2323#include "USBGetDevices.h"
    2424
     25#include <VBox/err.h>
    2526#include <iprt/assert.h>
    26 #include <iprt/err.h>
    2727#include <iprt/env.h>
     28#include <iprt/string.h>
    2829#include <iprt/test.h>
    2930
     
    6263}
    6364
    64 static const char *s_pcszDeviceRoot = "";
    65 static bool s_fIsDeviceNodes = false;
    66 
    67 bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot,
    68                                   bool fIsDeviceNodes)
    69 {
    70     return (   (!strcmp(s_pcszDeviceRoot, pcszRoot))
    71             && (s_fIsDeviceNodes == fIsDeviceNodes));
    72 }
    73 
    74 static struct
    75 {
     65int USBProxyService::getLastError(void)
     66{
     67    return mLastError;
     68}
     69
     70void SysFreeString(BSTR bstr)
     71{
     72    Assert(0);
     73}
     74
     75static struct
     76{
     77    const char *pcszEnvUsb;
     78    const char *pcszEnvUsbRoot;
    7679    const char *pcszDevicesRoot;
    77     bool fUseSysfs;
    78 } s_getDevices;
    79 
    80 PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot,
    81                                    bool fUseSysfs)
    82 {
    83     s_getDevices.pcszDevicesRoot = pcszDevicesRoot;
    84     s_getDevices.fUseSysfs = fUseSysfs;
    85     return NULL;
    86 }
    87 
    88 void SysFreeString(BSTR bstr)
    89 {
    90     Assert(0);
    91 }
    92 
    93 /*** END STUBS ***/
    94 
    95 class tstUSBProxyLinux : public USBProxyServiceLinux
    96 {
    97 protected:
    98     virtual int initUsbfs(void) { return VINF_SUCCESS; }
    99     virtual int initSysfs(void) { return VINF_SUCCESS; }
    100 public:
    101     tstUSBProxyLinux(void) : USBProxyServiceLinux(NULL) {}
    102     PUSBDEVICE getDevices(void)
    103     {
    104         return USBProxyServiceLinux::getDevices();
    105     }
     80    bool fDevicesAccessible;
     81    const char *pcszUsbfsRoot;
     82    bool fUsbfsAccessible;
     83    int rcMethodInit;
     84    int rcExpected;
     85    const char *pcszDevicesRootExpected;
     86    bool fUsingUsbfsExpected;
     87} s_testEnvironment[] =
     88{
     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/usbvbox", 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 }
    106103};
    107104
    108 static struct
    109 {
    110     const char *pcszVBOX_USB;
    111     const char *pcszVBOX_USB_ROOT;
    112     const char *pcszReturnedRoot;
    113     bool fReturnedUseSysfs;
    114     bool fRequestedUseSysfs;
    115     const char *pcszFinalRoot;
    116     bool fFinalUseSysfs;
    117 } s_testEnvironment[] =
    118 {
    119     { "sysfs", "/dev/bus/usb", "/proc/bus/usb", false, true, "/dev/bus/usb", true },
    120     { "sysfs", "/dev/bus/usb", "/dev/vboxusb", true, true, "/dev/bus/usb", true },
    121     { "sysfs", NULL, "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    122     { "sysfs", NULL, "/dev/vboxusb", true, true, "/dev/vboxusb", true },
    123     { "usbfs", "/dev/bus/usb", "/proc/bus/usb", false, false, "/dev/bus/usb", false },
    124     { "usbfs", "/dev/bus/usb", "/dev/vboxusb", true, false, "/dev/bus/usb", false },
    125     { "usbfs", NULL, "/proc/bus/usb", false, false, "/proc/bus/usb", false },
    126     { "usbfs", NULL, "/dev/vboxusb", true, false, "/dev/vboxusb", true },
    127     { "nofs", "/dev/bus/usb", "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    128     { "nofs", "/dev/bus/usb", "/dev/vboxusb", true, true, "/dev/vboxusb", true },
    129     { "nofs", NULL, "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    130     { "nofs", NULL, "/dev/vboxusb", true, true, "/dev/vboxusb", true },
    131     { "", "/dev/bus/usb", "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    132     { "", "/dev/bus/usb", "/dev/vboxusb", true, true, "/dev/vboxusb", true },
    133     { "", NULL, "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    134     { "", NULL, "/dev/vboxusb", true, true, "/dev/vboxusb", true },
    135     { NULL, "/dev/bus/usb", "/proc/bus/usb", false, true, "/proc/bus/usb", false },
    136     { NULL, "/dev/bus/usb", "/dev/vboxusb", true, true, "/dev/vboxusb", true }
    137 };
    138 
    139 /** @note Fiddling with the real environment for this is not nice, in my
    140  * opinion at least. */
    141 static void testEnvironment(RTTEST hTest)
    142 {
    143     RTTestSub(hTest, "Testing environment variable handling");
     105static void testInit(RTTEST hTest)
     106{
     107    RTTestSub(hTest, "Testing USBProxyServiceLinux initialisation");
    144108    for (unsigned i = 0; i < RT_ELEMENTS(s_testEnvironment); ++i)
    145109    {
    146         tstUSBProxyLinux test;
    147         if (s_testEnvironment[i].pcszVBOX_USB)
    148             RTEnvSet("VBOX_USB", s_testEnvironment[i].pcszVBOX_USB);
    149         else
    150             RTEnvUnset("VBOX_USB");
    151         if (s_testEnvironment[i].pcszVBOX_USB_ROOT)
    152             RTEnvSet("VBOX_USB_ROOT",
    153                      s_testEnvironment[i].pcszVBOX_USB_ROOT);
    154         else
    155             RTEnvUnset("VBOX_USB_ROOT");
    156         s_pcszDeviceRoot = s_testEnvironment[i].pcszReturnedRoot;
    157         s_fIsDeviceNodes = s_testEnvironment[i].fReturnedUseSysfs;
    158         RTTESTI_CHECK(test.init() == S_OK);
    159         test.getDevices();
    160         RTTESTI_CHECK_MSG(!strcmp(s_getDevices.pcszDevicesRoot,
    161                           s_testEnvironment[i].pcszFinalRoot),
    162                           ("i=%u: %s, %s\n", i, s_getDevices.pcszDevicesRoot,
    163                           s_testEnvironment[i].pcszFinalRoot));
    164         RTTESTI_CHECK_MSG(   s_getDevices.fUseSysfs
    165                           == s_testEnvironment[i].fFinalUseSysfs,
    166                           ("i=%u, %d, %d\n", i, s_getDevices.fUseSysfs,
    167                           s_testEnvironment[i].fFinalUseSysfs));
     110        USBProxyServiceLinux test(NULL);
     111        test.testSetEnv(s_testEnvironment[i].pcszEnvUsb,
     112                        s_testEnvironment[i].pcszEnvUsbRoot);
     113        test.testSetupInit(s_testEnvironment[i].pcszUsbfsRoot,
     114                           s_testEnvironment[i].fUsbfsAccessible,
     115                           s_testEnvironment[i].pcszDevicesRoot,
     116                           s_testEnvironment[i].fDevicesAccessible,
     117                           s_testEnvironment[i].rcMethodInit);
     118        HRESULT hrc = test.init();
     119        RTTESTI_CHECK_MSG(hrc == S_OK,
     120                           ("init() returned 0x%x on line %i!\n", hrc, i));
     121        int rc = test.getLastError();
     122        RTTESTI_CHECK_MSG(rc == s_testEnvironment[i].rcExpected,
     123                          ("getLastError() returned %Rrc on line %i instead of %Rrc!\n",
     124                           rc, i, s_testEnvironment[i].rcExpected));
     125        const char *pcszDevicesRoot = test.testGetDevicesRoot();
     126        RTTESTI_CHECK_MSG(!RTStrCmp(pcszDevicesRoot,
     127                               s_testEnvironment[i].pcszDevicesRootExpected),
     128                          ("testGetDevicesRoot() returned %s on line %i instead of %s!\n",
     129                           pcszDevicesRoot, i,
     130                           s_testEnvironment[i].pcszDevicesRootExpected));
     131        bool fUsingUsbfs = test.testGetUsingUsbfs();
     132        RTTESTI_CHECK_MSG(   fUsingUsbfs
     133                          == s_testEnvironment[i].fUsingUsbfsExpected,
     134                          ("testGetUsingUsbfs() returned %RTbool on line %i instead of %RTbool!\n",
     135                           fUsingUsbfs, i,
     136                           s_testEnvironment[i].fUsingUsbfsExpected));
     137    }
     138}
     139
     140static struct
     141{
     142    const char *pacszDeviceAddresses[16];
     143    const char *pacszAccessibleFiles[16];
     144    const char *pcszRoot;
     145    bool fIsDeviceNodes;
     146    bool fAvailableExpected;
     147} s_testCheckDeviceRoot[] =
     148{
     149    { { NULL }, { "/dev/vboxusb" }, "/dev/vboxusb", true, true },
     150    { { NULL }, { NULL }, "/dev/vboxusb", true, false },
     151    { { NULL }, { NULL }, "/proc/bus/usb", false, true },
     152    { { "/proc/bus/usb/001/001" }, { NULL }, "/proc/bus/usb", false, false },
     153    { { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
     154      { "/proc/bus/usb/001/001" }, "/proc/bus/usb", false, false },
     155    { { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
     156      { "/proc/bus/usb/001/001", "/proc/bus/usb/002/002" },
     157      "/proc/bus/usb", false, true }
     158};
     159
     160static void testCheckDeviceRoot(RTTEST hTest)
     161{
     162    RTTestSub(hTest, "Testing the USBProxyLinuxCheckDeviceRoot API");
     163    for (unsigned i = 0; i < RT_ELEMENTS(s_testCheckDeviceRoot); ++i)
     164    {
     165        TestUSBSetAvailableUsbfsDevices(s_testCheckDeviceRoot[i]
     166                                                .pacszDeviceAddresses);
     167        TestUSBSetAccessibleFiles(s_testCheckDeviceRoot[i]
     168                                                .pacszAccessibleFiles);
     169        bool fAvailable = USBProxyLinuxCheckDeviceRoot
     170                                  (s_testCheckDeviceRoot[i].pcszRoot,
     171                                   s_testCheckDeviceRoot[i].fIsDeviceNodes);
     172        RTTESTI_CHECK_MSG(   fAvailable
     173                          == s_testCheckDeviceRoot[i].fAvailableExpected,
     174                           ("USBProxyLinuxCheckDeviceRoot() returned %RTbool on line %i instead of %RTbool!\n",
     175                            fAvailable, i,
     176                            s_testCheckDeviceRoot[i].fAvailableExpected));
    168177    }
    169178}
     
    183192     * Run the tests.
    184193     */
    185     testEnvironment(hTest);
     194    testInit(hTest);
     195    testCheckDeviceRoot(hTest);
    186196
    187197    /*
     
    190200    return RTTestSummaryAndDestroy(hTest);
    191201}
    192 
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