• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2020 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 error
8from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
9
10class firmware_FAFTModeTransitions(FirmwareTest):
11    """This test checks FAFT mode transitions work."""
12    version = 1
13    NEEDS_SERVO_USB = True
14
15    def _checked_reboot(self, to_mode):
16        """Reboots DUT to mode and checks that it has done so.
17
18        @param to_mode: mode_switcher mode to reboot into
19        @type to_mode: string
20
21        @see: autotest_lib.server.cros.faft.utils.mode_switcher
22        """
23        self.switcher.reboot_to_mode(to_mode)
24        boot_mode = self.faft_client.system.get_boot_mode()
25        if boot_mode != to_mode:
26            raise error.TestFail("Expected boot mode %s, got %s" %
27                                 (to_mode, boot_mode))
28
29    def run_once(self, mode_seq=[]):
30        """Main test logic.
31
32        @param mode_seq: A list of mode_switcher modes to transition through
33        @type mode_seq: list of strings
34
35        @see: autotest_lib.server.cros.faft.utils.mode_switcher
36        """
37
38        if len(mode_seq) < 2:
39            raise ValueError("Not enough transitions to test: %s" % mode_seq)
40
41        logging.info("Testing transition sequence: %s",  " -> ".join(mode_seq))
42
43        if 'rec' in mode_seq:
44            logging.info("Mode sequence contains 'rec', setup USB stick with"
45                         " image.")
46            self.setup_usbkey(usbkey=True)
47
48        m1 = mode_seq[0]
49
50        logging.info("Start in %s mode.", m1)
51        self.switcher.setup_mode(m1)
52
53        for m2 in mode_seq[1:]:
54            logging.info("Checking mode transition: %s -> %s.", m1, m2)
55            self._checked_reboot(m2)
56            m1 = m2
57