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 6import time 7 8from autotest_lib.client.common_lib import error 9from autotest_lib.server.cros.faft.firmware_test import FirmwareTest 10 11 12class firmware_ECSharedMem(FirmwareTest): 13 """ 14 Servo based EC shared memory test. 15 """ 16 version = 1 17 18 def initialize(self, host, cmdline_args): 19 super(firmware_ECSharedMem, self).initialize(host, cmdline_args) 20 # Only run in normal mode 21 self.switcher.setup_mode('normal') 22 self.ec.send_command("chan 0") 23 24 def cleanup(self): 25 try: 26 self.ec.send_command("chan 0xffffffff") 27 except Exception as e: 28 logging.error("Caught exception: %s", str(e)) 29 super(firmware_ECSharedMem, self).cleanup() 30 31 def shared_mem_checker(self): 32 match = self.ec.send_command_get_output("shmem", 33 ["Size:\s+([0-9-]+)\r"])[0] 34 shmem_size = int(match[1]) 35 logging.info("EC shared memory size if %d bytes", shmem_size) 36 if shmem_size <= 0: 37 return False 38 elif shmem_size <= 256: 39 logging.warning("EC shared memory is less than 256 bytes") 40 return True 41 42 def jump_checker(self): 43 self.ec.send_command("sysjump RW") 44 time.sleep(self.faft_config.ec_boot_to_console) 45 return self.shared_mem_checker() 46 47 def run_once(self): 48 if not self.check_ec_capability(): 49 raise error.TestNAError("Nothing needs to be tested on this device") 50 51 logging.info("Check shared memory in normal operation and crash EC.") 52 self.check_state(self.shared_mem_checker) 53 self.switcher.mode_aware_reboot( 54 'custom', lambda:self.ec.send_command('crash unaligned')) 55 56 logging.info("Check shared memory after crash and system jump.") 57 self.check_state([self.shared_mem_checker, self.jump_checker]) 58 self.switcher.mode_aware_reboot('custom', self.sync_and_ec_reboot) 59