• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# Hardware test for temp sensor.  The test uses mosys to read temp sensor value
9# and check it's in reasonable range.
10
11
12import re
13
14from autotest_lib.client.bin import test, utils
15from autotest_lib.client.common_lib import error
16
17
18# Reasonable temp range for different temp units.
19TEMP_RANGE = {
20    'degrees C': (0, 100),
21}
22
23
24class TempSensor(object):
25    MOSYS_OUTPUT_RE = re.compile('(\w+)="(.*?)"')
26
27    def __init__(self, name):
28        self._name = name
29
30    def get_values(self):
31        values = {}
32        cmd = 'mosys -k sensor print thermal %s' % self._name
33        for kv in self.MOSYS_OUTPUT_RE.finditer(utils.system_output(cmd)):
34            key, value = kv.groups()
35            if key == 'reading':
36                value = int(value)
37            values[key] = value
38        return values
39
40    def get_units(self):
41        return self.get_values()['units']
42
43    def get_reading(self):
44        return self.get_values()['reading']
45
46
47class hardware_Thermal(test.test):
48    version = 1
49
50    def run_once(self, temp_sensor_names=['temp0']):
51        if not temp_sensor_names:
52            raise error.TestError('No temp sensor specified')
53
54        for name in temp_sensor_names:
55            ts = TempSensor(name)
56            units = ts.get_units()
57            try:
58                low, high = TEMP_RANGE[units]
59            except KeyError:
60                raise error.TestError('Unknown temp units of %s' % name)
61            if not low <= ts.get_reading() <= high:
62                raise error.TestError('Temperature of %s out of range' % name)
63