1# Copyright (c) 2012 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 6from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 7from autotest_lib.client.common_lib import error 8 9 10class firmware_UpdateKernelVersion(FirmwareTest): 11 """ 12 This is a server based kernel update test which should run in developer 13 mode. On runtime, this test modifies the kernel version of kernel b and 14 modifies cgpt to reboot with kernel b. Check kernel version after reboot, 15 and then recover kernel b version to original version. Here also tries to 16 reboot with kernel b after recovery. If success, reboot with kernel a. 17 """ 18 version = 1 19 20 def check_kernel_version(self, expected_ver): 21 """Checks the kernel version.""" 22 actual_ver = self.faft_client.kernel.get_version('b') 23 if actual_ver != expected_ver: 24 raise error.TestFail( 25 'Kernel Version should be %s, but got %s.' 26 % (expected_ver, actual_ver)) 27 else: 28 logging.info( 29 'Update success, now version is %s', 30 actual_ver) 31 32 def modify_kernel_b_and_set_cgpt_priority(self, delta, target_dev): 33 """Modifies kernel B and sets CGPT priority.""" 34 if delta == 1: 35 self.faft_client.kernel.move_version_forward('b') 36 elif delta == -1: 37 self.check_kernel_version(self._update_version) 38 self.faft_client.kernel.move_version_backward('b') 39 40 if target_dev == 'a': 41 self.reset_and_prioritize_kernel('a') 42 else: 43 self.reset_and_prioritize_kernel('b') 44 45 def initialize(self, host, cmdline_args, dev_mode=True): 46 """Initialize the test""" 47 super(firmware_UpdateKernelVersion, self).initialize(host, cmdline_args) 48 49 self.switcher.setup_mode('dev' if dev_mode else 'normal') 50 51 actual_ver = self.faft_client.kernel.get_version('b') 52 logging.info('Original Kernel Version of KERN-B is %s', actual_ver) 53 54 self._update_version = actual_ver + 1 55 logging.info('KERN-B will update to version %s', self._update_version) 56 57 self.setup_kernel('a') 58 59 def cleanup(self): 60 """Cleanup after the test""" 61 super(firmware_UpdateKernelVersion, self).cleanup() 62 63 def run_once(self): 64 """Runs a single iteration of the test.""" 65 logging.info("Update Kernel Version.") 66 self.check_state((self.check_root_part_on_non_recovery, 'a')) 67 self.modify_kernel_b_and_set_cgpt_priority(1, 'b') 68 self.switcher.mode_aware_reboot() 69 70 logging.info("Check kernel version and rollback.") 71 self.check_state((self.check_root_part_on_non_recovery, 'b')) 72 self.modify_kernel_b_and_set_cgpt_priority(-1, 'b') 73 self.switcher.mode_aware_reboot() 74 75 logging.info("Boot with rollback kernel and change boot priority.") 76 self.check_state((self.check_root_part_on_non_recovery, 'b')) 77 self.modify_kernel_b_and_set_cgpt_priority(0, 'a') 78 self.switcher.mode_aware_reboot() 79 80 logging.info("Check rollback version.") 81 self.check_state((self.check_root_part_on_non_recovery, 'a')) 82 self.check_kernel_version(self._update_version - 1) 83