Home | History | Annotate | Download | only in hardware_RamFio
      1 # Copyright (c) 2014 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 
      5 import logging
      6 import os
      7 import shutil
      8 
      9 from autotest_lib.client.bin import test
     10 from autotest_lib.client.bin import utils
     11 from autotest_lib.client.cros import service_stopper
     12 
     13 
     14 class hardware_RamFio(test.test):
     15     """
     16     Create ram disk and use FIO to test for ram throughput
     17     """
     18 
     19     version = 1
     20 
     21     _DEFAULT_SIZE = 1024 * 1024 * 1024
     22     _RAMDISK = '/tmp/ramdisk'
     23 
     24     def initialize(self):
     25         # This test grabs a lot of system memory. Lets move Chrome out of the
     26         # picture to avoid interference with OOM killer.
     27         self._services = service_stopper.ServiceStopper(['ui'])
     28         self._services.stop_services()
     29 
     30     def cleanup(self):
     31         if self._services:
     32             self._services.restore_services()
     33 
     34     def run_once(self, size=_DEFAULT_SIZE, requirements=None, dry_run=False):
     35         """Call hardware_StorageFio to test on ram drive
     36 
     37         @param size: size to test in byte
     38                      0 means all usable memory
     39         @param requirements: requirement to pass to hardware_StorageFio
     40         """
     41         usable_mem = utils.usable_memtotal() * 1024
     42         logging.info('Found %d bytes of usable memory.', usable_mem)
     43         # Assume 20% overhead with ramfs.
     44         usable_mem = 0.8 * usable_mem
     45         if size == 0:
     46             size = usable_mem
     47         elif usable_mem < size:
     48             logging.info('Not enough memory. Want: %d, Usable: %d', size,
     49                          usable_mem)
     50             size = usable_mem
     51         self.write_perf_keyval({'Size': size})
     52 
     53         if dry_run:
     54             return
     55 
     56         utils.run('mkdir -p %s' % self._RAMDISK)
     57         # Don't throw an exception on errors.
     58         result = utils.run('mount -t ramfs -o context=u:object_r:tmpfs:s0 '
     59                            'ramfs %s' % self._RAMDISK, ignore_status = True)
     60         if result.exit_status:
     61             logging.info('cannot mount ramfs with context=u:object_r:tmpfs:s0,'
     62                          ' trying plain mount')
     63             # Try again without selinux options.  This time fail on error.
     64             utils.run('mount -t ramfs ramfs %s' % self._RAMDISK)
     65 
     66         self.job.run_test('hardware_StorageFio',
     67                           dev='%s/test_file' % self._RAMDISK,
     68                           size=size,
     69                           requirements=requirements)
     70 
     71         utils.run('umount %s' % self._RAMDISK)
     72 
     73         dst = os.path.join(self.resultsdir, 'results-chart.json')
     74         src = dst.replace('hardware_RamFio', 'hardware_StorageFio')
     75         shutil.copyfile(src, dst)
     76