VirtualBox

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

Last change on this file since 31722 was 31652, checked in by vboxsync, 14 years ago

re-applied r64780

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/* $Id: tstHostHardwareLinux.cpp 31652 2010-08-13 14:17:53Z 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 AssertReturn(VBoxMainUSBDevInfoInit(&deviceInfo), 1);
95 rc = USBDevInfoUpdateDevices(&deviceInfo);
96 if (RT_FAILURE(rc))
97 {
98 RTPrintf ("Failed to update the host USB device information, error %Rrc\n",
99 rc);
100 return 1;
101 }
102 RTPrintf ("Listing USB devices detected:\n");
103 USBDeviceInfoList_iterator it;
104 USBDeviceInfoList_iter_init(&it, USBDevInfoBegin(&deviceInfo));
105 for (; !USBDeviceInfoList_iter_eq(&it, USBDevInfoEnd(&deviceInfo));
106 USBDeviceInfoList_iter_incr(&it))
107 {
108 char szProduct[1024];
109 USBDeviceInfo *pInfo = USBDeviceInfoList_iter_target(&it);
110 if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct),
111 "%s/product", pInfo->mSysfsPath) == -1)
112 {
113 if (errno != ENOENT)
114 {
115 RTPrintf ("Failed to get the product name for device %s: error %s\n",
116 pInfo->mDevice, strerror(errno));
117 return 1;
118 }
119 else
120 szProduct[0] = '\0';
121 }
122 RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, pInfo->mDevice,
123 pInfo->mSysfsPath);
124 RTPrintf (" interfaces:\n");
125 USBInterfaceList_iterator it2;
126 USBInterfaceList_iter_init(&it2, USBInterfaceList_begin(&pInfo->mInterfaces));
127 for (; !USBInterfaceList_iter_eq(&it2, USBInterfaceList_end(&pInfo->mInterfaces));
128 USBInterfaceList_iter_incr(&it2))
129 {
130 char szDriver[RTPATH_MAX];
131 char *pszIf = *USBInterfaceList_iter_target(&it2);
132 strcpy(szDriver, "none");
133 ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
134 "%s/driver", pszIf);
135 if (size == -1 && errno != ENOENT)
136 {
137 RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n",
138 pszIf, pInfo->mDevice, strerror(errno));
139 return 1;
140 }
141 if (RTLinuxSysFsExists("%s/driver", pszIf) != (size != -1))
142 {
143 RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n",
144 pszIf, pInfo->mDevice);
145 return 1;
146 }
147 uint64_t u64InterfaceClass;
148 u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass",
149 pszIf);
150 RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n",
151 pszIf, szDriver, u64InterfaceClass);
152 }
153 }
154 VBoxMainHotplugWaiter waiter;
155 RTPrintf ("Waiting for a hotplug event for five seconds...\n");
156 doHotplugEvent(&waiter, 5000);
157 RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");
158 doHotplugEvent(&waiter, RT_INDEFINITE_WAIT);
159 RTPrintf ("Testing interrupting a hotplug event...\n");
160 waiter.Interrupt();
161 rc = doHotplugEvent(&waiter, 5000);
162 RTPrintf ("%s\n", rc == VERR_INTERRUPTED ? "Success!" : "Failed!");
163#endif /* VBOX_USB_WITH_SYSFS */
164 return 0;
165}
166
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