Author: gnichols Date: 2012-09-06 15:11:11 +0000 (Thu, 06 Sep 2012) New Revision: 1372
Removed: trunk/tests/usb/runtest.sh Modified: trunk/tests/usb/Makefile trunk/tests/usb/usb.py trunk/v7/procDeviceDetector.py trunk/v7/usbTest.py Log: 843615 - usb test should not use HAL
Modified: trunk/tests/usb/Makefile =================================================================== --- trunk/tests/usb/Makefile 2012-08-28 13:17:21 UTC (rev 1371) +++ trunk/tests/usb/Makefile 2012-09-06 15:11:11 UTC (rev 1372) @@ -15,17 +15,15 @@
.PHONY: all install download clean
-FILES= runtest.sh usb.py +FILES=usb.py
run: $(FILES) build - ./runtest.sh
build: $(BUILT_FILES) - chmod a+x ./runtest.sh ./usb.py + chmod a+x ./usb.py
clean: rm -f $(BUILT_FILES)
# Include Common Makefile include $(DESTDIR)/usr/share/v7/lib/v7-make.include -
Deleted: trunk/tests/usb/runtest.sh =================================================================== --- trunk/tests/usb/runtest.sh 2012-08-28 13:17:21 UTC (rev 1371) +++ trunk/tests/usb/runtest.sh 2012-09-06 15:11:11 UTC (rev 1372) @@ -1,3 +0,0 @@ -#!/bin/bash - -v7-run-simple-test ${TEST:-$(basename $PWD)} ./usb.py
Modified: trunk/tests/usb/usb.py =================================================================== --- trunk/tests/usb/usb.py 2012-08-28 13:17:21 UTC (rev 1371) +++ trunk/tests/usb/usb.py 2012-09-06 15:11:11 UTC (rev 1372) @@ -1,9 +1,9 @@ #!/usr/bin/python -# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material -# is made available to anyone wishing to use, modify, copy, or -# redistribute it subject to the terms and conditions of the GNU General +# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General # Public License v.2. -# +# # This program is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -25,58 +25,35 @@
# sys.path.append("/home/gnichols/devel/v7") from v7.tags import Constants -from v7.hal import Hal -from v7.procDeviceDetector import ProcDeviceDetector +#from v7.udevDeviceDetector import UdevDeviceDetector from v7.test import Test from v7.device import Device from v7.usbTest import USBTestBase
-class USBTest(USBTestBase): +class USBTest(USBTestBase):
def __init__(self): USBTestBase.__init__(self, name="usb") - - # metadata AKA testinfo.desc - self.owner = "Greg Nichols gnichols@redhat.com" - self.nameSpace = "V7" - self.testPackage = "v7" - self.spaceName = "" - self.path = "v7/tests/usb" - self.version = "1.1" - self.description = "USB Device/Port test" - self.testTime = "5m" - self.runFor = "" - # was: "'usb' == info.bus and 'hub' == info.linux.driver" - # change to run once on what ever USB is there. - self.runOn = "info.product == 'Computer' and not smbios.bios.vendor == 'Xen'" - self.interactive = True - self.requires = "" - - + + def getRequiredRPMs(self): + return ["usbutils"] + def plan(self, planner): tests = list() - isXenGuest = False - hasUSB = False - devices = planner.getHalDeviceDetector().getDevices() - # run if there's a device with info.product == usb and it's not a Xen guest. + devices = planner.getUdevDeviceDetector().getDevices() + # run if there's a device with SUBSYSTEM == usb for device in devices: - if device.getProperty("info.product") == "Computer" and device.getProperty("smbios.bios.vendor") == "Xen": - isXenGuest = True - if device.getProperty("info.bus") == "usb": - hasUSB = True - if device.getProperty("class") == "USB": - hasUSB = True - if hasUSB and not isXenGuest: - test = self.makeCopy() - tests.append(test) + if device.getProperty("SUBSYSTEM") == "usb": + test = self.makeCopy() + tests.append(test) + break return tests -
def run(self): # ask user for the number of ports: print "USB test:" self.pluggedPorts = list() - # check for USB devices, print info about them + self.checkAllUSBPortsUnplugged() self.fixedDevices = len(self.pluggedInDevices) if self.getMode() == Constants.auto: @@ -90,22 +67,18 @@ self.result = Constants.PASS return 0
- - # otherwise - - while len(self.pluggedInDevices)-self.fixedDevices < self.numberOfSockets: + while len(self.pluggedInDevices) - self.fixedDevices < self.numberOfSockets: print "testing socket %s of %s..." % (len(self.pluggedInDevices)-self.fixedDevices+1, self.numberOfSockets) if self.promptContinue("Please plug in a USB device"):
# find out which port was plugged - found = self.addNewPluggedUSBPort() - if found: - (busNumber, portNumber, deviceID) = found + id = self.addNewPluggedUSBPort() + if id: if self.promptContinue("Please unplug the device"): - if self.confirmUSBPortUnplugged(deviceID): - print "confirmed device %s" % deviceID - self.pluggedInDevices.append(deviceID) + if self.confirmUSBPortUnplugged(searchID=id): + print "confirmed device %s unplugged" % id + self.pluggedInDevices.append(id) else: print "Did not confirm the device - repeating test." else: @@ -121,7 +94,6 @@ else: self.returnValue = 1 self.result = Constants.FAIL -
return self.returnValue
@@ -132,7 +104,3 @@ # usbTest.run() returnValue = usbTest.do(sys.argv) sys.exit(returnValue) - - - -
Modified: trunk/v7/procDeviceDetector.py =================================================================== --- trunk/v7/procDeviceDetector.py 2012-08-28 13:17:21 UTC (rev 1371) +++ trunk/v7/procDeviceDetector.py 2012-09-06 15:11:11 UTC (rev 1372) @@ -68,7 +68,7 @@ try: key = keyvalue[0].strip() except IndexError: - return + return
try: value = keyvalue[1].strip() @@ -95,7 +95,7 @@ for device in self.devices: if device.hasPropertyValue(udi): return device - # otherwise + # otherwise return None
@@ -120,16 +120,6 @@ output += device.dump() return output
- def getUSBBusAndPort(self, device): - try: - bus = device.getProperty("Bus") - port = device.getProperty("Port") - id = "%s.%s.%s" % (bus, port, device.getProperty("Dev#")) - return (bus, port, id) - except: - pass - return None - def getProduct(self, device): return device.getProperty("Product")
Modified: trunk/v7/usbTest.py =================================================================== --- trunk/v7/usbTest.py 2012-08-28 13:17:21 UTC (rev 1371) +++ trunk/v7/usbTest.py 2012-09-06 15:11:11 UTC (rev 1372) @@ -1,9 +1,9 @@ #!/usr/bin/python -# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material -# is made available to anyone wishing to use, modify, copy, or -# redistribute it subject to the terms and conditions of the GNU General +# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material +# is made available to anyone wishing to use, modify, copy, or +# redistribute it subject to the terms and conditions of the GNU General # Public License v.2. -# +# # This program is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -24,76 +24,75 @@ import dbus
from v7.tags import Constants, DeviceClass -from v7.hal import Hal -from v7.procDeviceDetector import ProcDeviceDetector from v7.test import Test from v7.device import Device +from v7.command import Command
-class USBTestBase(Test): +class USBTestBase(Test):
def __init__(self, name): Test.__init__(self, name) - self.deviceDetector = None + self.lsusbCommand = "lsusb" + self.pluggedInDevices = list() self.deviceClass = DeviceClass.usb
- def getUSBDevices(self): - #first time - find a working device detector - if not self.deviceDetector: - self.deviceDetector = Hal() - devices = self.deviceDetector.getDevices() - if len(devices) is 0: - print "Note: could not detect USB devices via HAL, using /proc" - self.deviceDetector = ProcDeviceDetector() - devices = self.deviceDetector.getDevices() - - return devices + devices = list() + pattern = re.compile("Bus (?P<bus>\d{3}) Device (?P<port>\d{3}): ID (?P<devid>[0-9a-f]{4}:[0-9a-f]{4}) (?P<name>.*$)") + try: + pipe = Command(self.lsusbCommand) + pipe.start() + while 1: + line = pipe.readline() + if not line or line.strip() == "": + break + match = pattern.match(line) + # a single dev list is a tuple containing information like: + # ('001','002','8087:0020','Intel Corp. Integrated Rate Matching Hub') + dev = match.groups() + devices.append(dev) + except Exception, e: + print "Error: could not read usb devices from lsusb command" + print e + return None + + return devices
- # otherwise - return self.deviceDetector.getDevices() - def checkAllUSBPortsUnplugged(self): devices = self.getUSBDevices() + if not devices: + return None self.pluggedInDevices = list() - returnValue = True for dev in devices: - found = self.deviceDetector.getUSBBusAndPort(dev) - if found: - (busNumber, portNumber, id) = found - self.pluggedInDevices.append(id) - if busNumber and portNumber: - try: - print "%s appears to be plugged into bus %s port %s" %(self.deviceDetector.getProduct(dev), busNumber, portNumber) - except KeyError: - pass + (busID, portID, devID, name) = dev + # generate an unique id combined from busID+portID+devID + # e.g.: 001.002.8087:0020 + id = "%s.%s.%s" % (busID, portID, devID) + self.pluggedInDevices.append(id) + if busID and portID: + print "%s (dev id: %s) appears to be plugged into bus %s port %s" % (name, devID, busID, portID)
def addNewPluggedUSBPort(self): devices = self.getUSBDevices() - for dev in devices: - found = self.deviceDetector.getUSBBusAndPort(dev) - if found: - (busNumber, portNumber, deviceID) = found - if (not deviceID in self.pluggedInDevices) and busNumber and portNumber: - deviceName = self.deviceDetector.getProduct(dev) - if deviceName == "": - deviceName = deviceID - print "%s appears to be plugged into bus %s port %s" %(deviceName, busNumber, portNumber) - - return (busNumber, portNumber, deviceID) + if not devices: + return None + for dev in devices: + (busID, portID, devID, name) = dev + id = "%s.%s.%s" % (busID, portID, devID) + # should execute checkAllUSBPortsUnplugged() first + if (not id in self.pluggedInDevices) and busID and portID: + print "%s (dev id: %s) appears to be plugged into bus %s port %s" % (name, devID, busID, portID) + return id return None
- def confirmUSBPortUnplugged(self, searchDeviceID): + def confirmUSBPortUnplugged(self, searchID): devices = self.getUSBDevices() + if not devices: + return True for dev in devices: - found = self.deviceDetector.getUSBBusAndPort(dev) - if found: - (busNumber, portNumber, deviceID) = found - if deviceID == searchDeviceID: - return False - return True - + (busID, portID, devID, name) = dev + id = "%s.%s.%s" % (busID, portID, devID) + if id == searchID: + return False
- - - - + return True
v7-commits@lists.stg.fedorahosted.org