# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging

from autotest_lib.server.cros.faft.firmware_test import FirmwareTest


class firmware_CorruptKernelB(FirmwareTest):
    """
    Servo based kernel B corruption test.

    This test sets kernel B boot and then corrupts kernel B. The firmware
    verifies kernel B failed so falls back to kernel A boot. This test will
    fail if kernel verification mis-behaved.
    """
    version = 1

    def initialize(self, host, cmdline_args, dev_mode=False):
        super(firmware_CorruptKernelB, self).initialize(host, cmdline_args)
        self.backup_kernel()
        self.backup_cgpt_attributes()
        self.switcher.setup_mode('dev' if dev_mode else 'normal')
        self.setup_usbkey(usbkey=False)
        self.setup_kernel('a')

    def cleanup(self):
        try:
            self.restore_cgpt_attributes()
            self.restore_kernel()
        except Exception as e:
            logging.error("Caught exception: %s", str(e))
        super(firmware_CorruptKernelB, self).cleanup()

    def run_once(self, dev_mode=False):
        """Runs a single iteration of the test."""
        logging.info("Prioritize kernel B.")
        self.check_state((self.checkers.root_part_checker, 'a'))
        self.reset_and_prioritize_kernel('b')
        self.switcher.mode_aware_reboot()

        logging.info("Expected kernel B boot and corrupt kernel B.")
        self.check_state((self.checkers.root_part_checker, 'b'))
        self.faft_client.Kernel.CorruptSig('b')
        self.switcher.mode_aware_reboot()

        logging.info("Expected kernel A boot and restore kernel B.")
        self.check_state((self.checkers.root_part_checker, 'a'))
        self.faft_client.Kernel.RestoreSig('b')
        self.switcher.mode_aware_reboot()

        logging.info("Expected kernel B boot and prioritize kerenl A.")
        self.check_state((self.checkers.root_part_checker, 'b'))
        self.reset_and_prioritize_kernel('a')
        self.switcher.mode_aware_reboot()

        logging.info("Expected kernel A boot.")
        self.check_state((self.checkers.root_part_checker, 'a'))
