diff --git a/avocado/utils/disk.py b/avocado/utils/disk.py new file mode 100644 index 0000000000000000000000000000000000000000..10731097d887a90818a26e1a7a426d5dbc4eaff0 --- /dev/null +++ b/avocado/utils/disk.py @@ -0,0 +1,26 @@ +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# See LICENSE for more details. +# +# This code was inspired in the autotest project, +# +# client/base_utils.py + + +""" +Disk utilities +""" + +import os + + +def freespace(path): + fs_stats = os.statvfs(path) + return fs_stats.f_bsize * fs_stats.f_bavail diff --git a/examples/tests/stress.py b/examples/tests/stress.py new file mode 100755 index 0000000000000000000000000000000000000000..f28528dff6bf79165ed3ab0f3581dfdbae7bba35 --- /dev/null +++ b/examples/tests/stress.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python + +import os +import multiprocessing + +from avocado import Test +from avocado import main +from avocado.utils import archive +from avocado.utils import disk +from avocado.utils import build +from avocado.utils import memory +from avocado.utils import process + + +class Stress(Test): + + """ + Calls stress, a simple program which aims to impose certain types of + computing stress on the target machine. + @author: Yi Yang (yang.y.yi@gmail.com) + """ + + def setUp(self): + """ + Build 'stress'. + Source: + http://people.seas.harvard.edu/~apw/stress/stress-1.0.4.tar.gz + """ + stress_tarball = self.params.get('stress_tarball', + default='stress-1.0.4.tar.gz') + tarball_path = self.get_data_path(stress_tarball) + archive.extract(tarball_path, self.srcdir) + stress_version = stress_tarball.split('.tar.')[0] + self.srcdir = os.path.join(self.srcdir, stress_version) + os.chdir(self.srcdir) + process.run('./configure') + build.make(self.srcdir) + + def test(self): + """ + Execute 'stress' with proper arguments. + """ + length = self.params.get('stress_lenght', default=60) + threads = self.params.get('threads', default=None) + memory_per_thread = self.params.get('memory_per_thread', default=None) + file_size_per_thread = self.params.get('file_size_per_thread', + default=None) + if threads is None: + # We will use 2 workers of each type for each CPU detected + threads = 2 * multiprocessing.cpu_count() + + if memory_per_thread is None: + # Sometimes the default memory used by each memory worker (256 M) + # might make our machine go OOM and then funny things might start to + # happen. Let's avoid that. + mb = (memory.freememtotal() + + memory.read_from_meminfo('SwapFree') / 2) + memory_per_thread = (mb * 1024) / threads + + if file_size_per_thread is None: + # Even though unlikely, it's good to prevent from allocating more + # disk than this machine actually has on its autotest directory + # (limit the amount of disk used to max of 90 % of free space) + free_disk = disk.freespace(self.srcdir) + file_size_per_thread = 1024 ** 2 + if (0.9 * free_disk) < file_size_per_thread * threads: + file_size_per_thread = (0.9 * free_disk) / threads + + # Number of CPU workers spinning on sqrt() + args = '--cpu %d ' % threads + # Number of IO workers spinning on sync() + args += '--io %d ' % threads + # Number of Memory workers spinning on malloc()/free() + args += '--vm %d ' % threads + # Amount of memory used per each worker + args += '--vm-bytes %d ' % memory_per_thread + # Number of HD workers spinning on write()/ulink() + args += '--hdd %d ' % threads + # Size of the files created by each worker in bytes + args += '--hdd-bytes %d ' % file_size_per_thread + # Time for which the stress test will run + args += '--timeout %d ' % length + # Verbose flag + args += '--verbose' + + os.chdir(self.srcdir) + cmd = ('./src/stress %s' % args) + process.run(cmd) + +if __name__ == "__main__": + main() diff --git a/examples/tests/stress.py.data/stress-1.0.4.tar.gz b/examples/tests/stress.py.data/stress-1.0.4.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..900286e763db70c3f6f1b4e0c613503dc7bc3fbe Binary files /dev/null and b/examples/tests/stress.py.data/stress-1.0.4.tar.gz differ diff --git a/examples/tests/stress.py.data/stress.yaml b/examples/tests/stress.py.data/stress.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c6e5c6f79665629e3f70b9336b8e8380368c179d --- /dev/null +++ b/examples/tests/stress.py.data/stress.yaml @@ -0,0 +1,15 @@ +setup: + duration: !mux + default: + stress_lenght: 60 + quick: + stress_lenght: 5 + workers: !mux + default: + threads: null + minimal: + threads: 1 + memory: + memory_per_thread: null + files: + file_size_per_thread: null