VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstHostHardwareLinux.cpp@ 37570

Last change on this file since 37570 was 37423, checked in by vboxsync, 14 years ago

Ran the source code massager (scm).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: tstHostHardwareLinux.cpp 37423 2011-06-12 18:37:56Z vboxsync $ */
2/** @file
3 *
4 * Test executable for quickly excercising/debugging the Linux host hardware
5 * bits.
6 */
7
8/*
9 * Copyright (C) 2008 Oracle Corporation
10 *
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
20#include <HostHardwareLinux.h>
21#include <USBGetDevices.h>
22
23#include <VBox/err.h>
24
25#include <iprt/initterm.h>
26#include <iprt/param.h>
27#include <iprt/stream.h>
28#include <iprt/thread.h>
29#include <iprt/linux/sysfs.h>
30
31#include <iprt/cdefs.h>
32#include <iprt/types.h>
33
34#include <errno.h>
35#include <string.h>
36#include <stdlib.h>
37
38int doHotplugEvent(VBoxMainHotplugWaiter *waiter, RTMSINTERVAL cMillies)
39{
40 int rc;
41 while (true)
42 {
43 rc = waiter->Wait (cMillies);
44 if (rc == VERR_TIMEOUT || rc == VERR_INTERRUPTED)
45 break;
46 if (RT_FAILURE(rc))
47 {
48 RTPrintf("Failed!\n");
49 exit(1);
50 }
51 if (RT_SUCCESS(rc))
52 break;
53 }
54 return rc;
55}
56
57void printDevices(PUSBDEVICE pDevices,
58 const char *pcszDevices,
59 const char *pcszMethod)
60{
61 PUSBDEVICE pDevice = pDevices;
62
63 RTPrintf("Enumerating usb devices using %s at %s\n", pcszMethod, pcszDevices);
64 while (pDevice)
65 {
66 const char *pcszState =
67 pDevice->enmState == USBDEVICESTATE_UNSUPPORTED ? "UNSUPPORTED"
68 : pDevice->enmState == USBDEVICESTATE_USED_BY_HOST ? "USED_BY_HOST"
69 : pDevice->enmState == USBDEVICESTATE_USED_BY_HOST_CAPTURABLE ? "USED_BY_HOST_CAPTURABLE"
70 : pDevice->enmState == USBDEVICESTATE_UNUSED ? "UNUSED"
71 : pDevice->enmState == USBDEVICESTATE_HELD_BY_PROXY ? "held by proxy"
72 : pDevice->enmState == USBDEVICESTATE_USED_BY_GUEST ? "used by guest"
73 : "invalid";
74 RTPrintf(" Manufacturer: %s, product: %s, serial number string: %s, state: %s\n",
75 pDevice->pszManufacturer, pDevice->pszProduct,
76 pDevice->pszSerialNumber, pcszState);
77 RTPrintf(" Device address: %s\n", pDevice->pszAddress);
78 pDevice = pDevice->pNext;
79 }
80}
81
82void freeDevices(PUSBDEVICE pDevices)
83{
84 PUSBDEVICE pDevice = pDevices, pDeviceNext;
85
86 while (pDevice)
87 {
88 pDeviceNext = pDevice->pNext;
89 deviceFree(pDevice);
90 pDevice = pDeviceNext;
91 }
92}
93
94int main()
95{
96 RTR3Init();
97 int rc = VINF_SUCCESS;
98 VBoxMainDriveInfo driveInfo;
99 rc = driveInfo.updateFloppies();
100 if (RT_SUCCESS(rc))
101 rc = driveInfo.updateDVDs();
102 if (RT_FAILURE(rc))
103 {
104 RTPrintf("Failed to update the host drive information, error %Rrc\n",
105 rc);
106 return 1;
107 }
108 RTPrintf ("Listing floppy drives detected:\n");
109 for (DriveInfoList::const_iterator it = driveInfo.FloppyBegin();
110 it != driveInfo.FloppyEnd(); ++it)
111 {
112 RTPrintf (" device: %s", it->mDevice.c_str());
113 if (!it->mUdi.isEmpty())
114 RTPrintf (", udi: %s", it->mUdi.c_str());
115 if (!it->mDescription.isEmpty())
116 RTPrintf (", description: %s", it->mDescription.c_str());
117 RTPrintf ("\n");
118 }
119 RTPrintf ("Listing DVD drives detected:\n");
120 for (DriveInfoList::const_iterator it = driveInfo.DVDBegin();
121 it != driveInfo.DVDEnd(); ++it)
122 {
123 RTPrintf (" device: %s", it->mDevice.c_str());
124 if (!it->mUdi.isEmpty())
125 RTPrintf (", udi: %s", it->mUdi.c_str());
126 if (!it->mDescription.isEmpty())
127 RTPrintf (", description: %s", it->mDescription.c_str());
128 RTPrintf ("\n");
129 }
130 RTPrintf("NOTE: checking for usbfs at /dev/bus/usb, not /proc/bus/usb!!!\n");
131 if (USBProxyLinuxCheckDeviceRoot("/dev/bus/usb", false))
132 {
133 PUSBDEVICE pDevice = USBProxyLinuxGetDevices("/dev/bus/usb",
134 false);
135 printDevices(pDevice, "/dev/bus/usb", "usbfs");
136 freeDevices(pDevice);
137 }
138 else
139 RTPrintf("-> not found\n");
140#ifdef VBOX_USB_WITH_SYSFS
141 RTPrintf("Testing for USB devices at /dev/vboxusb\n");
142 if (USBProxyLinuxCheckDeviceRoot("/dev/vboxusb", true))
143 {
144 PUSBDEVICE pDevice = USBProxyLinuxGetDevices("/dev/vboxusb",
145 true);
146 printDevices(pDevice, "/dev/vboxusb", "sysfs");
147 freeDevices(pDevice);
148 }
149 else
150 RTPrintf("-> not found\n");
151 VBoxMainHotplugWaiter waiter("/dev/vboxusb");
152 RTPrintf ("Waiting for a hotplug event for five seconds...\n");
153 doHotplugEvent(&waiter, 5000);
154 RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");
155 doHotplugEvent(&waiter, RT_INDEFINITE_WAIT);
156 RTPrintf ("Testing interrupting a hotplug event...\n");
157 waiter.Interrupt();
158 rc = doHotplugEvent(&waiter, 5000);
159 RTPrintf ("%s\n", rc == VERR_INTERRUPTED ? "Success!" : "Failed!");
160#endif /* VBOX_USB_WITH_SYSFS */
161 return 0;
162}
163
Note: See TracBrowser for help on using the repository browser.

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