Changeset 15401 in vbox for trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
- Timestamp:
- Dec 12, 2008 10:05:34 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 40850
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp
r14991 r15401 1 1 /* $Id$ */ 2 3 2 /** @file 4 3 * 5 * Test executable for quickly excercising/debugging the hal-based Linux USB4 * Test executable for quickly excercising/debugging the Linux host hardware 6 5 * bits. 7 6 */ … … 10 9 * Copyright (C) 2008 Sun Microsystems, Inc. 11 10 * 12 * Sun Microsystems, Inc. confidential 13 * All rights reserved 11 * This file is part of VirtualBox Open Source Edition (OSE), as 12 * available from http://www.virtualbox.org. This file is free software; 13 * you can redistribute it and/or modify it under the terms of the GNU 14 * General Public License (GPL) as published by the Free Software 15 * Foundation, in version 2 as it comes in the "COPYING" file of the 16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the 17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 18 * 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa 20 * Clara, CA 95054 USA or visit http://www.sun.com if you need 21 * additional information or have any questions. 14 22 */ 15 16 #ifdef VBOX_USB_WITH_SYSFS17 # include "tstUSBLinux.h"18 #endif19 23 20 24 #include <HostHardwareLinux.h> … … 23 27 24 28 #include <iprt/initterm.h> 29 #include <iprt/param.h> 25 30 #include <iprt/stream.h> 31 #include <iprt/linux/sysfs.h> 26 32 27 33 #include <iprt/cdefs.h> 28 34 #include <iprt/types.h> 29 35 36 #include <errno.h> 37 #include <string.h> 38 30 39 int main() 31 40 { 32 41 RTR3Init(); 33 #ifdef VBOX_USB_WITH_SYSFS 34 USBProxyServiceLinux service; 35 service.initSysfs(); 36 if (RT_FAILURE(service.getLastError())) 37 { 38 RTPrintf("Failed to initialise USBProxyServiceLinux, error %Rrc\n", 39 service.getLastError()); 40 return 1; 41 } 42 PUSBDEVICE pChain = service.getDevicesFromSysfs(); 43 if (pChain == NULL) 44 RTPrintf("Failed to get any devices from sysfs\n."); 45 else 46 { 47 PUSBDEVICE pNext = pChain; 48 while (pNext != NULL) 49 { 50 RTPrintf("Device: %s (product string)\n", pNext->pszProduct); 51 RTPrintf(" Manufacturer: %s\n", pNext->pszManufacturer); 52 RTPrintf(" Serial number: %s\n", pNext->pszSerialNumber); 53 RTPrintf(" Address: %s\n", pNext->pszAddress); 54 RTPrintf(" Vendor ID: %d\n", pNext->idVendor); 55 RTPrintf(" Product ID: %d\n", pNext->idProduct); 56 RTPrintf(" Revision: %d.%d\n", pNext->bcdDevice >> 8, pNext->bcdDevice & 255); 57 RTPrintf(" USB Version: %d.%d\n", pNext->bcdUSB >> 8, pNext->bcdUSB & 255); 58 RTPrintf(" Device class: %d\n", pNext->bDeviceClass); 59 RTPrintf(" Device subclass: %d\n", pNext->bDeviceSubClass); 60 RTPrintf(" Device protocol: %d\n", pNext->bDeviceProtocol); 61 RTPrintf(" Number of configurations: %d\n", pNext->bNumConfigurations); 62 RTPrintf(" Device state: %s\n", 63 pNext->enmState == USBDEVICESTATE_UNUSED ? "unused" 64 : pNext->enmState == USBDEVICESTATE_USED_BY_HOST_CAPTURABLE ? "used by host" 65 : "unknown" 66 ); 67 RTPrintf(" Device speed: %s\n", 68 pNext->enmSpeed == USBDEVICESPEED_LOW ? "low" 69 : pNext->enmSpeed == USBDEVICESPEED_FULL ? "full" 70 : pNext->enmSpeed == USBDEVICESPEED_HIGH ? "high" 71 : "unknown" 72 ); 73 RTPrintf(" Serial hash: 0x%llx\n", pNext->u64SerialHash); 74 RTPrintf(" Bus number: %d\n", pNext->bBus); 75 RTPrintf(" Port number: %d\n", pNext->bPort); 76 RTPrintf(" Device number: %d\n", pNext->bDevNum); 77 RTPrintf("\n"); 78 pNext = pNext->pNext; 79 } 80 } 81 #endif /* VBOX_USB_WITH_SYSFS */ 42 g_testHostHardwareLinux = true; 43 int rc = VINF_SUCCESS; 82 44 VBoxMainDriveInfo driveInfo; 83 45 g_testHostHardwareLinux = true; 84 intrc = driveInfo.updateFloppies();46 rc = driveInfo.updateFloppies(); 85 47 if (RT_SUCCESS (rc)) 86 48 rc = driveInfo.updateDVDs(); … … 92 54 } 93 55 RTPrintf ("Listing floppy drives detected:\n"); 94 for ( VBoxMainDriveInfo::DriveInfoList::const_iterator it = driveInfo.FloppyBegin();56 for (DriveInfoList::const_iterator it = driveInfo.FloppyBegin(); 95 57 it != driveInfo.FloppyEnd(); ++it) 96 58 { … … 103 65 } 104 66 RTPrintf ("Listing DVD drives detected:\n"); 105 for ( VBoxMainDriveInfo::DriveInfoList::const_iterator it = driveInfo.DVDBegin();67 for (DriveInfoList::const_iterator it = driveInfo.DVDBegin(); 106 68 it != driveInfo.DVDEnd(); ++it) 107 69 { … … 113 75 RTPrintf ("\n"); 114 76 } 77 #ifdef VBOX_USB_WITH_SYSFS 78 VBoxMainUSBDeviceInfo deviceInfo; 79 rc = deviceInfo.UpdateDevices(); 80 if (RT_FAILURE (rc)) 81 { 82 RTPrintf ("Failed to update the host USB device information, error %Rrc\n", 83 rc); 84 return 1; 85 } 86 RTPrintf ("Listing USB devices detected:\n"); 87 for (USBDeviceInfoList::const_iterator it = deviceInfo.DevicesBegin(); 88 it != deviceInfo.DevicesEnd(); ++it) 89 { 90 char szProduct[1024]; 91 if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct), 92 "%s/product", it->mSysfsPath.c_str()) == -1) 93 { 94 if (errno != ENOENT) 95 { 96 RTPrintf ("Failed to get the product name for device %s: error %s\n", 97 it->mDevice.c_str(), strerror(errno)); 98 return 1; 99 } 100 else 101 szProduct[0] = '\0'; 102 } 103 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, it->mDevice.c_str(), 104 it->mSysfsPath.c_str()); 105 RTPrintf (" interfaces:\n"); 106 for (USBInterfaceList::const_iterator it2 = it->mInterfaces.begin(); 107 it2 != it->mInterfaces.end(); ++it2) 108 { 109 char szDriver[RTPATH_MAX]; 110 strcpy(szDriver, "none"); 111 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver), 112 "%s/driver", it2->c_str()); 113 if (size == -1 && errno != ENOENT) 114 { 115 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n", 116 it2->c_str(), it->mDevice.c_str(), strerror(errno)); 117 return 1; 118 } 119 if (RTLinuxSysFsExists("%s/driver", it2->c_str()) != (size != -1)) 120 { 121 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n", 122 it2->c_str(), it->mDevice.c_str()); 123 return 1; 124 } 125 uint64_t u64InterfaceClass; 126 u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass", 127 it2->c_str()); 128 RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n", 129 it2->c_str(), szDriver, u64InterfaceClass); 130 } 131 } 132 RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n"); 133 VBoxMainHotplugWaiter waiter; 134 waiter.Wait(); 135 #endif /* VBOX_USB_WITH_SYSFS */ 115 136 return 0; 116 137 }
Note:
See TracChangeset
for help on using the changeset viewer.