1# Copyright (c) 2011 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 logging 6import os 7 8from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 9 10 11class firmware_ShellBall(FirmwareTest): 12 """ 13 chromeos-firmwareupdate functional tests. 14 15 Checks the mode condition and enables or disables developement mode 16 accordingly and runs all shellball functioanl tests. 17 """ 18 version = 1 19 20 _shellball_name = None 21 22 def update_firmware(self, mode): 23 self.faft_client.system.run_shell_command('%s --mode %s' % 24 (self._shellball_name, mode)) 25 # Enalbe dev mode if the mode is todev. 26 if mode == 'todev': 27 self.servo.enable_development_mode() 28 # Disable dev mode if the mode is tonormal. 29 elif mode == 'tonormal': 30 self.servo.disable_development_mode() 31 32 def install_original_firmware(self): 33 self.faft_client.system.run_shell_command( 34 'sudo chromeos-firmwareupdate --mode=factory_install') 35 self.invalidate_firmware_setup() 36 37 def initialize(self, host, cmdline_args, shellball_path=None, 38 shellball_name=None): 39 super(firmware_ShellBall, self).initialize(host, cmdline_args) 40 self._shellball_name = "/home/chronos/%s" % self._shellball_name 41 host.send_file("%s/%s" % (shellball_path, shellball_name), 42 self._shellball_name) 43 self.faft_client.system.run_shell_command('chmod +x %s' % 44 self._shellball_name) 45 self.switcher.setup_mode('normal') 46 # Get crossystem fwid. 47 [self._current_fwid] = ( 48 self.faft_client.system.run_shell_command_get_output( 49 'crossystem fwid')) 50 # Get BIOS version from shellball. 51 [self._shellball_fwid] = self.faft_client. \ 52 system.run_shell_command_get_output( 53 '%s -V | grep "BIOS version"' 54 ' | sed "s/BIOS version: ' 55 '\(.*\)/\\1/" ' 56 % self._shellball_name) 57 58 def cleanup(self): 59 if os.path.exists(self._shellball_name): 60 os.remove(self._shellball_name) 61 super(firmware_ShellBall, self).cleanup() 62 63 def run_once(self): 64 logging.info("Change to devmode.") 65 self.check_state((self.checkers.crossystem_checker, 66 {'dev_boot_usb': '0'})) 67 self.update_firmware('todev') 68 self.switcher.mode_aware_reboot() 69 70 logging.info("Check mainfw_type and run autoupdate.") 71 self.check_state((self.checkers.crossystem_checker, 72 {'mainfw_type': 'developer'})) 73 self.update_firmware('autoupdate') 74 self.switcher.mode_aware_reboot() 75 76 logging.info("Verify fwid and install system firmware.") 77 self.check_state((self.checkers.crossystem_checker, 78 {'fwid': self._shellball_fwid})) 79 self.install_original_firmware() 80 self.switcher.mode_aware_reboot() 81 82 logging.info("Verify the old firmware id and test factory_install.") 83 self.check_state((self.checkers.crossystem_checker, 84 {'fwid': self._current_fwid})) 85 self.update_firmware('factory_install') 86 self.switcher.mode_aware_reboot() 87 88 logging.info("Verify fwid and install original firmware.") 89 self.check_state((self.checkers.crossystem_checker, 90 {'fwid': self._shellball_fwid})) 91 self.install_original_firmware() 92 self.switcher.mode_aware_reboot() 93 94 logging.info("Verify old fwid.") 95 self.check_state((self.checkers.crossystem_checker, 96 {'fwid': self._current_fwid})) 97