1# Copyright (c) 2010 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 5from autotest_lib.client.bin import test 6from autotest_lib.client.common_lib import error 7from autotest_lib.client.cros import power_suspend 8 9 10# In cases like crosbug.com/p/26289, we want results, but also want 11# to make sure we are suspending quickly enough. Retry with this amount 12# of extra suspend time to make sure we can get some results, even 13# if we throw a warning. 14EXTRA_TIME = 10 15 16 17class power_Resume(test.test): 18 version = 1 19 preserve_srcdir = True 20 21 def initialize(self): 22 self._suspender = power_suspend.Suspender(self.resultsdir, 23 throw=True, device_times=True) 24 25 26 def run_once(self, max_devs_returned=10, seconds=0): 27 try: 28 self._suspend_once(max_devs_returned, seconds) 29 except error.TestWarn: 30 self._suspend_once(max_devs_returned, seconds + EXTRA_TIME) 31 raise 32 33 34 def _suspend_once(self, max_devs_returned, seconds): 35 (results, device_times) = self._suspender.suspend(seconds) 36 37 # return as keyvals the slowest n devices 38 slowest_devs = sorted( 39 device_times, 40 key=device_times.get, 41 reverse=True)[:max_devs_returned] 42 for dev in slowest_devs: 43 results[dev] = device_times[dev] 44 45 self.output_perf_value(description='system_suspend', 46 value=results['seconds_system_suspend'], 47 units='sec', higher_is_better=False) 48 self.output_perf_value(description='system_resume', 49 value=results['seconds_system_resume'], 50 units='sec', higher_is_better=False) 51 self.write_perf_keyval(results) 52