Home | History | Annotate | Download | only in hardware_EC
      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 cros_ec.has_ectool():
     36             raise error.TestNAError('No support for Google EC')
     37 
     38         if not ec.hello():
     39             raise error.TestError('EC communication failed')
     40 
     41         if test_fan:
     42             try:
     43                 ec.set_fanspeed(10000)
     44                 time.sleep(fan_delay_secs)
     45                 max_reading = ec.get_fanspeed()
     46                 if max_reading == 0:
     47                     raise error.TestError('Unable to start fan')
     48 
     49                 target_fanspeed = max_reading / 2
     50                 ec.set_fanspeed(target_fanspeed)
     51                 time.sleep(fan_delay_secs)
     52                 current_reading = ec.get_fanspeed()
     53 
     54                 # Sometimes the actual fan speed is close but not equal to
     55                 # the target speed, so we add some error margin here.
     56                 lower_bound = target_fanspeed - fan_rpm_error_margin
     57                 upper_bound = target_fanspeed + fan_rpm_error_margin
     58                 if not (lower_bound <= current_reading <= upper_bound):
     59                     raise error.TestError('Unable to set fan speed')
     60             finally:
     61                 ec.auto_fan_ctrl()
     62 
     63         if temp_sensor_to_test is None:
     64             temp_sensor_to_test = list(range(num_temp_sensor))
     65 
     66         for idx in temp_sensor_to_test:
     67             temperature = ec.get_temperature(idx) - 273
     68             if temperature < 0 or temperature > 100:
     69                 raise error.TestError(
     70                         'Abnormal temperature reading on sensor %d' % idx)
     71 
     72         if test_battery and not ec.get_battery():
     73             raise error.TestError('Battery communication failed')
     74 
     75         if test_lightbar and not ec.get_lightbar():
     76             raise error.TestError('Lightbar communication failed')
     77