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