VirtualBox

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

Last change on this file since 28739 was 28617, checked in by vboxsync, 15 years ago

Main/HostHardwareLinux: fix the timeout-in-USB-probing test

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.6 KB
Line 
1/* $Id: tstHostHardwareLinux.cpp 28617 2010-04-22 21:31:39Z vboxsync $ */
2/** @file
3 *
4 * Test executable for quickly excercising/debugging the Linux host hardware
5 * bits.
6 */
7
8/*
9 * Copyright (C) 2008 Sun Microsystems, Inc.
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 * 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.
22 */
23
24#include <HostHardwareLinux.h>
25
26#include <VBox/err.h>
27
28#include <iprt/initterm.h>
29#include <iprt/param.h>
30#include <iprt/stream.h>
31#include <iprt/thread.h>
32#include <iprt/linux/sysfs.h>
33
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36
37#include <errno.h>
38#include <string.h>
39#include <stdlib.h>
40
41void doHotplugEvent(VBoxMainHotplugWaiter *waiter, RTMSINTERVAL cMillies)
42{
43 while (true)
44 {
45 int rc = waiter->Wait (cMillies);
46 if (rc == VERR_TRY_AGAIN)
47 {
48 RTThreadYield();
49 continue;
50 }
51 if (rc == VERR_TIMEOUT)
52 break;
53 if (RT_FAILURE(rc))
54 {
55 RTPrintf("Failed!\n");
56 exit(1);
57 }
58 if (RT_SUCCESS(rc))
59 break;
60 }
61}
62
63int main()
64{
65 RTR3Init();
66 int rc = VINF_SUCCESS;
67 VBoxMainDriveInfo driveInfo;
68 rc = driveInfo.updateFloppies();
69 if (RT_SUCCESS(rc))
70 rc = driveInfo.updateDVDs();
71 if (RT_FAILURE(rc))
72 {
73 RTPrintf("Failed to update the host drive information, error %Rrc\n",
74 rc);
75 return 1;
76 }
77 RTPrintf ("Listing floppy drives detected:\n");
78 for (DriveInfoList::const_iterator it = driveInfo.FloppyBegin();
79 it != driveInfo.FloppyEnd(); ++it)
80 {
81 RTPrintf (" device: %s", it->mDevice.c_str());
82 if (!it->mUdi.isEmpty())
83 RTPrintf (", udi: %s", it->mUdi.c_str());
84 if (!it->mDescription.isEmpty())
85 RTPrintf (", description: %s", it->mDescription.c_str());
86 RTPrintf ("\n");
87 }
88 RTPrintf ("Listing DVD drives detected:\n");
89 for (DriveInfoList::const_iterator it = driveInfo.DVDBegin();
90 it != driveInfo.DVDEnd(); ++it)
91 {
92 RTPrintf (" device: %s", it->mDevice.c_str());
93 if (!it->mUdi.isEmpty())
94 RTPrintf (", udi: %s", it->mUdi.c_str());
95 if (!it->mDescription.isEmpty())
96 RTPrintf (", description: %s", it->mDescription.c_str());
97 RTPrintf ("\n");
98 }
99#ifdef VBOX_USB_WITH_SYSFS
100 VBoxMainUSBDeviceInfo deviceInfo;
101 rc = deviceInfo.UpdateDevices();
102 if (RT_FAILURE(rc))
103 {
104 RTPrintf ("Failed to update the host USB device information, error %Rrc\n",
105 rc);
106 return 1;
107 }
108 RTPrintf ("Listing USB devices detected:\n");
109 for (USBDeviceInfoList::const_iterator it = deviceInfo.DevicesBegin();
110 it != deviceInfo.DevicesEnd(); ++it)
111 {
112 char szProduct[1024];
113 if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct),
114 "%s/product", it->mSysfsPath.c_str()) == -1)
115 {
116 if (errno != ENOENT)
117 {
118 RTPrintf ("Failed to get the product name for device %s: error %s\n",
119 it->mDevice.c_str(), strerror(errno));
120 return 1;
121 }
122 else
123 szProduct[0] = '\0';
124 }
125 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, it->mDevice.c_str(),
126 it->mSysfsPath.c_str());
127 RTPrintf (" interfaces:\n");
128 for (USBInterfaceList::const_iterator it2 = it->mInterfaces.begin();
129 it2 != it->mInterfaces.end(); ++it2)
130 {
131 char szDriver[RTPATH_MAX];
132 strcpy(szDriver, "none");
133 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
134 "%s/driver", it2->c_str());
135 if (size == -1 && errno != ENOENT)
136 {
137 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n",
138 it2->c_str(), it->mDevice.c_str(), strerror(errno));
139 return 1;
140 }
141 if (RTLinuxSysFsExists("%s/driver", it2->c_str()) != (size != -1))
142 {
143 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n",
144 it2->c_str(), it->mDevice.c_str());
145 return 1;
146 }
147 uint64_t u64InterfaceClass;
148 u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass",
149 it2->c_str());
150 RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n",
151 it2->c_str(), szDriver, u64InterfaceClass);
152 }
153 }
154 VBoxMainHotplugWaiter waiter;
155 RTPrintf ("Waiting for hotplug events. Note that DBus often seems to deliver duplicate events in close succession.\n");
156 RTPrintf ("Waiting for a hotplug event for five seconds...\n");
157 doHotplugEvent(&waiter, 5000);
158 RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");
159 doHotplugEvent(&waiter, RT_INDEFINITE_WAIT);
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