Home | History | Annotate | Download | only in stress
      1 import os
      2 from autotest_lib.client.bin import test, utils
      3 
      4 
      5 class stress(test.test):
      6     """
      7     Calls stress, a simple program which aims to impose certain types of
      8     computing stress on the target machine.
      9     @author: Yi Yang (yang.y.yi (at] gmail.com)
     10 
     11     In order to verify at a glance the options supported by the program stress,
     12     check out the options summary located at the stress example control file.
     13     """
     14     version = 2
     15 
     16     def initialize(self):
     17         self.job.require_gcc()
     18 
     19 
     20     # http://weather.ou.edu/~apw/projects/stress/stress-1.0.4.tar.gz
     21     def setup(self, tarball = 'stress-1.0.4.tar.gz'):
     22         tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
     23         utils.extract_tarball_to_dir(tarball, self.srcdir)
     24         os.chdir(self.srcdir)
     25 
     26         utils.configure()
     27         utils.make()
     28 
     29 
     30     def run_once(self, args = '', stress_length=60):
     31         if not args:
     32             # We will use 2 workers of each type for each CPU detected
     33             threads = 2 * utils.count_cpus()
     34 
     35             # Sometimes the default memory used by each memory worker (256 M)
     36             # might make our machine go OOM and then funny things might start to
     37             # happen. Let's avoid that.
     38             mb = utils.freememtotal() + utils.read_from_meminfo('SwapFree') / 2
     39             memory_per_thread = (mb * 1024) / threads
     40 
     41             # Even though unlikely, it's good to prevent from allocating more
     42             # disk than this machine actually has on its autotest directory
     43             # (limit the amount of disk used to max of 90 % of free space)
     44             free_disk = utils.freespace(self.srcdir)
     45             file_size_per_thread = 1024 ** 2
     46             if (0.9 * free_disk) < file_size_per_thread * threads:
     47                 file_size_per_thread = (0.9 * free_disk) / threads
     48 
     49             # Number of CPU workers spinning on sqrt()
     50             args = '--cpu %d ' % threads
     51             # Number of IO workers spinning on sync()
     52             args += '--io %d ' % threads
     53             # Number of Memory workers spinning on malloc()/free()
     54             args += '--vm %d ' % threads
     55             # Amount of memory used per each worker
     56             args += '--vm-bytes %d ' % memory_per_thread
     57             # Number of HD workers spinning on write()/ulink()
     58             args += '--hdd %d ' % threads
     59             # Size of the files created by each worker in bytes
     60             args += '--hdd-bytes %d ' % file_size_per_thread
     61             # Time for which the stress test will run
     62             args += '--timeout %d ' % stress_length
     63             # Verbose flag
     64             args += '--verbose'
     65 
     66         utils.system(self.srcdir + '/src/stress ' + args)
     67