VirtualBox

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

Last change on this file since 34079 was 32324, checked in by vboxsync, 14 years ago

Main/USBProxyServiceLinux: split out USB enumeration from USBProxyServiceLinux.cpp and HostHardwareLinux.cpp into a separate file

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1/* $Id: tstHostHardwareLinux.cpp 32324 2010-09-08 15:43:32Z 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, const char *pcszAccess)
58{
59 PUSBDEVICE pDevice = pDevices;
60
61 RTPrintf("Enumerating usb devices using %s\n", pcszAccess);
62 while (pDevice)
63 {
64 RTPrintf(" Manufacturer: %s, product: %s, serial number string: %s\n",
65 pDevice->pszManufacturer, pDevice->pszProduct,
66 pDevice->pszSerialNumber);
67 RTPrintf(" Device address: %s\n", pDevice->pszAddress);
68 pDevice = pDevice->pNext;
69 }
70}
71
72void freeDevices(PUSBDEVICE pDevices)
73{
74 PUSBDEVICE pDevice = pDevices, pDeviceNext;
75
76 while (pDevice)
77 {
78 pDeviceNext = pDevice->pNext;
79 deviceFree(pDevice);
80 pDevice = pDeviceNext;
81 }
82}
83
84int main()
85{
86 RTR3Init();
87 int rc = VINF_SUCCESS;
88 VBoxMainDriveInfo driveInfo;
89 rc = driveInfo.updateFloppies();
90 if (RT_SUCCESS(rc))
91 rc = driveInfo.updateDVDs();
92 if (RT_FAILURE(rc))
93 {
94 RTPrintf("Failed to update the host drive information, error %Rrc\n",
95 rc);
96 return 1;
97 }
98 RTPrintf ("Listing floppy drives detected:\n");
99 for (DriveInfoList::const_iterator it = driveInfo.FloppyBegin();
100 it != driveInfo.FloppyEnd(); ++it)
101 {
102 RTPrintf (" device: %s", it->mDevice.c_str());
103 if (!it->mUdi.isEmpty())
104 RTPrintf (", udi: %s", it->mUdi.c_str());
105 if (!it->mDescription.isEmpty())
106 RTPrintf (", description: %s", it->mDescription.c_str());
107 RTPrintf ("\n");
108 }
109 RTPrintf ("Listing DVD drives detected:\n");
110 for (DriveInfoList::const_iterator it = driveInfo.DVDBegin();
111 it != driveInfo.DVDEnd(); ++it)
112 {
113 RTPrintf (" device: %s", it->mDevice.c_str());
114 if (!it->mUdi.isEmpty())
115 RTPrintf (", udi: %s", it->mUdi.c_str());
116 if (!it->mDescription.isEmpty())
117 RTPrintf (", description: %s", it->mDescription.c_str());
118 RTPrintf ("\n");
119 }
120#ifdef VBOX_USB_WITH_SYSFS
121 PUSBDEVICE pDevice = USBProxyLinuxGetDevices(NULL);
122 printDevices(pDevice, "sysfs");
123 freeDevices(pDevice);
124 if (USBProxyLinuxCheckForUsbfs("/proc/bus/usb/devices"))
125 {
126 pDevice = USBProxyLinuxGetDevices("/proc/bus/usb");
127 printDevices(pDevice, "/proc/bus/usb");
128 freeDevices(pDevice);
129 }
130 if (USBProxyLinuxCheckForUsbfs("/dev/bus/usb/devices"))
131 {
132 pDevice = USBProxyLinuxGetDevices("/dev/bus/usb");
133 printDevices(pDevice, "/dev/bus/usb");
134 freeDevices(pDevice);
135 }
136 VBoxMainHotplugWaiter waiter;
137 RTPrintf ("Waiting for a hotplug event for five seconds...\n");
138 doHotplugEvent(&waiter, 5000);
139 RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");
140 doHotplugEvent(&waiter, RT_INDEFINITE_WAIT);
141 RTPrintf ("Testing interrupting a hotplug event...\n");
142 waiter.Interrupt();
143 rc = doHotplugEvent(&waiter, 5000);
144 RTPrintf ("%s\n", rc == VERR_INTERRUPTED ? "Success!" : "Failed!");
145#endif /* VBOX_USB_WITH_SYSFS */
146 return 0;
147}
148
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