Home | History | Annotate | Download | only in firmware_ECPeci
      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 
      5 import logging
      6 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      9 
     10 
     11 class firmware_ECPeci(FirmwareTest):
     12     """
     13     Servo based EC PECI test.
     14     """
     15     version = 1
     16 
     17     # Repeat read count
     18     READ_COUNT = 200
     19 
     20     def initialize(self, host, cmdline_args):
     21         super(firmware_ECPeci, self).initialize(host, cmdline_args)
     22         # Don't bother if there is no Chrome EC.
     23         if not self.check_ec_capability(['peci']):
     24             raise error.TestNAError("Nothing needs to be tested on this device")
     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_ECPeci, self).cleanup()
     33 
     34     def _check_read(self):
     35         """Read CPU temperature through PECI.
     36 
     37         Raises:
     38           error.TestFail: Raised when read fails.
     39         """
     40         t = int(self.ec.send_command_get_output("pecitemp",
     41                 ["CPU temp = (\d+) K"])[0][1])
     42         if t < 273 or t > 400:
     43             raise error.TestFail("Abnormal CPU temperature %d K" % t)
     44 
     45     def run_once(self):
     46         """Execute the main body of the test.
     47         """
     48         if not self.check_ec_capability(['peci']):
     49             raise error.TestNAError("Nothing needs to be tested on this device")
     50         logging.info("Reading PECI CPU temperature for %d times.",
     51                      self.READ_COUNT)
     52         for _ in xrange(self.READ_COUNT):
     53             self._check_read()
     54