1 # Copyright (c) 2011 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 datetime, logging, subprocess, time 6 from autotest_lib.client.bin import test 7 from autotest_lib.client.common_lib import error, smogcheck_ttci, smogcheck_util 8 9 10 class hardware_TPMttci(test.test): 11 version = 1 12 13 def setup(self): 14 smogcheck_util.enableI2C() 15 self.ttci_obj = None 16 17 def _prepareTtciController(self): 18 """Prepare PcaController and InaController instances for use. 19 20 Returns: 21 an operational PcaController instance, ready to use. 22 an operational InaController instance, ready to use. 23 24 Raises: 25 TestFail: if error creating a new TtciController instance. 26 """ 27 try: 28 self.ttci_obj = smogcheck_ttci.TtciController() 29 except smogcheck_ttci.TtciError, e: 30 raise error.TestFail('Error creating a TtciController: %s' % e) 31 32 def _getMainPowerStatus(self): 33 """Wraps TTCI_Get_Main_Power_Status(). 34 35 Raises: 36 TestFail: if error getting main power status. 37 """ 38 ret, status = self.ttci_obj.TTCI_Get_Main_Power_Status() 39 if ret: 40 raise error.TestFail('TTCI_Get_Main_Power_Status() error: %s' % 41 self.ttci_obj.err) 42 logging.info('Main Power status = %r', status) 43 44 45 def _getBackupPowerStatus(self): 46 """Wraps TTCI_Get_Backup_Power_Status(). 47 48 Raises: 49 TestFail: if error getting backup power status. 50 """ 51 ret, status = self.ttci_obj.TTCI_Get_Backup_Power_Status() 52 if ret: 53 raise error.TestFail('TTCI_Get_Backup_Power_Status() error: %s' % 54 self.ttci_obj.err) 55 logging.info('Backup Power status = %r', status) 56 57 58 def _getTPMPhysicalPresenceStatus(self): 59 """Wraps TTCI_Get_PP_Status(). 60 61 Raises: 62 TestFail: if error getting Physical Presence status. 63 """ 64 ret, status = self.ttci_obj.TTCI_Get_PP_Status() 65 if ret: 66 raise error.TestFail('TTCI_Get_PP_Status() error: %s' % 67 self.ttci_obj.err) 68 logging.info('PP status = %r', status) 69 70 71 def _getTpmI2cStatus(self): 72 """Wraps TTCI_Get_TPM_I2C_Status(). 73 74 Raises: 75 TestFail: if error getting TPM I2C status. 76 """ 77 ret, status = self.ttci_obj.TTCI_Get_TPM_I2C_Status() 78 if ret: 79 raise error.TestFail('TTCI_Get_TPM_I2C_Status() error: %s' % 80 self.ttci_obj.err) 81 logging.info('TPM I2C status = %r', status) 82 83 def run_once(self): 84 # Initialize modules on TTCI 85 self._prepareTtciController() 86 87 start_time = datetime.datetime.now() 88 # Turn on LEDs sequentially 89 if self.ttci_obj.TTCI_Set_LEDs(0x1, failure=False, warning=False): 90 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 91 self.ttci_obj.err) 92 93 if self.ttci_obj.TTCI_Set_LEDs(0x3, failure=False, warning=False): 94 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 95 self.ttci_obj.err) 96 97 if self.ttci_obj.TTCI_Set_LEDs(0x7, failure=False, warning=False): 98 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 99 self.ttci_obj.err) 100 101 if self.ttci_obj.TTCI_Set_LEDs(0xf, failure=False, warning=False): 102 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 103 self.ttci_obj.err) 104 105 if self.ttci_obj.TTCI_Set_LEDs(0xf, failure=False, warning=True): 106 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 107 self.ttci_obj.err) 108 109 if self.ttci_obj.TTCI_Set_LEDs(0xf, failure=True, warning=True): 110 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 111 self.ttci_obj.err) 112 113 # Turn off LEDs sequentially 114 if self.ttci_obj.TTCI_Set_LEDs(0xf, failure=False, warning=True): 115 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 116 self.ttci_obj.err) 117 118 if self.ttci_obj.TTCI_Set_LEDs(0xf, failure=False, warning=False): 119 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 120 self.ttci_obj.err) 121 122 if self.ttci_obj.TTCI_Set_LEDs(0x7, failure=False, warning=False): 123 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 124 self.ttci_obj.err) 125 126 if self.ttci_obj.TTCI_Set_LEDs(0x3, failure=False, warning=False): 127 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 128 self.ttci_obj.err) 129 130 if self.ttci_obj.TTCI_Set_LEDs(0x1, failure=False, warning=False): 131 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 132 self.ttci_obj.err) 133 134 if self.ttci_obj.TTCI_Set_LEDs(0x0, failure=False, warning=False): 135 raise error.TestFail('TTCI_Set_LEDs() error: %s' % 136 self.ttci_obj.err) 137 138 # Get bit status 139 ret, status = self.ttci_obj.TTCI_Get_Switch_Status() 140 if ret: 141 raise error.TestFail('TTCI_Get_Switch_Status() error: %s' % 142 self.ttci_obj.err) 143 logging.info('Switch status = %r', status) 144 145 ret, bit_value, failure, warning = self.ttci_obj.TTCI_Get_LED_Status() 146 if ret: 147 raise error.TestFail('TTCI_Get_LED_Status() error: %s' % 148 self.ttci_obj.err) 149 logging.info('LED status: bit_value=%r, failure=%r, warning=%r', 150 bit_value, failure, warning) 151 152 # Test Main Power 153 self._getMainPowerStatus() 154 if self.ttci_obj.TTCI_Set_Main_Power_Control(turn_on=True): 155 raise error.TestFail('TTCI_Set_Main_Power_Control() error: %s' % 156 self.ttci_obj.err) 157 self._getMainPowerStatus() 158 if self.ttci_obj.TTCI_Set_Main_Power_Control(turn_on=False): 159 raise error.TestFail('TTCI_Set_Main_Power_Control() error: %s' % 160 self.ttci_obj.err) 161 self._getMainPowerStatus() 162 163 # Test Backup Power 164 self._getBackupPowerStatus() 165 if self.ttci_obj.TTCI_Set_Backup_Power_Control(turn_on=True): 166 raise error.TestFail('TTCI_Set_Backup_Power_Control() error: %s' % 167 self.ttci_obj.err) 168 self._getBackupPowerStatus() 169 if self.ttci_obj.TTCI_Set_Backup_Power_Control(turn_on=False): 170 raise error.TestFail('TTCI_Set_Backup_Power_Control() error: %s' % 171 self.ttci_obj.err) 172 self._getBackupPowerStatus() 173 174 # Test Physical Presence 175 self._getTPMPhysicalPresenceStatus() 176 if self.ttci_obj.TTCI_Set_PP_Control(turn_on=True): 177 raise error.TestFail('TTCI_Set_PP_Control() error: %s' % 178 self.ttci_obj.err) 179 self._getTPMPhysicalPresenceStatus() 180 if self.ttci_obj.TTCI_Set_PP_Control(turn_on=False): 181 raise error.TestFail('TTCI_Set_PP_Control() error: %s' % 182 self.ttci_obj.err) 183 self._getTPMPhysicalPresenceStatus() 184 185 # Test TPM I2C bit 186 self._getTpmI2cStatus() 187 if self.ttci_obj.TTCI_Set_TPM_I2C_Control(turn_on=True): 188 raise error.TestFail('TTCI_Set_TPM_I2C_Control() error: %s' % 189 self.ttci_obj.err) 190 self._getTpmI2cStatus() 191 if self.ttci_obj.TTCI_Set_TPM_I2C_Control(turn_on=False): 192 raise error.TestFail('TTCI_Set_TPM_I2C_Control() error: %s' % 193 self.ttci_obj.err) 194 self._getTpmI2cStatus() 195 196 # Test Reset 197 if self.ttci_obj.TTCI_Set_Reset_Control(turn_on=True): 198 raise error.TestFail('TTCI_Set_TPM_I2C_Control() error: %s' % 199 self.ttci_obj.err) 200 201 if self.ttci_obj.TTCI_Set_Reset_Control(turn_on=False): 202 raise error.TestFail('TTCI_Set_TPM_I2C_Control() error: %s' % 203 self.ttci_obj.err) 204 205 end_time = datetime.datetime.now() 206 smogcheck_util.computeTimeElapsed(end_time, start_time) 207