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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 import glob 7 import glob
8 import os 8 import os
9 import pprint 9 import pprint
10 import re 10 import re
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 @Memorize 128 @Memorize
129 def load_module(self, name): 129 def load_module(self, name):
130 grep_cmd = ('lsmod 2>/dev/null | grep -q %s' % name) 130 grep_cmd = ('lsmod 2>/dev/null | grep -q %s' % name)
131 loaded = (os.system(grep_cmd) == 0) 131 loaded = (os.system(grep_cmd) == 0)
132 if not loaded: 132 if not loaded:
133 if os.system('modprobe %s >/dev/null 2>&1' % name) != 0: 133 if os.system('modprobe %s >/dev/null 2>&1' % name) != 0:
134 ErrorMsg("Cannot load module: %s" % name) 134 ErrorMsg("Cannot load module: %s" % name)
135 return loaded 135 return loaded
136 136
137 @Memorize 137 @Memorize
138 def is_legacy_device_record(self, record):
139 """ Returns if a matching record looks like a legacy device. """
140 # Current format: [0-9a-f]{4}:[0-9a-f]{4}
141 return True if re.match('[0-9a-f]{4}:[0-9a-f]{4}', record) else False
142
143 @Memorize
144 def _get_legacy_device_list(self):
145 # pci: cat /proc/bus/pci/devices | cut -f 2 # 0.004s < lspci=0.012s
146 device_list = []
147 pci_device_file = '/proc/bus/pci/devices'
148 if os.path.exists(pci_device_file):
149 with open(pci_device_file) as handle:
150 pci_list = [data.split('\t', 2)[1]
151 for data in handle.readlines()]
152 device_list += ['%s:%s' % (entry[:4], entry[4:])
153 for entry in pci_list]
154 else:
155 DebugMsg('Failed to read %s. Execute lspci.' % pci_device_list)
156 pci_list = [entry.split()[2:4]
157 for entry in
158 gft_common.SystemOutput('lspci -n -mm').splitlines()]
159 device_list += ['%s:%s' % (vendor.strip('"'), product.strip('"'))
160 for (vendor, product) in pci_list]
161 # usb: realpath(/sys/bus/usb/devices/*:*)/../id* # 0.05s < lspci=0.078s
162 usb_devs = glob.glob('/sys/bus/usb/devices/*:*')
163 for dev in usb_devs:
164 path = os.path.join(os.path.realpath(dev), '..')
165 device_list += ['%s:%s' %
166 (gft_common.ReadOneLine(os.path.join(path, 'idVendor')),
167 gft_common.ReadOneLine(os.path.join(path, 'idProduct')))]
168 DebugMsg('Legacy device list: ' + ', '.join(device_list))
169 return device_list
170
171 @Memorize
138 def _get_all_connection_info(self): 172 def _get_all_connection_info(self):
139 """ Probes available connectivity and device information """ 173 """ Probes available connectivity and device information """
140 connection_info = { 174 connection_info = {
141 'wireless': '/sys/class/net/wlan0/device', 175 'wireless': '/sys/class/net/wlan0/device',
142 'ethernet': '/sys/class/net/eth0/device', 176 'ethernet': '/sys/class/net/eth0/device',
143 '3g': '/sys/class/tty/ttyUSB0/device', 177 '3g': '/sys/class/tty/ttyUSB0/device',
144 } 178 }
145 flimflam_scripts_base = '/usr/local/lib/flimflam/test' 179 flimflam_scripts_base = '/usr/local/lib/flimflam/test'
146 if os.path.exists(flimflam_scripts_base): 180 if os.path.exists(flimflam_scripts_base):
147 # TODO(hungte) use flimflam to update the device list. 181 # TODO(hungte) use flimflam to update the device list.
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 components = self.force_get_property('get_' + cid) 676 components = self.force_get_property('get_' + cid)
643 if not isinstance(components, list): 677 if not isinstance(components, list):
644 components = [components] 678 components = [components]
645 results[cid] = components 679 results[cid] = components
646 return results 680 return results
647 681
648 def check_enumerable_component(self, cid, exact_values, approved_values): 682 def check_enumerable_component(self, cid, exact_values, approved_values):
649 if '*' in approved_values: 683 if '*' in approved_values:
650 return 684 return
651 685
652 for value in exact_values: 686 unmatched = [value for value in exact_values
653 if value not in approved_values: 687 if value not in approved_values]
654 if cid in self._failures: 688 if not unmatched:
655 self._failures[cid].append(value) 689 return
656 else: 690
657 self._failures[cid] = [value] 691 # there's some error, let's try to match them in legacy list
692 legacy_approved = filter(self.is_legacy_device_record, approved_values)
693 if set(legacy_approved) == set(approved_values):
694 DebugMsg('Start legacy search for cid: ' + cid)
695 # safe for legacy match
696 legacy_list = self._get_legacy_device_list()
697 matched = list(set(legacy_list).intersection(set(approved_values)))
698 if matched:
699 DebugMsg('Changed detected list: %s->%s' % (self._system[cid], matched))
700 self._system[cid] = matched
701 return
702 # update with remaining error.
703 self._failures[cid] = unmatched
658 704
659 @Memorize 705 @Memorize
660 def verify_probable_component(self, cid, approved_values): 706 def verify_probable_component(self, cid, approved_values):
661 if '*' in approved_values: 707 if '*' in approved_values:
662 return (True, ['*']) 708 return (True, ['*'])
663 709
664 for value in approved_values: 710 for value in approved_values:
665 present = getattr(self, 'probe_' + cid)(value) 711 present = getattr(self, 'probe_' + cid)(value)
666 if present: 712 if present:
667 return (True, [value]) 713 return (True, [value])
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 777
732 for arg in args: 778 for arg in args:
733 (matched, failures) = components.match_current_system(arg) 779 (matched, failures) = components.match_current_system(arg)
734 print 'Probed (%s):' % arg 780 print 'Probed (%s):' % arg
735 print components.pformat(matched) 781 print components.pformat(matched)
736 print 'Failures (%s):' % arg 782 print 'Failures (%s):' % arg
737 print components.pformat(failures) 783 print components.pformat(failures)
738 784
739 if __name__ == '__main__': 785 if __name__ == '__main__':
740 _main(sys.argv[0], sys.argv[1:]) 786 _main(sys.argv[0], sys.argv[1:])
OLDNEW
« 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