OLD | NEW |
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import logging, os, pprint, re | 5 import logging, os, pprint, re |
6 from autotest_lib.client.bin import test, utils | 6 from autotest_lib.client.bin import test, utils |
7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
8 | 8 |
9 | 9 |
10 class hardware_Components(test.test): | 10 class hardware_Components(test.test): |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return part_id | 89 return part_id |
90 | 90 |
91 | 91 |
92 def get_part_id_ethernet(self): | 92 def get_part_id_ethernet(self): |
93 """ | 93 """ |
94 Returns a colon delimited string where the first section | 94 Returns a colon delimited string where the first section |
95 is the vendor id and the second section is the device id. | 95 is the vendor id and the second section is the device id. |
96 """ | 96 """ |
97 # Ethernet is optional so mark it as not present. A human | 97 # Ethernet is optional so mark it as not present. A human |
98 # operator needs to decide if this is acceptable or not. | 98 # operator needs to decide if this is acceptable or not. |
99 if not os.path.exists('/sys/class/net/eth0'): | 99 vendor_file = '/sys/class/net/eth0/device/vendor' |
100 return self._not_present | 100 part_file = '/sys/class/net/eth0/device/device' |
101 part_id = utils.read_one_line('/sys/class/net/eth0/device/device') | 101 if os.path.exists(part_file) and os.path.exists(vendor_file): |
102 vendor_id = utils.read_one_line('/sys/class/net/eth0/device/vendor') | 102 vendor_id = utils.read_one_line(vendor_file).replace('0x', '') |
103 return "%s:%s" % (vendor_id.replace('0x',''), part_id.replace('0x','')) | 103 part_id = utils.read_one_line(part_file).replace('0x', '') |
| 104 return "%s:%s" % (vendor_id, part_id) |
| 105 else: |
| 106 return self._not_present |
104 | 107 |
105 | 108 |
106 def get_part_id_flash_chip(self): | 109 def get_part_id_flash_chip(self): |
107 # example output: | 110 # example output: |
108 # Found chip "Winbond W25x16" (2048 KB, FWH) at physical address 0xfe | 111 # Found chip "Winbond W25x16" (2048 KB, FWH) at physical address 0xfe |
109 parts = [] | 112 parts = [] |
110 lines = utils.system_output('flashrom', ignore_status=True).split('\n') | 113 lines = utils.system_output('flashrom', ignore_status=True).split('\n') |
111 for line in lines: | 114 for line in lines: |
112 match = re.search(r'Found chip "(.*)" .* at physical address ', line) | 115 match = re.search(r'Found chip "(.*)" .* at physical address ', line) |
113 if match: | 116 if match: |
(...skipping 28 matching lines...) Expand all Loading... |
142 if not self._approved.has_key(cid): | 145 if not self._approved.has_key(cid): |
143 raise error.TestFail('%s missing from database' % cid) | 146 raise error.TestFail('%s missing from database' % cid) |
144 | 147 |
145 approved_devices = self._approved[cid] | 148 approved_devices = self._approved[cid] |
146 if '*' in approved_devices: | 149 if '*' in approved_devices: |
147 self._system[cid] = [ '*' ] | 150 self._system[cid] = [ '*' ] |
148 return | 151 return |
149 | 152 |
150 for device in approved_devices: | 153 for device in approved_devices: |
151 try: | 154 try: |
152 utils.system(cmd % device) | 155 output = utils.system_output(cmd % device) |
153 self._system[cid] = [ device ] | 156 # If it shows something, means found. |
154 return | 157 if output: |
| 158 self._system[cid] = [ device ] |
| 159 return |
155 except: | 160 except: |
156 pass | 161 pass |
157 self._failures[cid] = [ 'No match' ] | 162 self._failures[cid] = [ 'No match' ] |
158 | 163 |
159 | 164 |
160 def get_vendor_id_touchpad(self): | 165 def get_vendor_id_touchpad(self): |
161 cmd = 'grep -i Touchpad /proc/bus/input/devices | sed s/.\*=//' | 166 cmd = 'grep -i Touchpad /proc/bus/input/devices | sed s/.\*=//' |
162 part_id = utils.system_output(cmd).strip('"') | 167 part_id = utils.system_output(cmd).strip('"') |
163 return part_id | 168 return part_id |
164 | 169 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 for cid in self._usb_cids: | 203 for cid in self._usb_cids: |
199 self.check_approved_part_id_existence(cid, type='usb') | 204 self.check_approved_part_id_existence(cid, type='usb') |
200 | 205 |
201 logging.debug('System: %s', self.pformat(self._system)) | 206 logging.debug('System: %s', self.pformat(self._system)) |
202 | 207 |
203 outdb = os.path.join(self.resultsdir, 'system_components') | 208 outdb = os.path.join(self.resultsdir, 'system_components') |
204 utils.open_write_close(outdb, self.pformat(self._system)) | 209 utils.open_write_close(outdb, self.pformat(self._system)) |
205 | 210 |
206 if self._failures: | 211 if self._failures: |
207 raise error.TestFail(self.pformat(self._failures)) | 212 raise error.TestFail(self.pformat(self._failures)) |
OLD | NEW |