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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
5
6 import os, random, subprocess, time
7 import commands, logging, random, time, utils
8 from autotest_lib.client.bin import site_utils, test
9 from autotest_lib.client.common_lib import error, rtc, sys_power
10
11
12 MIN_SLEEP_INTERVAL = 5
13 MIN_WORK_INTERVAL = 30
14 START_FILE = '/tmp/power_state_cycle_begin'
15 STOP_FILE = '/tmp/power_state_cycle_end'
16
17 class platform_SuspendStress(test.test):
18 version = 1
19 def initialize(self):
20 random.seed() # System time is fine.
21 if os.path.exists(STOP_FILE):
22 logging.warning('removing existing stop file %s' % STOP_FILE)
23 os.unlink(STOP_FILE)
24
25
26 def suspend_and_resume(self, seconds=MIN_SLEEP_INTERVAL):
27 """Suspends for N seconds."""
28 sleep_seconds = min(seconds, MIN_SLEEP_INTERVAL)
29 suspend_time = rtc.get_seconds()
30 alarm_time = suspend_time + sleep_seconds
31 logging.debug('alarm_time = %d', alarm_time)
32 logging.debug('setting wake alarm at %d for +%ds', suspend_time,
33 seconds)
34 try:
35 rtc.set_wake_alarm(alarm_time)
36 except IOError:
37 logging.warning('setting wake alarm failed, re-trying.')
38 rtc.set_wake_alarm(0)
39 rtc.set_wake_alarm(alarm_time)
40 sys_power.suspend_to_ram()
41 logging.debug('and we\'re back... %ds elapsed.',
42 rtc.get_seconds() - suspend_time)
43
44
45 def power_state_cycle(self, timeout=None):
46 try:
47 while not os.path.exists(STOP_FILE):
48 if timeout and time.mktime(time.localtime()) > timeout:
49 raise error.TestFail('didn\'t find %s before timeout.' %
50 STOP_FILE)
51 self.suspend_and_resume(random.randint(MIN_SLEEP_INTERVAL, 15))
52 time.sleep(random.randint(MIN_WORK_INTERVAL,
53 MIN_WORK_INTERVAL+5))
54 finally:
55 # Ensure we disable the RTC alarm, leaving the original state
56 rtc.set_wake_alarm(0)
57
58
59 def run_once(self, auto_start=False, runtime=None):
60 if auto_start:
61 open(START_FILE, 'w').close()
62 site_utils.poll_for_condition(lambda: os.path.exists(START_FILE),
63 error.TestFail('startup not triggered.'),
64 timeout=30, sleep_interval=1)
65 logging.debug('Found %s, starting power state cycle.' % START_FILE)
66 if runtime:
67 runtime = time.mktime(time.localtime()) + runtime
68 os.unlink(START_FILE)
69 self.power_state_cycle(runtime)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698