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 6 # DESCRIPTION : 7 # 8 # This is a hardware test for EC. The test uses ectool to check if the EC can 9 # receive message from host and send expected reponse back to host. It also 10 # checks basic EC functionality, such as FAN and temperature sensor. 11 12 13 import time 14 15 from autotest_lib.client.bin import test 16 from autotest_lib.client.common_lib import error 17 from autotest_lib.client.cros import ec as cros_ec 18 19 20 class hardware_EC(test.test): 21 """Class for hardware_EC test.""" 22 version = 1 23 24 def run_once(self, 25 num_temp_sensor=0, 26 temp_sensor_to_test=None, 27 test_fan=False, 28 fan_rpm_error_margin=200, 29 test_battery=False, 30 test_lightbar=False, 31 fan_delay_secs=3): 32 33 ec = cros_ec.EC() 34 35 if not ec.hello(): 36 raise error.TestError('EC communication failed') 37 38 if test_fan: 39 try: 40 ec.set_fanspeed(10000) 41 time.sleep(fan_delay_secs) 42 max_reading = ec.get_fanspeed() 43 if max_reading == 0: 44 raise error.TestError('Unable to start fan') 45 46 target_fanspeed = max_reading / 2 47 ec.set_fanspeed(target_fanspeed) 48 time.sleep(fan_delay_secs) 49 current_reading = ec.get_fanspeed() 50 51 # Sometimes the actual fan speed is close but not equal to 52 # the target speed, so we add some error margin here. 53 lower_bound = target_fanspeed - fan_rpm_error_margin 54 upper_bound = target_fanspeed + fan_rpm_error_margin 55 if not (lower_bound <= current_reading <= upper_bound): 56 raise error.TestError('Unable to set fan speed') 57 finally: 58 ec.auto_fan_ctrl() 59 60 if temp_sensor_to_test is None: 61 temp_sensor_to_test = list(range(num_temp_sensor)) 62 63 for idx in temp_sensor_to_test: 64 temperature = ec.get_temperature(idx) - 273 65 if temperature < 0 or temperature > 100: 66 raise error.TestError( 67 'Abnormal temperature reading on sensor %d' % idx) 68 69 if test_battery and not ec.get_battery(): 70 raise error.TestError('Battery communication failed') 71 72 if test_lightbar and not ec.get_lightbar(): 73 raise error.TestError('Lightbar communication failed') 74