From 7d442b94732ba767239801c4d7213e8f52f22616 Mon Sep 17 00:00:00 2001 From: nanliu Date: Mon, 15 Jun 2020 14:43:08 +0800 Subject: [PATCH] virtio-serial:Under named-pipe non-blocking testing Signed-off-by: Nana Liu --- qemu/tests/cfg/virtio_trace_pipenb.cfg | 7 ++++ qemu/tests/virtio_trace_pipenb.py | 48 ++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 qemu/tests/cfg/virtio_trace_pipenb.cfg create mode 100644 qemu/tests/virtio_trace_pipenb.py diff --git a/qemu/tests/cfg/virtio_trace_pipenb.cfg b/qemu/tests/cfg/virtio_trace_pipenb.cfg new file mode 100644 index 00000000..0d5cd229 --- /dev/null +++ b/qemu/tests/cfg/virtio_trace_pipenb.cfg @@ -0,0 +1,7 @@ +- virtio_trace_pipenb: + only Linux + type = virtio_trace_pipenb + smp = 1 + serials += " vs2" + serial_type_vs2 = virtserialport + chardev_backend_vs2 = pipe diff --git a/qemu/tests/virtio_trace_pipenb.py b/qemu/tests/virtio_trace_pipenb.py new file mode 100644 index 00000000..83981581 --- /dev/null +++ b/qemu/tests/virtio_trace_pipenb.py @@ -0,0 +1,48 @@ +import time +import os +import errno + +from virttest import error_context + + +@error_context.context_aware +def run(test, params, env): + """ + Under named-pipe non-blocking testing: + 1) Create pipe named by the following + 2) Boot up a single-CPU guest with a virtio-serial device and + named-pipe chardev backend + 3) Write data to the virtio-serial port until the guest stops. + 4) check whether guest can work. + 5) Read the named-pipe file on the host. + + :param test: QEMU test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + timeout = float(params.get("login_timeout", 360)) + vm = env.get_vm(params["main_vm"]) + serials = params["serials"].split() + v_path = vm.get_serial_console_filename(serials[-1]) + vm.verify_alive() + session = vm.wait_for_login(timeout=timeout) + out_put = session.cmd_output("nohup cat /proc/kallsyms > /dev/virtio-ports/vs2 2>&1 &") + time.sleep(10) + if session.cmd_output("date") is None: + test.fail("Guest shouldn't be blocked and a date should output!") + guest_pid = out_put.split()[1] + pipe = os.open(v_path, os.O_RDONLY | os.O_NONBLOCK) + while True: + try: + os.read(pipe, 1) + except OSError as e: + if e.errno == errno.EAGAIN or e.errno == errno.EWOULDBLOCK: + time.sleep(5) + break + else: + raise Exception("Read data in host failed as %s" % e) + + if not session.cmd_status("ps -p %s" % guest_pid, safe=True): + test.fail("send process in guest does not exit after all data are read out in host") + vm.verify_alive() + vm.verify_kernel_crash() -- GitLab