| 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 glob, hashlib, logging, os, pprint, re, sys | 5 import glob, hashlib, logging, os, pprint, re, sys |
| 6 from autotest_lib.client.bin import factory | 6 from autotest_lib.client.bin import factory |
| 7 from autotest_lib.client.bin import test, utils | 7 from autotest_lib.client.bin import test, utils |
| 8 from autotest_lib.client.common_lib import error | 8 from autotest_lib.client.common_lib import error |
| 9 from autotest_lib.client.common_lib import flashrom_util | 9 from autotest_lib.client.common_lib import flashrom_util |
| 10 from autotest_lib.client.common_lib import gbb_util | 10 from autotest_lib.client.common_lib import gbb_util |
| 11 from autotest_lib.client.common_lib import site_fmap | 11 from autotest_lib.client.common_lib import site_fmap |
| 12 from autotest_lib.client.common_lib import site_vblock | 12 from autotest_lib.client.common_lib import site_vblock |
| 13 | 13 |
| 14 | 14 |
| 15 class hardware_Components(test.test): | 15 class hardware_Components(test.test): |
| 16 version = 1 | 16 version = 1 |
| 17 _cids = [ | 17 _cids = [ |
| 18 'data_display_geometry', | 18 'data_display_geometry', |
| 19 'hash_ec_firmware', |
| 19 'hash_ro_firmware', | 20 'hash_ro_firmware', |
| 20 'part_id_audio_codec', | 21 'part_id_audio_codec', |
| 21 'part_id_cpu', | 22 'part_id_cpu', |
| 22 'part_id_display_panel', | 23 'part_id_display_panel', |
| 23 'part_id_embedded_controller', | 24 'part_id_embedded_controller', |
| 24 'part_id_ethernet', | 25 'part_id_ethernet', |
| 25 'part_id_flash_chip', | 26 'part_id_flash_chip', |
| 26 'part_id_hwqual', | 27 'part_id_hwqual', |
| 27 'part_id_storage', | 28 'part_id_storage', |
| 28 'part_id_wireless', | 29 'part_id_wireless', |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 Returns a colon delimited string where the first section | 240 Returns a colon delimited string where the first section |
| 240 is the vendor id and the second section is the device id. | 241 is the vendor id and the second section is the device id. |
| 241 """ | 242 """ |
| 242 part_id = utils.read_one_line('/sys/class/net/wlan0/device/device') | 243 part_id = utils.read_one_line('/sys/class/net/wlan0/device/device') |
| 243 vendor_id = utils.read_one_line('/sys/class/net/wlan0/device/vendor') | 244 vendor_id = utils.read_one_line('/sys/class/net/wlan0/device/vendor') |
| 244 return "%s:%s" % (vendor_id.replace('0x',''), part_id.replace('0x','')) | 245 return "%s:%s" % (vendor_id.replace('0x',''), part_id.replace('0x','')) |
| 245 | 246 |
| 246 | 247 |
| 247 def get_closed_vendor_id_touchpad(self, vendor_name): | 248 def get_closed_vendor_id_touchpad(self, vendor_name): |
| 248 """ | 249 """ |
| 249 Using closed-source method to derive the vendor information | 250 Using closed-source method to derive the vendor information |
| 250 given the vendor name. | 251 given the vendor name. |
| 251 """ | 252 """ |
| 252 part_id = '' | 253 part_id = '' |
| 253 if vendor_name.lower() == 'synaptics': | 254 if vendor_name.lower() == 'synaptics': |
| 254 # Turn off raw mode in order to show touch pad as input | 255 # Turn off raw mode in order to show touch pad as input |
| 255 script_set_raw = '/opt/Synaptics/bin/synset' | 256 script_set_raw = '/opt/Synaptics/bin/synset' |
| 256 redirect_std_1_2 = '> /dev/null 2>&1' | 257 redirect_std_1_2 = '> /dev/null 2>&1' |
| 257 if not os.path.exists(script_set_raw): | 258 if not os.path.exists(script_set_raw): |
| 258 return part_id | 259 return part_id |
| 259 cmd_disable_raw = ' '.join([script_set_raw, 'stop', \ | 260 cmd_disable_raw = ' '.join([script_set_raw, 'stop', \ |
| 260 redirect_std_1_2]) | 261 redirect_std_1_2]) |
| 261 utils.system(cmd_disable_raw, ignore_status=True) | 262 utils.system(cmd_disable_raw, ignore_status=True) |
| 262 | 263 |
| 263 # Now we can capture touch pad input under /sys/class/input | 264 # Now we can capture touch pad input under /sys/class/input |
| 264 touchpad_input_path = '/sys/class/input/' | 265 touchpad_input_path = '/sys/class/input/' |
| 265 input_dirs = os.listdir(touchpad_input_path) | 266 input_dirs = os.listdir(touchpad_input_path) |
| 266 part_ids = [] | 267 part_ids = [] |
| 267 for input_dir in input_dirs: | 268 for input_dir in input_dirs: |
| 268 if not input_dir.startswith('input'): | 269 if not input_dir.startswith('input'): |
| 269 continue | 270 continue |
| 270 fname = os.path.join(touchpad_input_path, input_dir, 'name') | 271 fname = os.path.join(touchpad_input_path, input_dir, 'name') |
| 271 input_id = utils.read_file(fname) | 272 input_id = utils.read_file(fname) |
| 272 if input_id.startswith('SynPS'): | 273 if input_id.startswith('SynPS'): |
| 273 part_ids.append(input_id.strip()) | 274 part_ids.append(input_id.strip()) |
| 274 part_id = ",".join(part_ids) | 275 part_id = ",".join(part_ids) |
| 275 | 276 |
| 276 # Turn on raw mode again | 277 # Turn on raw mode again |
| 277 cmd_enable_raw = ' '.join([script_set_raw, 'start', \ | 278 cmd_enable_raw = ' '.join([script_set_raw, 'start', \ |
| 278 redirect_std_1_2]) | 279 redirect_std_1_2]) |
| 279 utils.system(cmd_enable_raw) | 280 utils.system(cmd_enable_raw) |
| 280 return part_id | 281 return part_id |
| 281 | 282 |
| 282 | 283 |
| 283 def get_vendor_id_touchpad(self): | 284 def get_vendor_id_touchpad(self): |
| 284 # First, try to use closed-source method to probe touch pad | 285 # First, try to use closed-source method to probe touch pad |
| 285 part_id = self.get_closed_vendor_id_touchpad('Synaptics') | 286 part_id = self.get_closed_vendor_id_touchpad('Synaptics') |
| 286 if part_id != '': | 287 if part_id != '': |
| 287 return part_id | 288 return part_id |
| 288 # If the closed-source method above fails to find vendor infomation, | 289 # If the closed-source method above fails to find vendor infomation, |
| 289 # try an open-source method. | 290 # try an open-source method. |
| 290 else:» | 291 else: |
| 291 cmd_grep = 'grep -i Touchpad /proc/bus/input/devices | sed s/.\*=//' | 292 cmd_grep = 'grep -i Touchpad /proc/bus/input/devices | sed s/.\*=//' |
| 292 part_id = utils.system_output(cmd_grep).strip('"') | 293 part_id = utils.system_output(cmd_grep).strip('"') |
| 293 return part_id | 294 return part_id |
| 294 | 295 |
| 295 | 296 |
| 296 def get_vendor_id_webcam(self): | 297 def get_vendor_id_webcam(self): |
| 297 cmd = 'cat /sys/class/video4linux/video0/name' | 298 cmd = 'cat /sys/class/video4linux/video0/name' |
| 298 part_id = utils.system_output(cmd).strip() | 299 part_id = utils.system_output(cmd).strip() |
| 299 return part_id | 300 return part_id |
| 300 | 301 |
| 301 | 302 |
| 302 def get_hash_ro_firmware(self): | 303 def get_hash_ro_firmware(self): |
| 303 """ | 304 """ |
| 304 Returns a hash of Read Only firmware parts, | 305 Returns a hash of Read Only (BIOS) firmware parts, |
| 305 to confirm we have proper keys / boot code / recovery image installed. | 306 to confirm we have proper keys / boot code / recovery image installed. |
| 306 """ | 307 """ |
| 307 # hash_ro_list: RO section to be hashed | 308 # hash_ro_list: RO section to be hashed |
| 308 hash_ro_list = ['FV_BSTUB', 'FV_GBB', 'FVDEV'] | 309 hash_ro_list = ['FV_BSTUB', 'FV_GBB', 'FVDEV'] |
| 309 flashrom = flashrom_util.flashrom_util() | 310 flashrom = flashrom_util.flashrom_util() |
| 310 if not flashrom.select_bios_flashrom(): | 311 if not flashrom.select_bios_flashrom(): |
| 311 raise error.TestError('Cannot select BIOS flashrom') | 312 raise error.TestError('Cannot select BIOS flashrom') |
| 312 base_img = flashrom.read_whole() | 313 base_img = flashrom.read_whole() |
| 313 flashrom_size = len(base_img) | 314 flashrom_size = len(base_img) |
| 314 # XXX Allowing the FMAP to override our default layout may be an exploit | 315 # XXX Allowing the FMAP to override our default layout may be an exploit |
| (...skipping 11 matching lines...) Expand all Loading... |
| 326 for section in hash_ro_list: | 327 for section in hash_ro_list: |
| 327 src = flashrom.get_section(base_img, layout, section) | 328 src = flashrom.get_section(base_img, layout, section) |
| 328 if not src: | 329 if not src: |
| 329 raise error.TestError('Cannot get section [%s] from flashrom' % | 330 raise error.TestError('Cannot get section [%s] from flashrom' % |
| 330 section) | 331 section) |
| 331 hash_src = hash_src + src | 332 hash_src = hash_src + src |
| 332 if not hash_src: | 333 if not hash_src: |
| 333 raise error.TestError('Invalid hash source from flashrom.') | 334 raise error.TestError('Invalid hash source from flashrom.') |
| 334 return hashlib.sha256(hash_src).hexdigest() | 335 return hashlib.sha256(hash_src).hexdigest() |
| 335 | 336 |
| 337 def get_hash_ec_firmware(self): |
| 338 """ |
| 339 Returns a hash of Embedded Controller firmware parts, |
| 340 to confirm we have proper updated version of EC firmware. |
| 341 """ |
| 342 flashrom = flashrom_util.FlashromUtility() |
| 343 flashrom.initialize(flashrom.TARGET_EC) |
| 344 # to bypass the 'skip verification' sections |
| 345 image = flashrom.get_current_image() |
| 346 hash_src = flashrom.get_verification_image(image) |
| 347 return hashlib.sha256(hash_src).hexdigest() |
| 336 | 348 |
| 337 def get_version_rw_firmware(self): | 349 def get_version_rw_firmware(self): |
| 338 """ | 350 """ |
| 339 Returns the version of Read-Write (writable) firmware from VBOOT | 351 Returns the version of Read-Write (writable) firmware from VBOOT |
| 340 section. If A/B has different version, that means this system | 352 section. If A/B has different version, that means this system |
| 341 needs a reboot + firmwar update so return value is a "error report" | 353 needs a reboot + firmwar update so return value is a "error report" |
| 342 in the form "A=x, B=y". | 354 in the form "A=x, B=y". |
| 343 """ | 355 """ |
| 344 versions = [None, None] | 356 versions = [None, None] |
| 345 section_names = ['VBOOTA', 'VBOOTB'] | 357 section_names = ['VBOOTA', 'VBOOTB'] |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 cids_need_to_be_record = ['part_id_hwqual'] | 450 cids_need_to_be_record = ['part_id_hwqual'] |
| 439 for cid in cids_need_to_be_record: | 451 for cid in cids_need_to_be_record: |
| 440 factory.log_shared_data(cid, self._approved[cid][0]) | 452 factory.log_shared_data(cid, self._approved[cid][0]) |
| 441 return | 453 return |
| 442 | 454 |
| 443 if only_cardreader_failed: | 455 if only_cardreader_failed: |
| 444 all_failures = ('You may forget to insert an SD card.\n' + | 456 all_failures = ('You may forget to insert an SD card.\n' + |
| 445 all_failures) | 457 all_failures) |
| 446 | 458 |
| 447 raise error.TestFail(repr(all_failures)) | 459 raise error.TestFail(repr(all_failures)) |
| OLD | NEW |