Home | History | Annotate | Download | only in firmware_ECKeyboard
      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 
      5 import logging
      6 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
     10 
     11 
     12 class firmware_ECKeyboard(FirmwareTest):
     13     """
     14     Servo based EC keyboard test.
     15     """
     16     version = 1
     17 
     18     # Delay between commands
     19     CMD_DELAY = 1
     20 
     21     # Delay to wait until developer console is open.
     22     DEV_CONSOLE_DELAY = 2
     23 
     24     def initialize(self, host, cmdline_args):
     25         super(firmware_ECKeyboard, self).initialize(host, cmdline_args)
     26         # Only run in normal mode
     27         self.switcher.setup_mode('normal')
     28 
     29     def switch_tty2(self):
     30         """Switch to tty2 console."""
     31         self.ec.key_down('<ctrl_l>')
     32         self.ec.key_down('<alt_l>')
     33         self.ec.key_down('<f2>')
     34         self.ec.key_up('<f2>')
     35         self.ec.key_up('<alt_l>')
     36         self.ec.key_up('<ctrl_l>')
     37         time.sleep(self.DEV_CONSOLE_DELAY)
     38 
     39     def reboot_by_keyboard(self):
     40         """
     41         Simulate key press sequence to log into console and then issue reboot
     42         command.
     43         """
     44         self.switch_tty2()
     45         self.ec.send_key_string('root<enter>')
     46         time.sleep(self.CMD_DELAY)
     47         self.ec.send_key_string('test0000<enter>')
     48         time.sleep(self.CMD_DELAY)
     49         self.ec.send_key_string('reboot<enter>')
     50 
     51     def run_once(self):
     52         if not self.check_ec_capability(['keyboard']):
     53             raise error.TestNAError("Nothing needs to be tested on this device")
     54 
     55         logging.info("Use key press simulation to issue reboot command.")
     56         self.switcher.mode_aware_reboot('custom', self.reboot_by_keyboard)
     57