blob: 7d417cffd5e52a6d19216da23149432801a15101 [file] [log] [blame]
# Copyright (c) 2014 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
import os
import shutil
from autotest_lib.client.bin import test
from autotest_lib.client.bin import utils
from autotest_lib.client.common_lib import error
from autotest_lib.client.cros import service_stopper
class hardware_RamFio(test.test):
Create ram disk and use FIO to test for ram throughput
version = 1
_MB = 1024 * 1024
_DEFAULT_SIZE = 1024 * _MB
_RAMDISK = '/tmp/ramdisk'
def initialize(self):
# This test grabs a lot of system memory. Lets move Chrome out of the
# picture to avoid interference with OOM killer.
self._services = service_stopper.ServiceStopper(['ui'])
def cleanup(self):
if self._services:
def run_once(self, size=_DEFAULT_SIZE, requirements=None, dry_run=False):
"""Call hardware_StorageFio to test on ram drive
@param size: size to test in byte
0 means all usable memory
@param requirements: requirement to pass to hardware_StorageFio
usable_mem = utils.usable_memtotal() * 1024'Found %d bytes of usable memory.', usable_mem)
# Assume 20% overhead with ramfs.
usable_mem *= 1 - self._RAMFS_OVERHEAD
# Reserved 200 MiB to prevent OOM error.
if usable_mem <= self._RESERVED_RAM_SIZE:
raise error.TestNAError(
'Usable memory (%d MiB) is less than reserved size (%d MiB).' %
(usable_mem / self._MB, self._RESERVED_RAM_SIZE / self._MB))
usable_mem -= self._RESERVED_RAM_SIZE
if size == 0:
size = usable_mem
elif usable_mem < size:'Not enough memory. Want: %d, Usable: %d', size,
size = usable_mem
self.write_perf_keyval({'Size': size})
if dry_run:
return'mkdir -p %s' % self._RAMDISK)
# Don't throw an exception on errors.
result ='mount -t ramfs -o context=u:object_r:tmpfs:s0 '
'ramfs %s' % self._RAMDISK, ignore_status = True)
if result.exit_status:'cannot mount ramfs with context=u:object_r:tmpfs:s0,'
' trying plain mount')
# Try again without selinux options. This time fail on error.'mount -t ramfs ramfs %s' % self._RAMDISK)
dev='%s/test_file' % self._RAMDISK,
requirements=requirements)'umount %s' % self._RAMDISK)
dst = os.path.join(self.resultsdir, 'results-chart.json')
src = dst.replace('hardware_RamFio', 'hardware_StorageFio')
shutil.copyfile(src, dst)