• 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
5import logging, os, shutil, tempfile
6from autotest_lib.client.bin import fio_util, test, utils
7from autotest_lib.client.common_lib import error
8from autotest_lib.client.cros import cryptohome
9
10CRYPTOHOMESTRESS_START = '/tmp/cryptohomestress_begin'
11CRYPTOHOMESTRESS_END = '/tmp/cryptohomestress_end'
12TEST_USER = 'test@chromium.org'
13TEST_PASSWORD = 'test'
14
15class platform_CryptohomeFio(test.test):
16    """Run FIO in the crypto partition."""
17
18    version = 2
19
20    USE_CRYPTO = 'crypto'
21    USE_PLAIN = 'plain'
22    USE_TMPFS = 'tmpfs'
23    DISK_CONFIG_KEYS = [ USE_CRYPTO, USE_PLAIN, USE_TMPFS ]
24
25    def initialize(self, from_internal_disk_only=False):
26        """ Check that we are running on the fixed device"""
27        if from_internal_disk_only and not utils.is_booted_from_internal_disk():
28            raise error.TestNAError('Test only on internal disk')
29
30        if os.path.exists(CRYPTOHOMESTRESS_END):
31            os.unlink(CRYPTOHOMESTRESS_END)
32        open(CRYPTOHOMESTRESS_START, 'w').close()
33
34    def run_once(self, runtime, disk_configs,
35                 script=None, sysctls_list=None):
36        """
37        Create a 300MB file in tmpfs/encrypted/unencrypted location
38        and run fio tesst.
39
40        @param disk_configs: list of keys from DISK_CONFIG_KEYS.
41        @param script: fio script to run
42        @param sysctls_list: list of dictionary of sysctls to alter.
43        """
44        if not set(disk_configs).issubset(set(self.DISK_CONFIG_KEYS)):
45            raise error.TestFail('Unknown keys in disk config')
46        for config in disk_configs:
47            for sysctls in sysctls_list or [ {} ]:
48                graph_descr = ''
49                for key, val in sysctls.iteritems():
50                    utils.sysctl(key, val)
51                    graph_descr += '-'.join([os.path.basename(key), str(val)])
52                # Mount a test cryptohome vault.
53                if config == self.USE_CRYPTO:
54                    cryptohome.mount_vault(TEST_USER, TEST_PASSWORD,
55                                           create=True)
56                    tmpdir = cryptohome.user_path(TEST_USER)
57                elif config == self.USE_TMPFS:
58                    tmpdir = None
59                else:
60                    tmpdir = self.tmpdir
61                self.__work_dir = tempfile.mkdtemp(dir=tmpdir)
62
63                results = {}
64                # TODO make these parameters to run_once & check disk for space.
65                self.__filesize = '300m'
66                self.__runtime = str(runtime)
67                env_vars = ' '.join(
68                    ['FILENAME=' + os.path.join(self.__work_dir, script),
69                     'FILESIZE=' + self.__filesize,
70                     'RUN_TIME=' + self.__runtime
71                     ])
72                job_file = os.path.join(self.bindir, script)
73                results.update(fio_util.fio_runner(self, job_file, env_vars,
74                    name_prefix=graph_descr + config))
75                self.write_perf_keyval(results)
76
77                logging.info('Finished with FS stress, cleaning up.')
78                if config == self.USE_CRYPTO:
79                    cryptohome.unmount_vault(TEST_USER)
80                    cryptohome.remove_vault(TEST_USER)
81                else:
82                    shutil.rmtree(self.__work_dir)
83
84    def cleanup(self):
85        open(CRYPTOHOMESTRESS_END, 'w').close()
86        if os.path.exists(CRYPTOHOMESTRESS_START):
87            os.unlink(CRYPTOHOMESTRESS_START)
88