VirtualBox

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

Last change on this file since 30670 was 30265, checked in by vboxsync, 14 years ago

OSE fix

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