blob: 0de189db6345101ebeb6be577fa4d313c6c91019 [file] [log] [blame]
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging, os, shutil, tempfile, utils
from autotest_lib.client.bin import test
from autotest_lib.client.cros import login as site_login
from autotest_lib.client.cros import cryptohome as site_cryptohome
from autotest_lib.client.cros import constants as chromeos_constants
CRYPTOHOMESTRESS_START = '/tmp/cryptohomestress_begin'
CRYPTOHOMESTRESS_END = '/tmp/cryptohomestress_end'
TEST_USER = 'test@chromium.org'
TEST_PASSWORD = 'test'
class platform_CryptohomeFio(test.test):
"""Run FIO in the crypto partition."""
version = 1
def initialize(self):
# Is it necessary to check for a previously bad state?
if site_login.logged_in():
site_login.attempt_logout()
# Cleanup/touch marker files.
if os.path.exists(CRYPTOHOMESTRESS_END):
os.unlink(CRYPTOHOMESTRESS_END)
open(CRYPTOHOMESTRESS_START, 'w').close()
def run_once(self, runtime, mount_cryptohome=True, tmpfs=False,
script=None):
# Mount a test cryptohome vault.
self.__mount_cryptohome = mount_cryptohome
if mount_cryptohome:
site_cryptohome.mount_vault(TEST_USER, TEST_PASSWORD, create=True)
tmpdir = chromeos_constants.CRYPTOHOME_MOUNT_PT
else:
if tmpfs:
tmpdir = None
else:
tmpdir = self.tmpdir
self.__work_dir = tempfile.mkdtemp(dir=tmpdir)
self.__script = script
# TODO make these parameters to run_once & check target disk for space.
self.__filesize = '150m'
self.__runtime = str(runtime)
env_vars = ' '.join(
['FILENAME=' + os.path.join(self.__work_dir, self.__script),
'FILESIZE=' + self.__filesize,
'RUN_TIME=' + self.__runtime
])
fio_opts = ''
fio = ' '.join([env_vars, 'fio', fio_opts,
os.path.join(self.bindir, self.__script)])
#TODO: Call fio and collect / parse logs. See hardware_storageFio.
status = utils.run(fio)
logging.info(status.stdout)
def cleanup(self):
logging.info('Finished with FS stress, cleaning up.')
if self.__mount_cryptohome:
site_cryptohome.unmount_vault(TEST_USER)
site_cryptohome.remove_vault(TEST_USER)
else:
shutil.rmtree(self.__work_dir)
open(CRYPTOHOMESTRESS_END, 'w').close()
os.unlink(CRYPTOHOMESTRESS_START)