cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox Validation Kit - USB testcase and benchmark.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Standard Python imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Only the main script needs to modify the path.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncg_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# Validation Kit imports.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# USB gadget control import
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncclass tdUsbBenchmark(vbox.TestDriver): # pylint: disable=R0902
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync USB benchmark.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # The available test devices
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # The first key is the hostname of the host the test is running on.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # It contains a new dictionary with the attached gadgets based on the
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # USB speed we want to test (Low, Full, High, Super).
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # The parameters consist of the hostname of the gadget in the network
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # and the hardware type.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # The following is for local testing and not for the test lab.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync 'adaris': {
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # Mappings of USB controllers to supported USB device speeds.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync self.asVirtModesDef = ['hwvirt', 'hwvirt-np', 'raw'];
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync self.asUsbSpeedDef = ['Low', 'Full', 'High', 'Super'];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Overridden methods.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' Default: %s' % (':'.join(self.asVirtModesDef)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' Default: %s' % (':'.join(str(c) for c in self.acCpusDef)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' Test the specified VMs in the given order. Use this to change');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' the execution order or limit the choice of VMs');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' Default: %s (all)' % (':'.join(self.asTestVMsDef)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log(' Skip the specified VMs when testing.');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbCtrlsDef)));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log(' Default: %s' % (':'.join(str(c) for c in self.asUsbSpeedDef)));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync def parseOption(self, asArgs, iArg): # pylint: disable=R0912,R0915
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--virt-modes" takes a colon separated list of modes');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.InvalidOption('The "--virt-modes" value "%s" is not valid; valid values are: %s' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--cpu-counts" takes a colon separated list of cpu counts');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try: c = int(s);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: raise base.InvalidOption('The "--cpu-counts" value "%s" is not an integer' % (s,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if c <= 0: raise base.InvalidOption('The "--cpu-counts" value "%s" is zero or negative' % (s,));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--test-vms" takes colon separated list');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync raise base.InvalidOption('The "--test-vms" value "%s" is not valid; valid values are: %s' \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--skip-vms" takes colon separated list');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.log('warning: The "--test-vms" value "%s" does not specify any of our test VMs.' % (s));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-ctrls" takes a colon separated list of USB controllers');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('warning: The "--usb-ctrls" value "%s" is not a valid USB controller.' % (s));
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync if iArg >= len(asArgs): raise base.InvalidOption('The "--usb-speed" takes a colon separated list of USB speeds');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log('warning: The "--usb-speed" value "%s" is not a valid USB speed.' % (s));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return vbox.TestDriver.parseOption(self, asArgs, iArg);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Remove skipped VMs from the test list.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except: pass;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Construct the resource list the first time it's queried.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Some stupid trickery to guess the location of the iso. ## fixme - testsuite unzip ++
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxValidationKit.iso'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../VBoxTestSuite.iso'));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/validationkit/VBoxValidationKit.iso';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = '/mnt/ramdisk/vbox/svn/trunk/testsuite/VBoxTestSuite.iso';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = os.path.join(sCur, 'validationkit/VBoxValidationKit.iso');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = os.path.join(sCur, 'testsuite/VBoxTestSuite.iso');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if i is None: pass; # shut up pychecker/pylint.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = '/home/bird/validationkit/VBoxValidationKit.iso';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync sVBoxValidationKit_iso = '/home/bird/testsuite/VBoxTestSuite.iso';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Make sure vboxapi has been imported so we can use the constants.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Configure the VMs we're going to use.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Linux VMs
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oVM = self.createTestVM('tst-arch', 1, '4.2/usb/tst-arch.vdi', sKind = 'ArchLinux_64', fIoApic = True, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync eNic0AttachType = vboxcon.NetworkAttachmentType_NAT, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oVM is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Execute the testcase.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync Returns the gadget hostname and type from the
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync given hostname the test is running on and device speed we want to test.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync kdGadgetsConfigured = self.kdGadgetParams.get(sHostname);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync if kdGadgetsConfigured is not None:
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync return (None, None);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Test execution helpers.
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync def testUsbCompliance(self, oSession, oTxsSession, sSpeed):
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync Test VirtualBoxs USB stack in a VM.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # Get configured USB test devices from hostname we are running on
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync sGadgetHost, sGadgetType = self.getGadgetParams(self.sHostname, sSpeed);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Create device filter
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = oSession.addUsbDeviceFilter('Compliance device', '0525', 'a4a0');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync fRc = oUsbGadget.connectTo(30 * 1000, sGadgetType, sGadgetHost);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Wait a moment to let the USB device appear
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync fRc = self.txsRunTest(oTxsSession, 'Compliance', 3600 * 1000, \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync '${CDROM}/${OS/ARCH}/UsbTest${EXESUFF}', ('UsbTest', ));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.testFailure('Failed to impersonate test device');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.testFailure('Failed to connect to USB gadget');
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync reporter.testFailure('Failed to create USB device filter');
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync def testUsbOneCfg(self, sVmName, sUsbCtrl, sSpeed):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Runs the specified VM thru test #1.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns a success indicator on the general test execution. This is not
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync the actual test result.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Reconfigure the VM
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oSession is not None:
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync # Make sure controllers are disabled initially.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync fRc = oSession.close() and fRc and True; # pychecker hack.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Start up.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oSession, oTxsSession = self.startVmAndConnectToTxsViaTcp(sVmName, fCdWait = False, fNatForwardingForTxs = False);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oSession is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Fudge factor - Allow the guest to finish starting up.
125d777ae84cb6e756c9aa47506cecbcd5849dbfvboxsync fRc = self.testUsbCompliance(oSession, oTxsSession, sSpeed);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Runs one VM thru the various configurations.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync asSupportedSpeeds = self.kdUsbSpeedMappings.get(sUsbCtrl);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync fRc = self.testUsbOneCfg(sVmName, sUsbCtrl, sUsbSpeed);
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync Executes USB test.
5bbb9454328dfeedc25e69918425996f1f8eae60vboxsync reporter.log("Running on host: " + self.sHostname);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # Loop thru the test VMs.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # run test on the VM.