VirtualBox

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

Last change on this file since 17610 was 16178, checked in by vboxsync, 16 years ago

Main/Linux: fixes and clean ups in the DBus code

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