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 # Don't bother if there is no Chrome EC. 21 if not self.check_ec_capability(): 22 raise error.TestNAError("Nothing needs to be tested on this device") 23 # Only run in normal mode 24 self.switcher.setup_mode('normal') 25 self.ec.send_command("chan 0") 26 27 def cleanup(self): 28 try: 29 self.ec.send_command("chan 0xffffffff") 30 except Exception as e: 31 logging.error("Caught exception: %s", str(e)) 32 super(firmware_ECSharedMem, self).cleanup() 33 34 def shared_mem_checker(self): 35 """Return whether there is still EC shared memory available. 36 """ 37 match = self.ec.send_command_get_output("shmem", 38 ["Size:\s*([0-9-]+)\r"])[0] 39 shmem_size = int(match[1]) 40 logging.info("EC shared memory size is %d bytes", shmem_size) 41 if shmem_size <= 0: 42 return False 43 elif shmem_size <= 256: 44 logging.warning("EC shared memory is less than 256 bytes") 45 return True 46 47 def jump_checker(self): 48 """Check for available EC shared memory after jumping to RW image, if 49 necessary. 50 51 Does not jump to RW if the EC is already in RW or RW_B. 52 """ 53 ec_image = self.servo.get_ec_active_copy() 54 # If we are not currently in RW, switch there first before testing. 55 if ec_image != 'RW' and ec_image != 'RW_B': 56 self.ec.send_command("sysjump RW") 57 time.sleep(self.faft_config.ec_boot_to_console) 58 ec_image = self.servo.get_ec_active_copy() 59 if ec_image != 'RW': 60 raise error.TestFail('Expected EC to be in RW, but was ' + 61 ec_image) 62 return self.shared_mem_checker() 63 64 def run_once(self): 65 """Execute the main body of the test. 66 """ 67 logging.info("Check shared memory in normal operation and crash EC.") 68 self.check_state(self.shared_mem_checker) 69 self.switcher.mode_aware_reboot( 70 'custom', lambda:self.ec.send_command('crash unaligned')) 71 72 logging.info("Check shared memory after crash and system jump.") 73 self.check_state([self.shared_mem_checker, self.jump_checker]) 74 self.switcher.mode_aware_reboot('custom', self.sync_and_ec_reboot) 75