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
6
7from autotest_lib.client.common_lib import utils
8from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
9
10
11class firmware_CgptStress(FirmwareTest):
12    """
13    Servo based, iterative cgpt test. One iteration of test modifies CGPT to
14    switch to boot kernel B and then switch back to kernel A again.
15    """
16    version = 1
17
18    def initialize(self, host, cmdline_args, dev_mode):
19        # Parse arguments from command line
20        dict_args = utils.args_to_dict(cmdline_args)
21        self.faft_iterations = int(dict_args.get('faft_iterations', 1))
22        super(firmware_CgptStress, self).initialize(host, cmdline_args)
23        self.backup_cgpt_attributes()
24        self.switcher.setup_mode('dev' if dev_mode else 'normal')
25        self.setup_usbkey(usbkey=False)
26        self.setup_kernel('a')
27
28    def cleanup(self):
29        self.restore_cgpt_attributes()
30        super(firmware_CgptStress, self).cleanup()
31
32    def run_once(self):
33        for i in xrange(self.faft_iterations):
34            logging.info('======== Running FAFT ITERATION %d/%s ========',
35                         i + 1, self.faft_iterations)
36            logging.info("Expected kernel A boot and prioritize kernel B.")
37            self.check_state((self.checkers.root_part_checker, 'a'))
38            self.reset_and_prioritize_kernel('b')
39            self.switcher.mode_aware_reboot()
40
41            logging.info("Expected kernel B boot and prioritize kernel A.")
42            self.check_state((self.checkers.root_part_checker, 'b'))
43            self.reset_and_prioritize_kernel('a')
44            self.switcher.mode_aware_reboot()
45
46            logging.info("Expected kernel A boot, done.")
47            self.check_state((self.checkers.root_part_checker, 'a'))
48