VirtualBox

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

Last change on this file since 58899 was 58899, checked in by vboxsync, 10 years ago

ValidationKit/tests/usb: New profile for local tests

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# $Id: tdUsb1.py 58899 2015-11-27 11:21:51Z 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.215389.xyz. 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: 58899 $"
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
51from usbgadget import 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', 'BeagleBoneBlack'),
69 'Full': ('beaglebone', 'BeagleBoneBlack'),
70 'High': ('beaglebone', 'BeagleBoneBlack'),
71 'Super': ('odroidxu3', 'ODroid-XU3')
72 },
73 'archusb': {
74 'Low': ('odroidxu3', 'ODroid-XU3'),
75 'Full': ('odroidxu3', 'ODroid-XU3'),
76 'High': ('odroidxu3', 'ODroid-XU3'),
77 'Super': ('odroidxu3', 'ODroid-XU3')
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.oGuestToGuestVM = None;
92 self.oGuestToGuestSess = None;
93 self.oGuestToGuestTxs = None;
94 self.asTestVMsDef = ['tst-arch'];
95 self.asTestVMs = self.asTestVMsDef;
96 self.asSkipVMs = [];
97 self.asVirtModesDef = ['hwvirt', 'hwvirt-np', 'raw'];
98 self.asVirtModes = self.asVirtModesDef;
99 self.acCpusDef = [1, 2,];
100 self.acCpus = self.acCpusDef;
101 self.asUsbCtrlsDef = ['OHCI', 'EHCI', 'XHCI'];
102 self.asUsbCtrls = self.asUsbCtrlsDef;
103 self.asUsbSpeedDef = ['Low', 'Full', 'High', 'Super'];
104 self.asUsbSpeed = self.asUsbSpeedDef;
105 self.sHostname = socket.gethostname().lower();
106
107 #
108 # Overridden methods.
109 #
110 def showUsage(self):
111 rc = vbox.TestDriver.showUsage(self);
112 reporter.log('');
113 reporter.log('tdStorageBenchmark1 Options:');
114 reporter.log(' --virt-modes <m1[:m2[:]]');
115 reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef)));
116 reporter.log(' --cpu-counts <c1[:c2[:]]');
117 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
118 reporter.log(' --test-vms <vm1[:vm2[:...]]>');
119 reporter.log(' Test the specified VMs in the given order. Use this to change');
120 reporter.log(' the execution order or limit the choice of VMs');
121 reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
122 reporter.log(' --skip-vms <vm1[:vm2[:...]]>');
123 reporter.log(' Skip the specified VMs when testing.');
124 reporter.log(' --usb-ctrls <u1[:u2[:]]');
125 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbCtrlsDef)));
126 reporter.log(' --usb-speed <s1[:s2[:]]');
127 reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbSpeedDef)));
128 return rc;
129
130 def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
131 if asArgs[iArg] == '--virt-modes':
132 iArg += 1;
133 if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
134 self.asVirtModes = asArgs[iArg].split(':');
135 for s in self.asVirtModes:
136 if s not in self.asVirtModesDef:
137 raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
138 % (s, ' '.join(self.asVirtModesDef)));
139 elif asArgs[iArg] == '--cpu-counts':
140 iArg += 1;
141 if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
142 self.acCpus = [];
143 for s in asArgs[iArg].split(':'):
144 try: c = int(s);
145 except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
146 if c <= 0: raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
147 self.acCpus.append(c);
148 elif asArgs[iArg] == '--test-vms':
149 iArg += 1;
150 if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
151 self.asTestVMs = asArgs[iArg].split(':');
152 for s in self.asTestVMs:
153 if s not in self.asTestVMsDef:
154 raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
155 % (s, ' '.join(self.asTestVMsDef)));
156 elif asArgs[iArg] == '--skip-vms':
157 iArg += 1;
158 if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
159 self.asSkipVMs = asArgs[iArg].split(':');
160 for s in self.asSkipVMs:
161 if s not in self.asTestVMsDef:
162 reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));
163 elif asArgs[iArg] == '--usb-ctrls':
164 iArg += 1;
165 if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-ctrls" takes a colon separated list of USB controllers');
166 self.asUsbCtrls = asArgs[iArg].split(':');
167 for s in self.asUsbCtrls:
168 if s not in self.asUsbCtrlsDef:
169 reporter.log('warning: The "--usb-ctrls" value "%s" is not a valid USB controller.' % (s));
170 elif asArgs[iArg] == '--usb-speed':
171 iArg += 1;
172 if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-speed" takes a colon separated list of USB speeds');
173 self.asUsbSpeed = asArgs[iArg].split(':');
174 for s in self.asUsbSpeed:
175 if s not in self.asUsbSpeedDef:
176 reporter.log('warning: The "--usb-speed" value "%s" is not a valid USB speed.' % (s));
177 else:
178 return vbox.TestDriver.parseOption(self, asArgs, iArg);
179 return iArg + 1;
180
181 def completeOptions(self):
182 # Remove skipped VMs from the test list.
183 for sVM in self.asSkipVMs:
184 try: self.asTestVMs.remove(sVM);
185 except: pass;
186
187 return vbox.TestDriver.completeOptions(self);
188
189 def getResourceSet(self):
190 # Construct the resource list the first time it's queried.
191 if self.asRsrcs is None:
192 self.asRsrcs = [];
193
194 if 'tst-arch' in self.asTestVMs:
195 self.asRsrcs.append('4.2/usb/tst-arch.vdi');
196
197 return self.asRsrcs;
198
199 def actionConfig(self):
200
201 # Some stupid trickery to guess the location of the iso. ## fixme - testsuite unzip ++
202 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
203 if not os.path.isfile(sVBoxValidationKit_iso):
204 sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
205 if not os.path.isfile(sVBoxValidationKit_iso):
206 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/validationkit/VBoxValidationKit.iso';
207 if not os.path.isfile(sVBoxValidationKit_iso):
208 sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/testsuite/VBoxTestSuite.iso';
209 if not os.path.isfile(sVBoxValidationKit_iso):
210 sCur = os.getcwd();
211 for i in range(0, 10):
212 sVBoxValidationKit_iso = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
213 if os.path.isfile(sVBoxValidationKit_iso):
214 break;
215 sVBoxValidationKit_iso = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
216 if os.path.isfile(sVBoxValidationKit_iso):
217 break;
218 sCur = os.path.abspath(os.path.join(sCur, '..'));
219 if i is None: pass; # shut up pychecker/pylint.
220 if not os.path.isfile(sVBoxValidationKit_iso):
221 sVBoxValidationKit_iso = '/home/bird/validationkit/VBoxValidationKit.iso';
222 if not os.path.isfile(sVBoxValidationKit_iso):
223 sVBoxValidationKit_iso = '/home/bird/testsuite/VBoxTestSuite.iso';
224
225 # Make sure vboxapi has been imported so we can use the constants.
226 if not self.importVBoxApi():
227 return False;
228
229 #
230 # Configure the VMs we're going to use.
231 #
232
233 # Linux VMs
234 if 'tst-arch' in self.asTestVMs:
235 oVM = self.createTestVM('tst-arch', 1, '4.2/usb/tst-arch.vdi', sKind = 'ArchLinux_64', fIoApic = True, \
236 eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
237 sDvdImage = sVBoxValidationKit_iso);
238 if oVM is None:
239 return False;
240
241 return True;
242
243 def actionExecute(self):
244 """
245 Execute the testcase.
246 """
247 fRc = self.testUsb();
248 return fRc;
249
250 def getGadgetParams(self, sHostname, sSpeed):
251 """
252 Returns the gadget hostname and type from the
253 given hostname the test is running on and device speed we want to test.
254 """
255 kdGadgetsConfigured = self.kdGadgetParams.get(sHostname);
256 if kdGadgetsConfigured is not None:
257 return kdGadgetsConfigured.get(sSpeed);
258
259 return (None, None);
260
261 #
262 # Test execution helpers.
263 #
264 def testUsbCompliance(self, oSession, oTxsSession, sSpeed):
265 """
266 Test VirtualBoxs USB stack in a VM.
267 """
268 # Get configured USB test devices from hostname we are running on
269 sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed);
270
271 # Create device filter
272 fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
273 if fRc is True:
274 oUsbGadget = UsbGadget();
275 fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost);
276 if fRc is True:
277 fRc = oUsbGadget.impersonate('Test');
278 if fRc is True:
279
280 # Wait a moment to let the USB device appear
281 self.sleep(3);
282
283 fRc = self.txsRunTest(oTxsSession, 'Compliance', 3600 * 1000, \
284 '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', ('UsbTest', ));
285
286 else:
287 reporter.testFailure('Failed to impersonate test device');
288
289 oUsbGadget.disconnectFrom();
290 else:
291 reporter.testFailure('Failed to connect to USB gadget');
292 else:
293 reporter.testFailure('Failed to create USB device filter');
294
295 return fRc;
296
297 def testUsbOneCfg(self, sVmName, sUsbCtrl, sSpeed):
298 """
299 Runs the specified VM thru test #1.
300
301 Returns a success indicator on the general test execution. This is not
302 the actual test result.
303 """
304 oVM = self.getVmByName(sVmName);
305
306 # Reconfigure the VM
307 fRc = True;
308 oSession = self.openSession(oVM);
309 if oSession is not None:
310 fRc = fRc and oSession.enableVirtEx(True);
311 fRc = fRc and oSession.enableNestedPaging(True);
312
313 # Make sure controllers are disabled initially.
314 fRc = fRc and oSession.enableUsbOhci(False);
315 fRc = fRc and oSession.enableUsbEhci(False);
316 fRc = fRc and oSession.enableUsbXhci(False);
317
318 if sUsbCtrl == 'OHCI':
319 fRc = fRc and oSession.enableUsbOhci(True);
320 elif sUsbCtrl == 'EHCI':
321 fRc = fRc and oSession.enableUsbEhci(True);
322 elif sUsbCtrl == 'XHCI':
323 fRc = fRc and oSession.enableUsbXhci(True);
324 fRc = fRc and oSession.saveSettings();
325 fRc = oSession.close() and fRc and True; # pychecker hack.
326 oSession = None;
327 else:
328 fRc = False;
329
330 # Start up.
331 if fRc is True:
332 self.logVmInfo(oVM);
333 oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = False);
334 if oSession is not None:
335 self.addTask(oSession);
336
337 # Fudge factor - Allow the guest to finish starting up.
338 self.sleep(5);
339
340 fRc = self.testUsbCompliance(oSession, oTxsSession, sSpeed);
341
342 # cleanup.
343 self.removeTask(oTxsSession);
344 self.terminateVmBySession(oSession)
345 else:
346 fRc = False;
347 return fRc;
348
349 def testUsbForOneVM(self, sVmName):
350 """
351 Runs one VM thru the various configurations.
352 """
353 reporter.testStart(sVmName);
354 for sUsbCtrl in self.asUsbCtrls:
355 reporter.testStart(sUsbCtrl)
356 for sUsbSpeed in self.asUsbSpeed:
357 asSupportedSpeeds = self.kdUsbSpeedMappings.get(sUsbCtrl);
358 if sUsbSpeed in asSupportedSpeeds:
359 reporter.testStart(sUsbSpeed)
360 fRc = self.testUsbOneCfg(sVmName, sUsbCtrl, sUsbSpeed);
361 reporter.testDone(not fRc);
362 reporter.testDone();
363 reporter.testDone();
364 return fRc;
365
366 def testUsb(self):
367 """
368 Executes USB test.
369 """
370
371 reporter.log("Running on host: " + self.sHostname);
372
373 # Loop thru the test VMs.
374 for sVM in self.asTestVMs:
375 # run test on the VM.
376 if not self.testUsbForOneVM(sVM):
377 fRc = False;
378 else:
379 fRc = True;
380
381 return fRc;
382
383
384
385if __name__ == '__main__':
386 sys.exit(tdUsbBenchmark().main(sys.argv));
387
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