提交 6e767cf3 编写于 作者: L lolyu

qemu/tests/aio_test.py: add new case aio test

aims to verify all aio tests are passed.
Signed-off-by: Nlolyu <lolyu@redhat.com>
上级 3fd85d5b
import contextlib
import functools
import glob
import logging
import os
import re
from avocado import TestCancel
from avocado import TestFail
from avocado.utils import cpu
from avocado.utils import path
from avocado.utils import process
from virttest import data_dir
from virttest import utils_misc
def which(cmd):
"""Return command path if available, otherwise cancel the test."""
logging.debug("check if command '%s' is available", cmd)
try:
return path.find_command(cmd)
except path.CmdNotFoundError as detail:
raise TestCancel(str(detail))
def coroutine(func):
"""Start coroutine."""
@functools.wraps(func)
def start(*args, **kargs):
cr = func(*args, **kargs)
cr.send(None)
return cr
return start
@contextlib.contextmanager
def chcwd(path):
"""Support with statement to temporarily change cwd to path."""
cwd = os.getcwd()
os.chdir(path)
try:
yield
finally:
os.chdir(cwd)
def get_qemu_version(params, target):
"""Get installed QEMU version."""
logging.debug("check QEMU version")
qemu_binary = utils_misc.get_qemu_binary(params)
cmd = "%s --version" % qemu_binary
line = process.run(cmd).stdout_text.splitlines()[0]
version = line.split()[-1].strip("()")
logging.debug("QEMU version: %s", version)
target.send(version)
@coroutine
def brew_download_build(target):
"""Download source rpm."""
while True:
version = yield
filename = "%s.src.rpm" % version
root_dir = data_dir.get_data_dir()
save_path = os.path.join(root_dir, filename)
logging.debug("download source rpm to %s", save_path)
if not os.path.isfile(save_path):
with chcwd(root_dir):
cmd = "brew download-build -q --rpm {filename}".format(
filename=filename)
process.run(cmd)
target.send(save_path)
@coroutine
def unpack_source(target):
"""Unpack source rpm."""
while True:
path = yield
logging.debug("unpack source rpm")
process.run("rpm -ivhf {path}".format(path=path))
process.run("rpmbuild -bp /root/rpmbuild/SPECS/qemu-kvm.spec --nodeps")
version = re.search(r"\d+.\d+.\d+", path).group()
src_path = glob.glob("/root/rpmbuild/BUILD/qemu*%s" % version)[0]
target.send(src_path)
@coroutine
def run_aio_tests(target):
"""Compile the source code then run aio tests."""
while True:
path = yield
with chcwd(path):
logging.debug("compile source code of QEMU")
process.run("./configure")
cpu_count = cpu.online_cpus_count()
aio_path = "tests/test-aio"
make_cmd = "make {aio_path} -j{cpu_count}".format(
aio_path=aio_path, cpu_count=cpu_count)
process.run(make_cmd)
logging.debug("run aio tests")
result = process.run(aio_path)
target.send(result.stdout_text)
@coroutine
def parse_result():
"""Parse tests result."""
while True:
result = yield
err = False
for line in result.splitlines():
if "OK" not in line:
err = True
logging.error(line)
if err:
raise TestFail("aio test failed.")
else:
logging.debug("all aio tests have passed")
def run(test, params, env):
"""
Build and run aio tests from QEMU source.
1. get QEMU version.
2. download source.
3. compile source.
4. run aio tests.
5. check result.
"""
# check if command brew and rpmbuild is presented
which("brew")
which("rpmbuild")
get_qemu_version(params,
brew_download_build(
unpack_source(
run_aio_tests(
parse_result()))))
- aio_test:
only qcow2
only Linux
type = aio_test
not_preprocess = yes
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册