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