提交 8e2ddf58 编写于 作者: L Lukáš Doktor

examples.tests: Adjust tests to use new params API

This patch modifies all example tests to use the new API. It uses the
default path, which is `*`, which matches the mux-entry paths ONLY.
In order to get the values it's necessarily to inject the YAML files
into the mux-entry path, by default `/test`, eg:

    avocado run sleeptest -m /test:examples/tests/sleeptest.py.data/
    sleeptest.yaml

It might seen as a bit more complicated to execute, but it's definitely
easier for maintaining and combining existing YAML files. To execute
matrix of tests you simply inject them into 2 different `/test` children,
eg: `-m /test/by_length:lengths.yaml /test/by_method:methods.yaml`.
Signed-off-by: NLukáš Doktor <ldoktor@redhat.com>
上级 726c702f
......@@ -145,14 +145,14 @@ Using a multiplex file
You may use the avocado runner with a multiplex file to provide params and matrix
generation for sleeptest just like::
$ avocado run sleeptest --multiplex examples/tests/sleeptest.py.data/sleeptest.yaml
$ avocado run sleeptest --multiplex /test:examples/tests/sleeptest.py.data/sleeptest.yaml
JOB ID : d565e8dec576d6040f894841f32a836c751f968f
JOB LOG : $HOME/avocado/job-results/job-2014-08-12T15.44-d565e8de/job.log
JOB HTML : $HOME/avocado/job-results/job-2014-08-12T15.44-d565e8de/html/results.html
TESTS : 3
(1/3) sleeptest.short: PASS (0.50 s)
(2/3) sleeptest.medium: PASS (1.01 s)
(3/3) sleeptest.long: PASS (5.01 s)
(1/3) sleeptest: PASS (0.50 s)
(2/3) sleeptest.1: PASS (1.01 s)
(3/3) sleeptest.2: PASS (5.01 s)
PASS : 3
ERROR : 0
FAIL : 0
......@@ -161,30 +161,43 @@ generation for sleeptest just like::
INTERRUPT : 0
TIME : 6.52 s
The ``--multiplex`` accepts either only ``$FILE_LOCATION`` or ``$INJECT_TO:$FILE_LOCATION``.
By later you can combine multiple simple YAML files and inject them into a specific location
as shown in the example above. As you learned in previous section the ``/test`` location
is part of default ``mux-entry`` path thus sleeptest can access the values without specifying
the path. To understand the difference execute those commands::
$ avocado multiplex -t examples/tests/sleeptest.py.data/sleeptest.yaml
$ avocado multiplex -t /test:examples/tests/sleeptest.py.data/sleeptest.yaml
Note that, as your multiplex file specifies all parameters for sleeptest, you
can't leave the test ID empty::
$ scripts/avocado run --multiplex examples/tests/sleeptest/sleeptest.yaml
$ scripts/avocado run --multiplex /test:examples/tests/sleeptest/sleeptest.yaml
Empty test ID. A test path or alias must be provided
If you want to run some tests that don't require params set by the multiplex file, you can::
$ avocado run sleeptest synctest --multiplex examples/tests/sleeptest.py.data/sleeptest.yaml
JOB ID : dd91ea5f8b42b2f084702315688284f7e8aa220a
JOB LOG : $HOME/avocado/job-results/job-2014-08-12T15.49-dd91ea5f/job.log
JOB HTML : $HOME/avocado/job-results/job-2014-08-12T15.49-dd91ea5f/html/results.html
TESTS : 4
(1/4) sleeptest.short: PASS (0.50 s)
(2/4) sleeptest.medium: PASS (1.01 s)
(3/4) sleeptest.long: PASS (5.01 s)
(4/4) synctest.1: ERROR (1.85 s)
PASS : 3
ERROR : 1
FAIL : 0
SKIP : 0
WARN : 0
INTERRUPT : 0
TIME : 8.69 s
You can also execute multiple tests with the same multiplex file::
./scripts/avocado run sleeptest synctest --multiplex examples/tests/sleeptest.py.data/sleeptest.yaml
JOB ID : 72166988c13fec26fcc9c2e504beec8edaad4761
JOB LOG : /home/medic/avocado/job-results/job-2015-05-15T11.02-7216698/job.log
JOB HTML : /home/medic/avocado/job-results/job-2015-05-15T11.02-7216698/html/results.html
TESTS : 8
(1/8) sleeptest.py: PASS (1.00 s)
(2/8) sleeptest.py.1: PASS (1.00 s)
(3/8) sleeptest.py.2: PASS (1.00 s)
(4/8) sleeptest.py.3: PASS (1.00 s)
(5/8) synctest.py: PASS (1.31 s)
(6/8) synctest.py.1: PASS (1.48 s)
(7/8) synctest.py.2: PASS (3.36 s)
(8/8) synctest.py.3: PASS (3.59 s)
PASS : 8
ERROR : 0
FAIL : 0
SKIP : 0
WARN : 0
INTERRUPT : 0
TIME : 13.76 s
Avocado tests are also unittests
================================
......@@ -542,16 +555,14 @@ impact your test grid. You can account for that possibility and set up a
::
variants:
- sleeptest:
sleep_length = 5
sleep_length_type = float
timeout = 3
timeout_type = float
sleep_length = 5
sleep_length_type = float
timeout = 3
timeout_type = float
::
$ avocado run sleeptest --multiplex /tmp/sleeptest-example.mplx
$ avocado run sleeptest --multiplex /test:/tmp/sleeptest-example.mplx
JOB ID : 6d5a2ff16bb92395100fbc3945b8d253308728c9
JOB LOG : $HOME/avocado/job-results/job-2014-08-12T15.52-6d5a2ff1/job.log
JOB HTML : $HOME/avocado/job-results/job-2014-08-12T15.52-6d5a2ff1/html/results.html
......
......@@ -19,7 +19,7 @@ class CAbort(test.Test):
"""
Build 'abort'.
"""
c_file = self.get_data_path(self.params.get('source', 'abort.c'))
c_file = self.get_data_path(self.params.get('source', default='abort.c'))
c_file_name = os.path.basename(c_file)
dest_c_file = os.path.join(self.srcdir, c_file_name)
shutil.copy(c_file, dest_c_file)
......
......@@ -19,7 +19,8 @@ class DataDirTest(test.Test):
"""
Build 'datadir'.
"""
c_file = self.get_data_path(self.params.get('source', 'datadir.c'))
c_file = self.get_data_path(self.params.get('source',
default='datadir.c'))
c_file_name = os.path.basename(c_file)
dest_c_file = os.path.join(self.srcdir, c_file_name)
shutil.copy(c_file, dest_c_file)
......
......@@ -20,7 +20,8 @@ class DoubleFreeTest(test.Test):
"""
Build 'doublefree'.
"""
c_file = self.get_data_path(self.params.get('source', 'doublefree.c'))
c_file = self.get_data_path(self.params.get('source',
default='doublefree.c'))
c_file_name = os.path.basename(c_file)
dest_c_file = os.path.join(self.srcdir, c_file_name)
shutil.copy(c_file, dest_c_file)
......
......@@ -21,7 +21,7 @@ class DoubleFreeTest(test.Test):
"""
Build 'doublefree'.
"""
source = self.params.get('source', 'doublefree.c')
source = self.params.get('source', default='doublefree.c')
c_file = self.get_data_path(source)
shutil.copy(c_file, self.srcdir)
self.__binary = source.rsplit('.', 1)[0]
......
......@@ -22,7 +22,8 @@ class FioTest(test.Test):
"""
Build 'fio'.
"""
fio_tarball = self.params.get('fio_tarball', 'fio-2.1.10.tar.bz2')
fio_tarball = self.params.get('fio_tarball',
default='fio-2.1.10.tar.bz2')
tarball_path = self.get_data_path(fio_tarball)
archive.extract(tarball_path, self.srcdir)
fio_version = fio_tarball.split('.tar.')[0]
......@@ -34,7 +35,7 @@ class FioTest(test.Test):
Execute 'fio' with appropriate parameters.
"""
os.chdir(self.srcdir)
fio_job = self.params.get('fio_job', 'fio-mixed.job')
fio_job = self.params.get('fio_job', default='fio-mixed.job')
cmd = ('./fio %s' % self.get_data_path(fio_job))
process.system(cmd)
......
......@@ -12,8 +12,8 @@ class LinuxBuildTest(test.Test):
"""
def setUp(self):
kernel_version = self.params.get('linux_version', '3.14.5')
linux_config = self.params.get('linux_config', 'config')
kernel_version = self.params.get('linux_version', default='3.14.5')
linux_config = self.params.get('linux_config', default='config')
config_path = self.get_data_path(linux_config)
self.linux_build = kernel_build.KernelBuild(kernel_version,
config_path,
......
......@@ -24,7 +24,7 @@ class PrintVariableTest(test.Test):
"""
Build 'print_variable'.
"""
source = self.params.get('source', 'print_variable.c')
source = self.params.get('source', default='print_variable.c')
c_file = self.get_data_path(source)
shutil.copy(c_file, self.srcdir)
self.__binary = source.rsplit('.', 1)[0]
......
......@@ -16,7 +16,7 @@ class MultiplexTest(test.Test):
self.set_numa_balance()
self.assembly_vm()
os_type = self.params.get('os_type', 'linux')
os_type = self.params.get('os_type', default='linux')
if os_type == 'windows':
self.log.info('Preparing VM with Windows (%s)',
self.params.get('win'))
......@@ -26,16 +26,17 @@ class MultiplexTest(test.Test):
def compile_code(self):
self.log.info('Compile code')
self.log.info('gcc %s %s', self.params.get('gcc_flags', '-O2'),
self.log.info('gcc %s %s', self.params.get('gcc_flags', default='-O2'),
'code.c')
def set_hugepages(self):
if self.params.get('huge_pages', 'yes') == 'yes':
if self.params.get('huge_pages', default='yes') == 'yes':
self.log.info('Setting hugepages')
def set_numa_balance(self):
numa_balancing = self.params.get('numa_balancing', 'yes')
numa_migrate = self.params.get('numa_balancing_migrate_deferred', 'no')
numa_balancing = self.params.get('numa_balancing', default='yes')
numa_migrate = self.params.get('numa_balancing_migrate_deferred',
default='no')
if numa_balancing:
self.log.info('Numa balancing: %s', numa_balancing)
if numa_migrate:
......@@ -43,9 +44,10 @@ class MultiplexTest(test.Test):
def assembly_vm(self):
self.log.info('Assembling VM')
drive_format = self.params.get('drive_format', 'virtio_blk')
nic_model = self.params.get('nic_model', 'virtio_net')
enable_msx_vectors = self.params.get('enable_msx_vectors', 'yes')
drive_format = self.params.get('drive_format', default='virtio_blk')
nic_model = self.params.get('nic_model', default='virtio_net')
enable_msx_vectors = self.params.get('enable_msx_vectors',
default='yes')
if drive_format:
self.log.info('Drive format: %s', drive_format)
if nic_model:
......@@ -56,13 +58,13 @@ class MultiplexTest(test.Test):
def runTest(self):
self.log.info('Executing synctest...')
self.log.info('synctest --timeout %s --tries %s',
self.params.get('sync_timeout', 12),
self.params.get('sync_tries', 3))
self.params.get('sync_timeout', default=12),
self.params.get('sync_tries', default=3))
self.log.info('Executing ping test...')
cmdline = ('ping --timeout %s --tries %s'
% (self.params.get('ping_timeout', 10),
self.params.get('ping_tries', 5)))
% (self.params.get('ping_timeout', default=10),
self.params.get('ping_tries', default=5)))
ping_flags = self.params.get('ping_flags')
if ping_flags:
......
......@@ -19,7 +19,8 @@ class Raise(test.Test):
"""
Build 'raise'.
"""
c_file = self.get_data_path(self.params.get('source', 'raise.c'))
c_file = self.get_data_path(self.params.get('source',
default='raise.c'))
c_file_name = os.path.basename(c_file)
dest_c_file = os.path.join(self.srcdir, c_file_name)
shutil.copy(c_file, dest_c_file)
......@@ -31,7 +32,7 @@ class Raise(test.Test):
"""
Execute 'raise'.
"""
signum = self.params.get('signal_number', 15)
signum = self.params.get('signal_number', default=15)
cmd = os.path.join(self.srcdir, 'raise %d' % signum)
cmd_result = process.run(cmd, ignore_status=True)
self.log.info(cmd_result)
......
......@@ -17,9 +17,9 @@ class SleepTenMin(test.Test):
"""
Sleep for length seconds.
"""
cycles = int(self.params.get('sleep_cycles', 1))
length = int(self.params.get('sleep_length', 600))
method = self.params.get('sleep_method', 'builtin')
cycles = int(self.params.get('sleep_cycles', default=1))
length = int(self.params.get('sleep_length', default=600))
method = self.params.get('sleep_method', default='builtin')
for cycle in xrange(0, cycles):
self.log.debug("Sleeping for %.2f seconds", length)
......
!mux
!using : test
short:
sleep_length: 0.5
medium:
......
......@@ -20,11 +20,11 @@ class SyncTest(test.Test):
Build the synctest suite.
"""
self.cwd = os.getcwd()
tarball_path = self.get_data_path(self.params.get('sync_tarball',
'synctest.tar.bz2'))
tarball_path = self.get_data_path(self.params.get('sync_tarball', '*',
default='synctest.tar.bz2'))
archive.extract(tarball_path, self.srcdir)
self.srcdir = os.path.join(self.srcdir, 'synctest')
if self.params.get('debug_symbols', True):
if self.params.get('debug_symbols', default=True):
build.make(self.srcdir,
env={'CFLAGS': '-g -O0'},
extra_args='synctest')
......@@ -38,8 +38,8 @@ class SyncTest(test.Test):
os.chdir(self.srcdir)
path = os.path.join(os.getcwd(), 'synctest')
cmd = ('%s %s %s' %
(path, self.params.get('sync_length', 100),
self.params.get('sync_loop', 10)))
(path, self.params.get('sync_length', default=100),
self.params.get('sync_loop', default=10)))
process.system(cmd)
os.chdir(self.cwd)
......
......@@ -18,7 +18,7 @@ class TimeoutTest(test.Test):
"""
This should throw a TestTimeoutError.
"""
sleep_time = self.params.get('sleep_time', 5)
sleep_time = self.params.get('sleep_time', default=5)
self.log.info('Sleeping for %.2f seconds (2 more than the timeout)',
sleep_time)
time.sleep(sleep_time)
......
......@@ -13,8 +13,8 @@ class WhiteBoard(test.Test):
"""
def runTest(self):
data_file = self.params.get('whiteboard_data_file', '')
data_size = self.params.get('whiteboard_data_size', '10')
data_file = self.params.get('whiteboard_data_file', default='')
data_size = self.params.get('whiteboard_data_size', default='10')
if data_file:
self.log.info('Writing data to whiteboard from file: %s',
data_file)
......@@ -24,9 +24,9 @@ class WhiteBoard(test.Test):
else:
offset = int(data_size) - 1
data = self.params.get('whiteboard_data_text',
'default whiteboard text')[0:offset]
default='default whiteboard text')[0:offset]
iterations = int(self.params.get('whiteboard_writes', 1))
iterations = int(self.params.get('whiteboard_writes', default=1))
result = ''
for _ in xrange(0, iterations):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册