1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import os, re 6 7from autotest_lib.client.bin import test, utils 8from autotest_lib.client.common_lib import error 9 10class hardware_DiskFirmwareUpgrade(test.test): 11 """ 12 Run the disk firmware upgrade script. 13 """ 14 TEST_SCRIPT = '/usr/sbin/chromeos-disk-firmware-update.sh' 15 UPGRADED_RE = r'^Upgraded.*' 16 version = 1 17 18 def run_once(self, 19 disk_firmware_package='/opt/google/disk/firmware', 20 expected_result=0, 21 upgrade_required=True): 22 """ 23 Runs the shell script that upgrade disk firmware. 24 25 @param disk_firmware_package: pre-installed firmware package location. 26 @param expected_result: expected results of the upgrade. 27 @param upgrade_required: if True, the firmware must change on the 28 device. 29 """ 30 status_file = os.path.join(self.resultsdir, 'status') 31 cmd = [self.TEST_SCRIPT, 32 '--status %s' % (status_file), 33 '--fw_package_dir %s' % (disk_firmware_package)] 34 fw_upgrade = utils.run(' '.join(cmd), ignore_status=True) 35 36 # Check the result of the upgrade. 37 upgrade_happened = False 38 try: 39 with open(status_file) as sf: 40 for l in sf: 41 if re.match(self.UPGRADED_RE, l): 42 upgrade_happened = True 43 except IOError: 44 pass 45 if fw_upgrade.exit_status != expected_result: 46 raise error.TestError( 47 'Expected %d Result is %d' % ( 48 expected_result, fw_upgrade.exit_status)) 49 if (fw_upgrade.exit_status == 0 and 50 upgrade_required and not upgrade_happened): 51 raise error.TestError('Expected upgrade did not happened') 52