VirtualBox

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

Last change on this file since 25275 was 23522, checked in by vboxsync, 15 years ago

Main/HostHardwareLinux: more rewriting of the Linux host drive code, including a complete rewrite of the legacy code

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

© 2023 Oracle
ContactPrivacy policyTerms of Use