1# Copyright 2020 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 5import logging 6 7from autotest_lib.client.cros.power import power_test 8from autotest_lib.client.cros.power import power_utils 9 10 11class power_WaitForCoolDown(power_test.power_Test): 12 """class for power_WaitForCoolDown test.""" 13 version = 1 14 15 def initialize(self, pdash_note='', seconds_period=20., 16 force_discharge=False): 17 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_OFF) 18 super(power_WaitForCoolDown, self).initialize( 19 seconds_period=seconds_period, 20 pdash_note=pdash_note, 21 force_discharge=force_discharge) 22 23 def run_once(self, target_temp=48, max_runtime=600): 24 """"Look at temperature every |seconds_period| seconds for at most 25 |max_runtime| seconds until reported temps do not exceed |target_temp|. 26 27 @param target_temp: Target temperature in celsius. 28 @param max_runtime: Maximum runtime in seconds. 29 """ 30 loop_secs = max(1, int(self._seconds_period)) 31 num_loop = int(max_runtime / loop_secs) 32 self.start_measurements() 33 34 for i in range(num_loop): 35 max_temp = max(self._tlog.refresh()) 36 if max_temp <= target_temp: 37 logging.info('Cooldown at %d seconds, temp: %.1fC', 38 i * self._seconds_period, max_temp) 39 return 40 self.loop_sleep(i, loop_secs) 41 42 max_temp = max(self._tlog.refresh()) 43 logging.warn( 44 'Fail to cool down after %d seconds, temp: %.1fC, target: %dC', 45 num_loop * loop_secs, max_temp, target_temp) 46 47 def cleanup(self): 48 power_utils.set_display_power(power_utils.DISPLAY_POWER_ALL_ON) 49 super(power_WaitForCoolDown, self).cleanup() 50