VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/usb/tdUsb1.py@ 58907

Last change on this file since 58907 was 58907, checked in by vboxsync, 9 years ago

ValidationKit/usb: More fixes

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdUsb1.py 58907 2015-11-29 17:06:00Z vboxsync $
4
5"""
6VirtualBox Validation Kit - USB testcase and benchmark.
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2014-2015 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 58907 $"
31
32
33# Standard Python imports.
34import os;
35import sys;
36import socket;
37
38# Only the main script needs to modify the path.
39try: __file__
40except: __file__ = sys.argv[0];
41g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
42sys.path.append(g_ksValidationKitDir);
43
44# Validation Kit imports.
45from testdriver import reporter;
46from testdriver import base;
47from testdriver import vbox;
48from testdriver import vboxcon;
49
50# USB gadget control import
51import usbgadget;
52
53class tdUsbBenchmark(vbox.TestDriver): # pylint: disable=R0902
54 """
55 USB benchmark.
56 """
57
58 # The available test devices
59 #
60 # The first key is the hostname of the host the test is running on.
61 # It contains a new dictionary with the attached gadgets based on the
62 # USB speed we want to test (Low, Full, High, Super).
63 # The parameters consist of the hostname of the gadget in the network
64 # and the hardware type.
65 kdGadgetParams = {
66 # The following is for local testing and not for the test lab.
67 'adaris': {
68 'Low': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
69 'Full': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
70 'High': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
71 'Super': ('odroidxu3', usbgadget.g_ksGadgetTypeODroidXu3)
72 },
73 'archusb': {
74 'Low': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
75 'Full': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
76 'High': ('beaglebone', usbgadget.g_ksGadgetTypeBeaglebone),
77 'Super': ('odroidxu3', usbgadget.g_ksGadgetTypeODroidXu3)
78 },
79 };
80
81 # Mappings of USB controllers to supported USB device speeds.
82 kdUsbSpeedMappings = {
83 'OHCI': ['Low', 'Full'],
84 'EHCI': ['High'],
85 'XHCI': ['Low', 'Full', 'High', 'Super']
86 };
87
88 def __init__(self):
89 vbox.TestDriver.__init__(self);
90 self.asRsrcs = None;
91 self.asTestVMsDef = ['tst-arch'];
92 self.asTestVMs = self.asTestVMsDef;
93 self.asSkipVMs = [];
94 self.asVirtModesDef = ['hwvirt', 'hwvirt-np', 'raw'];
95 self.asVirtModes = self.asVirtModesDef;
96 self.acCpusDef = [1, 2,];
97 self.acCpus = self.acCpusDef;
98 self.asUsbCtrlsDef = ['OHCI', 'EHCI', 'XHCI'];
99 self.asUsbCtrls = self.asUsbCtrlsDef;
100 self.asUsbSpeedDef = ['Low', 'Full', 'High', 'Super'];
101 self.asUsbSpeed = self.asUsbSpeedDef;
102 self.sHostname = socket.gethostname().lower();
103
104 #
105 # Overridden methods.
106 #
107 def showUsage(self):
108 rc = vbox.TestDriver.showUsage(self);
109 reporter.log('');
110 reporter.log('tdStorageBenchmark1 Options:');
111 reporter.log(' --virt-modes <m1[:m2[:]]');
112 reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef)));
113 reporter.log(' --cpu-counts <c1[:c2[:]]');
114 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
115 reporter.log(' --test-vms <vm1[:vm2[:...]]>');
116 reporter.log(' Test the specified VMs in the given order. Use this to change');
117 reporter.log(' the execution order or limit the choice of VMs');
118 reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
119 reporter.log(' --skip-vms <vm1[:vm2[:...]]>');
120 reporter.log(' Skip the specified VMs when testing.');
121 reporter.log(' --usb-ctrls <u1[:u2[:]]');
122 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbCtrlsDef)));
123 reporter.log(' --usb-speed <s1[:s2[:]]');
124 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbSpeedDef)));
125 return rc;
126
127 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
128 if asArgs[iArg] == '--virt-modes':
129 iArg += 1;
130 if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
131 self.asVirtModes = asArgs[iArg].split(':');
132 for s in self.asVirtModes:
133 if s not in self.asVirtModesDef:
134 raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
135 % (s, ' '.join(self.asVirtModesDef)));
136 elif asArgs[iArg] == '--cpu-counts':
137 iArg += 1;
138 if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
139 self.acCpus = [];
140 for s in asArgs[iArg].split(':'):
141 try: c = int(s);
142 except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
143 if c <= 0: raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
144 self.acCpus.append(c);
145 elif asArgs[iArg] == '--test-vms':
146 iArg += 1;
147 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
148 self.asTestVMs = asArgs[iArg].split(':');
149 for s in self.asTestVMs:
150 if s not in self.asTestVMsDef:
151 raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
152 % (s, ' '.join(self.asTestVMsDef)));
153 elif asArgs[iArg] == '--skip-vms':
154 iArg += 1;
155 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
156 self.asSkipVMs = asArgs[iArg].split(':');
157 for s in self.asSkipVMs:
158 if s not in self.asTestVMsDef:
159 reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));
160 elif asArgs[iArg] == '--usb-ctrls':
161 iArg += 1;
162 if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-ctrls" takes a colon separated list of USB controllers');
163 self.asUsbCtrls = asArgs[iArg].split(':');
164 for s in self.asUsbCtrls:
165 if s not in self.asUsbCtrlsDef:
166 reporter.log('warning: The "--usb-ctrls" value "%s" is not a valid USB controller.' % (s));
167 elif asArgs[iArg] == '--usb-speed':
168 iArg += 1;
169 if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-speed" takes a colon separated list of USB speeds');
170 self.asUsbSpeed = asArgs[iArg].split(':');
171 for s in self.asUsbSpeed:
172 if s not in self.asUsbSpeedDef:
173 reporter.log('warning: The "--usb-speed" value "%s" is not a valid USB speed.' % (s));
174 else:
175 return vbox.TestDriver.parseOption(self, asArgs, iArg);
176 return iArg + 1;
177
178 def completeOptions(self):
179 # Remove skipped VMs from the test list.
180 for sVM in self.asSkipVMs:
181 try: self.asTestVMs.remove(sVM);
182 except: pass;
183
184 return vbox.TestDriver.completeOptions(self);
185
186 def getResourceSet(self):
187 # Construct the resource list the first time it's queried.
188 if self.asRsrcs is None:
189 self.asRsrcs = [];
190
191 if 'tst-arch' in self.asTestVMs:
192 self.asRsrcs.append('4.2/usb/tst-arch.vdi');
193
194 return self.asRsrcs;
195
196 def actionConfig(self):
197
198 # Some stupid trickery to guess the location of the iso. ## fixme - testsuite unzip ++
199 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
200 if not os.path.isfile(sVBoxValidationKit_iso):
201 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
202 if not os.path.isfile(sVBoxValidationKit_iso):
203 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/validationkit/VBoxValidationKit.iso';
204 if not os.path.isfile(sVBoxValidationKit_iso):
205 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/testsuite/VBoxTestSuite.iso';
206 if not os.path.isfile(sVBoxValidationKit_iso):
207 sCur = os.getcwd();
208 for i in range(0, 10):
209 sVBoxValidationKit_iso = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
210 if os.path.isfile(sVBoxValidationKit_iso):
211 break;
212 sVBoxValidationKit_iso = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
213 if os.path.isfile(sVBoxValidationKit_iso):
214 break;
215 sCur = os.path.abspath(os.path.join(sCur, '..'));
216 if i is None: pass; # shut up pychecker/pylint.
217 if not os.path.isfile(sVBoxValidationKit_iso):
218 sVBoxValidationKit_iso = '/home/bird/validationkit/VBoxValidationKit.iso';
219 if not os.path.isfile(sVBoxValidationKit_iso):
220 sVBoxValidationKit_iso = '/home/bird/testsuite/VBoxTestSuite.iso';
221
222 # Make sure vboxapi has been imported so we can use the constants.
223 if not self.importVBoxApi():
224 return False;
225
226 #
227 # Configure the VMs we're going to use.
228 #
229
230 # Linux VMs
231 if 'tst-arch' in self.asTestVMs:
232 oVM = self.createTestVM('tst-arch', 1, '4.2/usb/tst-arch.vdi', sKind = 'ArchLinux_64', fIoApic = True, \
233 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
234 sDvdImage = sVBoxValidationKit_iso);
235 if oVM is None:
236 return False;
237
238 return True;
239
240 def actionExecute(self):
241 """
242 Execute the testcase.
243 """
244 fRc = self.testUsb();
245 return fRc;
246
247 def getGadgetParams(self, sHostname, sSpeed):
248 """
249 Returns the gadget hostname and type from the
250 given hostname the test is running on and device speed we want to test.
251 """
252 kdGadgetsConfigured = self.kdGadgetParams.get(sHostname);
253 if kdGadgetsConfigured is not None:
254 return kdGadgetsConfigured.get(sSpeed);
255
256 return (None, None);
257
258 #
259 # Test execution helpers.
260 #
261 def testUsbCompliance(self, oSession, oTxsSession, sUsbCtrl, sSpeed):
262 """
263 Test VirtualBoxs USB stack in a VM.
264 """
265 # Get configured USB test devices from hostname we are running on
266 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed);
267
268 # Create device filter
269 fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
270 if fRc is True:
271 oUsbGadget = usbgadget.UsbGadget();
272 reporter.log('Connecting to gadget: ' + sGadgetType);
273 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost);
274 if fRc is True:
275 reporter.log('Connect succeeded');
276 fRc = oUsbGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
277 if fRc is True:
278
279 # Wait a moment to let the USB device appear
280 self.sleep(3);
281
282 tupCmdLine = ('UsbTest', );
283 # Exclude a few tests which hang and cause a timeout, need investigation.
284 if sUsbCtrl is 'XHCI':
285 tupCmdLine = tupCmdLine + ('--exclude', '10', '--exclude', '24');
286
287 fRc = self.txsRunTest(oTxsSession, 'Compliance', 3600 * 1000, \
288 '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', tupCmdLine);
289
290 else:
291 reporter.testFailure('Failed to impersonate test device');
292
293 oUsbGadget.disconnectFrom();
294 else:
295 reporter.testFailure('Failed to connect to USB gadget');
296 else:
297 reporter.testFailure('Failed to create USB device filter');
298
299 return fRc;
300
301 def testUsbOneCfg(self, sVmName, sUsbCtrl, sSpeed):
302 """
303 Runs the specified VM thru test #1.
304
305 Returns a success indicator on the general test execution. This is not
306 the actual test result.
307 """
308 oVM = self.getVmByName(sVmName);
309
310 # Reconfigure the VM
311 fRc = True;
312 oSession = self.openSession(oVM);
313 if oSession is not None:
314 fRc = fRc and oSession.enableVirtEx(True);
315 fRc = fRc and oSession.enableNestedPaging(True);
316
317 # Make sure controllers are disabled initially.
318 fRc = fRc and oSession.enableUsbOhci(False);
319 fRc = fRc and oSession.enableUsbEhci(False);
320 fRc = fRc and oSession.enableUsbXhci(False);
321
322 if sUsbCtrl == 'OHCI':
323 fRc = fRc and oSession.enableUsbOhci(True);
324 elif sUsbCtrl == 'EHCI':
325 fRc = fRc and oSession.enableUsbEhci(True);
326 elif sUsbCtrl == 'XHCI':
327 fRc = fRc and oSession.enableUsbXhci(True);
328 fRc = fRc and oSession.saveSettings();
329 fRc = oSession.close() and fRc and True; # pychecker hack.
330 oSession = None;
331 else:
332 fRc = False;
333
334 # Start up.
335 if fRc is True:
336 self.logVmInfo(oVM);
337 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = False);
338 if oSession is not None:
339 self.addTask(oSession);
340
341 # Fudge factor - Allow the guest to finish starting up.
342 self.sleep(5);
343
344 fRc = self.testUsbCompliance(oSession, oTxsSession, sUsbCtrl, sSpeed);
345
346 # cleanup.
347 self.removeTask(oTxsSession);
348 self.terminateVmBySession(oSession)
349 else:
350 fRc = False;
351 return fRc;
352
353 def testUsbForOneVM(self, sVmName):
354 """
355 Runs one VM thru the various configurations.
356 """
357 reporter.testStart(sVmName);
358 for sUsbCtrl in self.asUsbCtrls:
359 reporter.testStart(sUsbCtrl)
360 for sUsbSpeed in self.asUsbSpeed:
361 asSupportedSpeeds = self.kdUsbSpeedMappings.get(sUsbCtrl);
362 if sUsbSpeed in asSupportedSpeeds:
363 reporter.testStart(sUsbSpeed)
364 fRc = self.testUsbOneCfg(sVmName, sUsbCtrl, sUsbSpeed);
365 reporter.testDone();
366 reporter.testDone();
367 reporter.testDone();
368 return fRc;
369
370 def testUsb(self):
371 """
372 Executes USB test.
373 """
374
375 reporter.log("Running on host: " + self.sHostname);
376
377 # Loop thru the test VMs.
378 for sVM in self.asTestVMs:
379 # run test on the VM.
380 fRc = self.testUsbForOneVM(sVM);
381
382 return fRc;
383
384
385
386if __name__ == '__main__':
387 sys.exit(tdUsbBenchmark().main(sys.argv));
388
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette