1 | /* $Id: tstHostHardwareLinux.cpp 15465 2008-12-14 14:31:14Z 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/linux/sysfs.h>
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 |
|
---|
36 | #include <errno.h>
|
---|
37 | #include <string.h>
|
---|
38 |
|
---|
39 | int main()
|
---|
40 | {
|
---|
41 | RTR3Init();
|
---|
42 | g_testHostHardwareLinux = true;
|
---|
43 | int rc = VINF_SUCCESS;
|
---|
44 | VBoxMainDriveInfo driveInfo;
|
---|
45 | g_testHostHardwareLinux = true;
|
---|
46 | rc = driveInfo.updateFloppies();
|
---|
47 | if (RT_SUCCESS (rc))
|
---|
48 | rc = driveInfo.updateDVDs();
|
---|
49 | if (RT_FAILURE (rc))
|
---|
50 | {
|
---|
51 | RTPrintf("Failed to update the host drive information, error %Rrc\n",
|
---|
52 | rc);
|
---|
53 | return 1;
|
---|
54 | }
|
---|
55 | RTPrintf ("Listing floppy drives detected:\n");
|
---|
56 | for (DriveInfoList::const_iterator it = driveInfo.FloppyBegin();
|
---|
57 | it != driveInfo.FloppyEnd(); ++it)
|
---|
58 | {
|
---|
59 | RTPrintf (" device: %s", it->mDevice.c_str());
|
---|
60 | if (!it->mUdi.empty())
|
---|
61 | RTPrintf (", udi: %s", it->mUdi.c_str());
|
---|
62 | if (!it->mDescription.empty())
|
---|
63 | RTPrintf (", description: %s", it->mDescription.c_str());
|
---|
64 | RTPrintf ("\n");
|
---|
65 | }
|
---|
66 | RTPrintf ("Listing DVD drives detected:\n");
|
---|
67 | for (DriveInfoList::const_iterator it = driveInfo.DVDBegin();
|
---|
68 | it != driveInfo.DVDEnd(); ++it)
|
---|
69 | {
|
---|
70 | RTPrintf (" device: %s", it->mDevice.c_str());
|
---|
71 | if (!it->mUdi.empty())
|
---|
72 | RTPrintf (", udi: %s", it->mUdi.c_str());
|
---|
73 | if (!it->mDescription.empty())
|
---|
74 | RTPrintf (", description: %s", it->mDescription.c_str());
|
---|
75 | RTPrintf ("\n");
|
---|
76 | }
|
---|
77 | #ifdef VBOX_USB_WITH_SYSFS
|
---|
78 | VBoxMainUSBDeviceInfo deviceInfo;
|
---|
79 | rc = deviceInfo.UpdateDevices();
|
---|
80 | if (RT_FAILURE (rc))
|
---|
81 | {
|
---|
82 | RTPrintf ("Failed to update the host USB device information, error %Rrc\n",
|
---|
83 | rc);
|
---|
84 | return 1;
|
---|
85 | }
|
---|
86 | RTPrintf ("Listing USB devices detected:\n");
|
---|
87 | for (USBDeviceInfoList::const_iterator it = deviceInfo.DevicesBegin();
|
---|
88 | it != deviceInfo.DevicesEnd(); ++it)
|
---|
89 | {
|
---|
90 | char szProduct[1024];
|
---|
91 | if (RTLinuxSysFsReadStrFile(szProduct, sizeof(szProduct),
|
---|
92 | "%s/product", it->mSysfsPath.c_str()) == -1)
|
---|
93 | {
|
---|
94 | if (errno != ENOENT)
|
---|
95 | {
|
---|
96 | RTPrintf ("Failed to get the product name for device %s: error %s\n",
|
---|
97 | it->mDevice.c_str(), strerror(errno));
|
---|
98 | return 1;
|
---|
99 | }
|
---|
100 | else
|
---|
101 | szProduct[0] = '\0';
|
---|
102 | }
|
---|
103 | RTPrintf (" device: %s (%s), sysfs path: %s\n", szProduct, it->mDevice.c_str(),
|
---|
104 | it->mSysfsPath.c_str());
|
---|
105 | RTPrintf (" interfaces:\n");
|
---|
106 | for (USBInterfaceList::const_iterator it2 = it->mInterfaces.begin();
|
---|
107 | it2 != it->mInterfaces.end(); ++it2)
|
---|
108 | {
|
---|
109 | char szDriver[RTPATH_MAX];
|
---|
110 | strcpy(szDriver, "none");
|
---|
111 | ssize_t size = RTLinuxSysFsGetLinkDest(szDriver, sizeof(szDriver),
|
---|
112 | "%s/driver", it2->c_str());
|
---|
113 | if (size == -1 && errno != ENOENT)
|
---|
114 | {
|
---|
115 | RTPrintf ("Failed to get the driver for interface %s of device %s: error %s\n",
|
---|
116 | it2->c_str(), it->mDevice.c_str(), strerror(errno));
|
---|
117 | return 1;
|
---|
118 | }
|
---|
119 | if (RTLinuxSysFsExists("%s/driver", it2->c_str()) != (size != -1))
|
---|
120 | {
|
---|
121 | RTPrintf ("RTLinuxSysFsExists did not return the expected value for the driver link of interface %s of device %s.\n",
|
---|
122 | it2->c_str(), it->mDevice.c_str());
|
---|
123 | return 1;
|
---|
124 | }
|
---|
125 | uint64_t u64InterfaceClass;
|
---|
126 | u64InterfaceClass = RTLinuxSysFsReadIntFile(16, "%s/bInterfaceClass",
|
---|
127 | it2->c_str());
|
---|
128 | RTPrintf (" sysfs path: %s, driver: %s, interface class: 0x%x\n",
|
---|
129 | it2->c_str(), szDriver, u64InterfaceClass);
|
---|
130 | }
|
---|
131 | }
|
---|
132 | VBoxMainHotplugWaiter waiter;
|
---|
133 | RTPrintf ("Waiting for hotplug events. Note that DBus often seems to deliver duplicate events in close succession.\n");
|
---|
134 | RTPrintf ("Waiting for a hotplug event for five seconds...\n");
|
---|
135 | waiter.Wait (5000);
|
---|
136 | RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");
|
---|
137 | waiter.Wait(RT_INDEFINITE_WAIT);
|
---|
138 | #endif /* VBOX_USB_WITH_SYSFS */
|
---|
139 | return 0;
|
---|
140 | }
|
---|
141 |
|
---|