From 6e767cf3b899be2118908afa5cd69bb6297050a7 Mon Sep 17 00:00:00 2001 From: lolyu Date: Mon, 12 Aug 2019 14:46:27 +0800 Subject: [PATCH] qemu/tests/aio_test.py: add new case aio test aims to verify all aio tests are passed. Signed-off-by: lolyu --- qemu/tests/aio_test.py | 142 ++++++++++++++++++++++++++++++++++++ qemu/tests/cfg/aio_test.cfg | 5 ++ 2 files changed, 147 insertions(+) create mode 100644 qemu/tests/aio_test.py create mode 100644 qemu/tests/cfg/aio_test.cfg diff --git a/qemu/tests/aio_test.py b/qemu/tests/aio_test.py new file mode 100644 index 00000000..6f13c235 --- /dev/null +++ b/qemu/tests/aio_test.py @@ -0,0 +1,142 @@ +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())))) diff --git a/qemu/tests/cfg/aio_test.cfg b/qemu/tests/cfg/aio_test.cfg new file mode 100644 index 00000000..fa31473e --- /dev/null +++ b/qemu/tests/cfg/aio_test.cfg @@ -0,0 +1,5 @@ +- aio_test: + only qcow2 + only Linux + type = aio_test + not_preprocess = yes -- GitLab