Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: gft_hwcomp.py

Issue 6821072: factory_test_tools: support legacy probing mode (Closed) Base URL: ssh://gitrw.chromium.org:9222/factory_test_tools.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gft_hwcomp.py
diff --git a/gft_hwcomp.py b/gft_hwcomp.py
index ff2b8e0e36b5eeb191b070fc02b65b184adcbd42..a8534d64fabc7aa25f9ff548111d97136b72a2c6 100755
--- a/gft_hwcomp.py
+++ b/gft_hwcomp.py
@@ -135,6 +135,40 @@ class HardwareComponents(object):
return loaded
@Memorize
+ def is_legacy_device_record(self, record):
+ """ Returns if a matching record looks like a legacy device. """
+ # Current format: [0-9a-f]{4}:[0-9a-f]{4}
+ return True if re.match('[0-9a-f]{4}:[0-9a-f]{4}', record) else False
+
+ @Memorize
+ def _get_legacy_device_list(self):
+ # pci: cat /proc/bus/pci/devices | cut -f 2 # 0.004s < lspci=0.012s
+ device_list = []
+ pci_device_file = '/proc/bus/pci/devices'
+ if os.path.exists(pci_device_file):
+ with open(pci_device_file) as handle:
+ pci_list = [data.split('\t', 2)[1]
+ for data in handle.readlines()]
+ device_list += ['%s:%s' % (entry[:4], entry[4:])
+ for entry in pci_list]
+ else:
+ DebugMsg('Failed to read %s. Execute lspci.' % pci_device_list)
+ pci_list = [entry.split()[2:4]
+ for entry in
+ gft_common.SystemOutput('lspci -n -mm').splitlines()]
+ device_list += ['%s:%s' % (vendor.strip('"'), product.strip('"'))
+ for (vendor, product) in pci_list]
+ # usb: realpath(/sys/bus/usb/devices/*:*)/../id* # 0.05s < lspci=0.078s
+ usb_devs = glob.glob('/sys/bus/usb/devices/*:*')
+ for dev in usb_devs:
+ path = os.path.join(os.path.realpath(dev), '..')
+ device_list += ['%s:%s' %
+ (gft_common.ReadOneLine(os.path.join(path, 'idVendor')),
+ gft_common.ReadOneLine(os.path.join(path, 'idProduct')))]
+ DebugMsg('Legacy device list: ' + ', '.join(device_list))
+ return device_list
+
+ @Memorize
def _get_all_connection_info(self):
""" Probes available connectivity and device information """
connection_info = {
@@ -649,12 +683,24 @@ class HardwareComponents(object):
if '*' in approved_values:
return
- for value in exact_values:
- if value not in approved_values:
- if cid in self._failures:
- self._failures[cid].append(value)
- else:
- self._failures[cid] = [value]
+ unmatched = [value for value in exact_values
+ if value not in approved_values]
+ if not unmatched:
+ return
+
+ # there's some error, let's try to match them in legacy list
+ legacy_approved = filter(self.is_legacy_device_record, approved_values)
+ if set(legacy_approved) == set(approved_values):
+ DebugMsg('Start legacy search for cid: ' + cid)
+ # safe for legacy match
+ legacy_list = self._get_legacy_device_list()
+ matched = list(set(legacy_list).intersection(set(approved_values)))
+ if matched:
+ DebugMsg('Changed detected list: %s->%s' % (self._system[cid], matched))
+ self._system[cid] = matched
+ return
+ # update with remaining error.
+ self._failures[cid] = unmatched
@Memorize
def verify_probable_component(self, cid, approved_values):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698