• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Lint as: python2, python3
2# # Copyright 2020 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import logging
7
8from autotest_lib.client.common_lib import error
9from autotest_lib.client.cros.power import power_status
10from autotest_lib.client.cros.power import power_test
11from autotest_lib.client.cros.power import power_utils
12
13
14class power_WaitForCoolDown(power_test.power_Test):
15    """class for power_WaitForCoolDown test."""
16    version = 1
17
18    def initialize(self, pdash_note='', seconds_period=20.,
19                   force_discharge=False):
20        power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF)
21        super(power_WaitForCoolDown, self).initialize(
22                seconds_period=seconds_period,
23                pdash_note=pdash_note,
24                force_discharge=force_discharge)
25        for log in self._meas_logs:
26            if type(log) == power_status.TempLogger:
27                self._tlog = log
28                break
29        else:
30            raise error.TestNAError('DUT does not have temp sensor.')
31
32    def run_once(self, target_temp=48, max_runtime=600):
33        """"Look at temperature every |seconds_period| seconds for at most
34        |max_runtime| seconds until reported temps do not exceed |target_temp|.
35
36        @param target_temp: Target temperature in celsius.
37        @param max_runtime: Maximum runtime in seconds.
38        """
39        loop_secs = max(1, int(self._seconds_period))
40        num_loop = int(max_runtime / loop_secs)
41        self.start_measurements()
42
43        for i in range(num_loop):
44            max_temp = max(self._tlog.refresh())
45            if max_temp <= target_temp:
46                logging.info('Cooldown at %d seconds, temp: %.1fC',
47                             i * self._seconds_period, max_temp)
48                return
49            self.loop_sleep(i, loop_secs)
50
51        max_temp = max(self._tlog.refresh())
52        logging.warning(
53            'Fail to cool down after %d seconds, temp: %.1fC, target: %dC',
54            num_loop * loop_secs, max_temp, target_temp)
55
56    def cleanup(self):
57        power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON)
58        super(power_WaitForCoolDown, self).cleanup()
59