| Index: client/site_tests/platform_SuspendStress/platform_SuspendStress.py
|
| diff --git a/client/site_tests/platform_SuspendStress/platform_SuspendStress.py b/client/site_tests/platform_SuspendStress/platform_SuspendStress.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f5b0fe9ec5c56d16db19705c1fa6aede8fad4143
|
| --- /dev/null
|
| +++ b/client/site_tests/platform_SuspendStress/platform_SuspendStress.py
|
| @@ -0,0 +1,69 @@
|
| +# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +
|
| +import os, random, subprocess, time
|
| +import commands, logging, random, time, utils
|
| +from autotest_lib.client.bin import site_utils, test
|
| +from autotest_lib.client.common_lib import error, rtc, sys_power
|
| +
|
| +
|
| +MIN_SLEEP_INTERVAL = 5
|
| +MIN_WORK_INTERVAL = 30
|
| +START_FILE = '/tmp/power_state_cycle_begin'
|
| +STOP_FILE = '/tmp/power_state_cycle_end'
|
| +
|
| +class platform_SuspendStress(test.test):
|
| + version = 1
|
| + def initialize(self):
|
| + random.seed() # System time is fine.
|
| + if os.path.exists(STOP_FILE):
|
| + logging.warning('removing existing stop file %s' % STOP_FILE)
|
| + os.unlink(STOP_FILE)
|
| +
|
| +
|
| + def suspend_and_resume(self, seconds=MIN_SLEEP_INTERVAL):
|
| + """Suspends for N seconds."""
|
| + sleep_seconds = min(seconds, MIN_SLEEP_INTERVAL)
|
| + suspend_time = rtc.get_seconds()
|
| + alarm_time = suspend_time + sleep_seconds
|
| + logging.debug('alarm_time = %d', alarm_time)
|
| + logging.debug('setting wake alarm at %d for +%ds', suspend_time,
|
| + seconds)
|
| + try:
|
| + rtc.set_wake_alarm(alarm_time)
|
| + except IOError:
|
| + logging.warning('setting wake alarm failed, re-trying.')
|
| + rtc.set_wake_alarm(0)
|
| + rtc.set_wake_alarm(alarm_time)
|
| + sys_power.suspend_to_ram()
|
| + logging.debug('and we\'re back... %ds elapsed.',
|
| + rtc.get_seconds() - suspend_time)
|
| +
|
| +
|
| + def power_state_cycle(self, timeout=None):
|
| + try:
|
| + while not os.path.exists(STOP_FILE):
|
| + if timeout and time.mktime(time.localtime()) > timeout:
|
| + raise error.TestFail('didn\'t find %s before timeout.' %
|
| + STOP_FILE)
|
| + self.suspend_and_resume(random.randint(MIN_SLEEP_INTERVAL, 15))
|
| + time.sleep(random.randint(MIN_WORK_INTERVAL,
|
| + MIN_WORK_INTERVAL+5))
|
| + finally:
|
| + # Ensure we disable the RTC alarm, leaving the original state
|
| + rtc.set_wake_alarm(0)
|
| +
|
| +
|
| + def run_once(self, auto_start=False, runtime=None):
|
| + if auto_start:
|
| + open(START_FILE, 'w').close()
|
| + site_utils.poll_for_condition(lambda: os.path.exists(START_FILE),
|
| + error.TestFail('startup not triggered.'),
|
| + timeout=30, sleep_interval=1)
|
| + logging.debug('Found %s, starting power state cycle.' % START_FILE)
|
| + if runtime:
|
| + runtime = time.mktime(time.localtime()) + runtime
|
| + os.unlink(START_FILE)
|
| + self.power_state_cycle(runtime)
|
|
|