~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Main/testcase/tstHostHardwareLinux.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: tstHostHardwareLinux.cpp $ */
 
1
/* $Id: tstHostHardwareLinux.cpp 34341 2010-11-24 20:14:36Z vboxsync $ */
2
2
/** @file
3
3
 *
4
4
 * Test executable for quickly excercising/debugging the Linux host hardware
18
18
 */
19
19
 
20
20
#include <HostHardwareLinux.h>
 
21
#include <USBGetDevices.h>
21
22
 
22
23
#include <VBox/err.h>
23
24
 
53
54
    return rc;
54
55
}
55
56
 
 
57
void printDevices(PUSBDEVICE pDevices,
 
58
                  const char *pcszDevices,
 
59
                  const char *pcszMethod)
 
60
{
 
61
    PUSBDEVICE pDevice = pDevices;
 
62
 
 
63
    RTPrintf("Enumerating usb devices using %s at %s\n", pcszMethod, pcszDevices);
 
64
    while (pDevice)
 
65
    {
 
66
        RTPrintf("  Manufacturer: %s, product: %s, serial number string: %s\n",
 
67
                    pDevice->pszManufacturer, pDevice->pszProduct,
 
68
                    pDevice->pszSerialNumber);
 
69
        RTPrintf("    Device address: %s\n", pDevice->pszAddress);
 
70
        pDevice = pDevice->pNext;
 
71
    }
 
72
}
 
73
 
 
74
void freeDevices(PUSBDEVICE pDevices)
 
75
{
 
76
    PUSBDEVICE pDevice = pDevices, pDeviceNext;
 
77
 
 
78
    while (pDevice)
 
79
    {
 
80
        pDeviceNext = pDevice->pNext;
 
81
        deviceFree(pDevice);
 
82
        pDevice = pDeviceNext;
 
83
    }
 
84
}
 
85
 
56
86
int main()
57
87
{
58
88
    RTR3Init();
89
119
            RTPrintf (", description: %s", it->mDescription.c_str());
90
120
        RTPrintf ("\n");
91
121
    }
 
122
    PCUSBDEVTREELOCATION pcLocation = USBProxyLinuxGetDeviceRoot(false);
 
123
    if (pcLocation && !pcLocation->fUseSysfs)
 
124
    {
 
125
        PUSBDEVICE pDevice = USBProxyLinuxGetDevices(pcLocation->szDevicesRoot,
 
126
                                                     false);
 
127
        printDevices(pDevice, pcLocation->szDevicesRoot, "usbfs");
 
128
        freeDevices(pDevice);
 
129
    }
92
130
#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");
 
131
    pcLocation = USBProxyLinuxGetDeviceRoot(true);
 
132
    if (pcLocation && pcLocation->fUseSysfs)
 
133
    {
 
134
        PUSBDEVICE pDevice = USBProxyLinuxGetDevices(pcLocation->szDevicesRoot,
 
135
                                                     true);
 
136
        printDevices(pDevice, pcLocation->szDevicesRoot, "sysfs");
 
137
        freeDevices(pDevice);
 
138
    }
 
139
    VBoxMainHotplugWaiter waiter(pcLocation->szDevicesRoot);
149
140
    RTPrintf ("Waiting for a hotplug event for five seconds...\n");
150
141
    doHotplugEvent(&waiter, 5000);
151
142
    RTPrintf ("Waiting for a hotplug event, Ctrl-C to abort...\n");