Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Unified Diff: client/site_tests/platform_SuspendStress/platform_SuspendStress.py

Issue 3412036: Basis for cryptohome+power_SuspendResume stress test. (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: tweaks to test params Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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)

Powered by Google App Engine
This is Rietveld 408576698