• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
6import logging, random, os
7from autotest_lib.client.bin import test, utils
8from autotest_lib.client.common_lib import error
9
10SUSPEND_START = '/tmp/power_state_cycle_begin'
11SUSPEND_END = '/tmp/power_state_cycle_end'
12CRYPTOHOMESTRESS_START = '/tmp/cryptohomestress_begin'
13CRYPTOHOMESTRESS_END = '/tmp/cryptohomestress_end'
14
15class platform_CryptohomeStress(test.test):
16    """This is a stress test of the file system in Chromium OS.
17       While performing the test, we will cycle through power
18       states, and interrupt disk activity.
19    """
20    version = 1
21
22    def initialize(self):
23        for signal_file in [SUSPEND_END]:
24            if os.path.exists(signal_file):
25                logging.warning('removing existing stop file %s', signal_file)
26                os.unlink(signal_file)
27        self.d_ratio = utils.system_output('cat /proc/sys/vm/dirty_ratio')
28        utils.system('echo 1 > /proc/sys/vm/dirty_ratio')
29    random.seed() # System time is fine.
30
31
32    def run_once(self, runtime=300):
33        # check that fio has started, waiting for up to TIMEOUT
34        utils.poll_for_condition(
35            lambda: os.path.exists(CRYPTOHOMESTRESS_START),
36            error.TestFail('fiostress not triggered.'),
37            timeout=30, sleep_interval=1)
38        open(SUSPEND_START, 'w').close()
39        # Pad disk stress runtime for safety.
40        runtime = runtime*3
41        utils.poll_for_condition(
42            lambda: os.path.exists(CRYPTOHOMESTRESS_END),
43            error.TestFail('fiostress runtime exceeded.'),
44            timeout=runtime, sleep_interval=10)
45
46
47    def cleanup(self):
48        open(SUSPEND_END, 'w').close()
49        command = 'echo %s > /proc/sys/vm/dirty_ratio' % self.d_ratio
50        utils.system(command)
51
52