• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2018 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.server.cros.faft.firmware_test import FirmwareTest
8
9
10class firmware_WriteProtect(FirmwareTest):
11    """
12    This test checks whether the hardware write-protect state reported by
13    crossystem matches the real write-protect state driven by Servo.
14    """
15    version = 1
16
17    def initialize(self, host, cmdline_args, dev_mode=False):
18        """Initialize the test"""
19        super(firmware_WriteProtect, self).initialize(host, cmdline_args)
20        self.switcher.setup_mode('dev' if dev_mode else 'normal')
21        self._original_wp = 'on' in self.servo.get('fw_wp_state')
22
23    def cleanup(self):
24        """Cleanup the test"""
25        try:
26            if hasattr(self, '_original_wp'):
27                self.set_ap_write_protect_and_reboot(self._original_wp)
28        except Exception as e:
29            logging.error('Caught exception: %s', str(e))
30        super(firmware_WriteProtect, self).cleanup()
31
32    def run_once(self):
33        """Runs a single iteration of the test."""
34        logging.info('Enable write-protect.')
35        self.set_ap_write_protect_and_reboot(True)
36        self.check_state((self.checkers.crossystem_checker, {'wpsw_cur': '1'}))
37        logging.info('Now disable write-protect and check again.')
38        self.set_ap_write_protect_and_reboot(False)
39        self.check_state((self.checkers.crossystem_checker, {'wpsw_cur': '0'}))
40        logging.info('Enable write-protect again to check final state.')
41        self.set_ap_write_protect_and_reboot(True)
42        self.check_state((self.checkers.crossystem_checker, {'wpsw_cur': '1'}))
43