1# Copyright 2019 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.cr50_test import Cr50Test 10 11 12class firmware_Cr50RddG3(Cr50Test): 13 """Verify Rdd connect and disconnect in G3.""" 14 version = 1 15 16 WAIT_FOR_STATE = 10 17 # Cr50 debounces disconnects. We need to wait before checking Rdd state 18 RDD_DEBOUNCE = 3 19 20 def rdd_is_connected(self): 21 """Return True if Cr50 detects Rdd.""" 22 time.sleep(2) 23 return self.cr50.get_ccdstate()['Rdd'] == 'connected' 24 25 26 def check_rdd_status(self, dts_mode, err_desc, capability=''): 27 """Check the rdd state. 28 29 @param dts_mode: 'on' if Rdd should be connected. 'off' if it should be 30 disconnected. 31 @param err_desc: Description of the rdd error. 32 @param capability: ignore err_desc if this capability string is found in 33 the faft board config. 34 @param raises TestFail if rdd state doesn't match the expected rdd state 35 or if it does and the board has the capability set. 36 """ 37 time.sleep(self.RDD_DEBOUNCE) 38 err_msg = None 39 rdd_enabled = self.rdd_is_connected() 40 logging.info('dts: %r rdd: %r', dts_mode, 41 'connected' if rdd_enabled else 'disconnected') 42 has_cap = capability and self.check_cr50_capability([capability]) 43 if rdd_enabled != (dts_mode == 'on'): 44 if has_cap: 45 logging.info('Found %r. %r still applies to board.', capability, 46 err_desc) 47 else: 48 err_msg = err_desc 49 elif has_cap: 50 err_msg = 'Found %r, but %r did not occur.' % (capability, err_desc) 51 if err_msg: 52 logging.warning(err_msg) 53 self.rdd_failures.append(err_msg) 54 55 56 def run_once(self): 57 """Verify Rdd in G3.""" 58 self.rdd_failures = [] 59 if not hasattr(self, 'ec'): 60 raise error.TestNAError('Board does not have an EC.') 61 62 self.servo.set_dts_mode('on') 63 self.check_rdd_status('on', 'Cr50 did not detect Rdd with dts mode on') 64 65 self.servo.set_dts_mode('off') 66 self.check_rdd_status('off', 'Cr50 did not detect Rdd disconnect in S0') 67 68 logging.info('Checking Rdd is disconnected with the EC in hibernate') 69 self.faft_client.system.run_shell_command('poweroff') 70 time.sleep(self.WAIT_FOR_STATE) 71 self.ec.send_command('hibernate') 72 time.sleep(self.WAIT_FOR_STATE) 73 74 self.check_rdd_status('off', 'Rdd connected after EC hibernate', 75 'rdd_leakage') 76 77 logging.info('Checking Rdd can be connected in G3.') 78 self.servo.set_dts_mode('on') 79 self.check_rdd_status('on', 'Cr50 did not detect Rdd connect in G3') 80 81 # Turn the DUT on, then reenter G3 to make sure the system handles Rdd 82 # while entering G3 ok. 83 self._try_to_bring_dut_up() 84 self.check_rdd_status('on', 'Rdd disconnected entering S0') 85 86 logging.info('Checking Rdd is connected with the EC in hibernate.') 87 self.faft_client.system.run_shell_command('poweroff') 88 time.sleep(self.WAIT_FOR_STATE) 89 self.ec.send_command('hibernate') 90 time.sleep(self.WAIT_FOR_STATE) 91 92 self.check_rdd_status('on', 'Rdd disconnected after EC hibernate') 93 94 logging.info('Checking Rdd can be disconnected in G3.') 95 self.servo.set_dts_mode('off') 96 self.check_rdd_status('off', 'Cr50 did not detect Rdd disconnect in G3') 97 self._try_to_bring_dut_up() 98 if self.rdd_failures: 99 raise error.TestFail('Found Rdd issues: %s' % (self.rdd_failures)) 100