Changeset 36993 in vbox for trunk/src/VBox/Main/src-server/linux
- Timestamp:
- May 6, 2011 9:53:21 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 71604
- Location:
- trunk/src/VBox/Main/src-server/linux
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/linux/USBGetDevices.cpp
r36958 r36993 1390 1390 } 1391 1391 1392 #ifdef UNIT_TEST 1393 /* Set up mock functions for USBProxyLinuxCheckDeviceRoot - here dlsym and close 1394 * for the inotify presence check. */ 1395 static int testInotifyInitGood(void) { return 0; } 1396 static int testInotifyInitBad(void) { return -1; } 1397 static bool s_fHaveInotifyLibC = true; 1398 static bool s_fHaveInotifyKernel = true; 1399 1400 static 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 1411 void 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 1392 1420 /** Is inotify available and working on this system? This is a requirement 1393 1421 * for using USB with sysfs */ … … 1406 1434 } 1407 1435 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. */ 1443 static const char **s_pacszUsbfsDeviceAddresses = NULL; 1444 1445 static 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 1469 void 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. */ 1476 static const char **s_pacszAccessibleFiles = NULL; 1477 1478 static 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 1488 void TestUSBSetAccessibleFiles(const char **pacszAccessibleFiles) 1489 { 1490 s_pacszAccessibleFiles = pacszAccessibleFiles; 1491 } 1492 #endif 1493 1408 1494 bool USBProxyLinuxCheckDeviceRoot(const char *pcszRoot, bool fIsDeviceNodes) 1409 1495 { … … 1431 1517 } 1432 1518 1519 #ifdef UNIT_TEST 1520 # undef getDevicesFromUsbfs 1521 # undef access 1522 #endif 1433 1523 1434 1524 PUSBDEVICE USBProxyLinuxGetDevices(const char *pcszDevicesRoot, -
trunk/src/VBox/Main/src-server/linux/USBProxyServiceLinux.cpp
r36964 r36993 63 63 mWakeupPipeW(NIL_RTFILE), mUsingUsbfsDevices(true /* see init */), 64 64 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 65 71 { 66 72 LogFlowThisFunc(("aHost=%p\n", aHost)); 67 73 } 68 74 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 69 97 70 98 /** … … 131 159 mUsingUsbfsDevices = !fUseSysfs; 132 160 mDevicesRoot = pcszUsbRoot; 161 #ifndef UNIT_TEST /* Hack for now */ 133 162 int rc = mUsingUsbfsDevices ? initUsbfs() : initSysfs(); 163 #else 164 int rc = mrcTestMethodInitResult; 165 #endif 134 166 /* For the day when we have VBoxSVC release logging... */ 135 167 LogRel((RT_SUCCESS(rc) ? "Successfully initialised host USB using %s\n" … … 145 177 } 146 178 179 #ifdef UNIT_TEST 180 # undef RTEnvGet 181 # undef USBProxyLinuxCheckDeviceRoot 182 # undef RTDirExists 183 # undef RTFileExists 184 #endif 147 185 148 186 /**
Note:
See TracChangeset
for help on using the changeset viewer.