From 1ca989109ff1a292aa309efe1adb25606b2bb25b Mon Sep 17 00:00:00 2001 From: Qingtang Zhou Date: Tue, 5 Feb 2013 14:04:44 +0800 Subject: [PATCH] Qemu Test: Create a separated script for usb device These code existed in boot.py before. But it's better to put them in a new separated file. Signed-off-by: Qingtang Zhou --- qemu/tests/cfg/usb.cfg | 4 +- qemu/tests/usb_basic_check.py | 74 +++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 qemu/tests/usb_basic_check.py diff --git a/qemu/tests/cfg/usb.cfg b/qemu/tests/cfg/usb.cfg index 5d7cd070..79623dbf 100644 --- a/qemu/tests/cfg/usb.cfg +++ b/qemu/tests/cfg/usb.cfg @@ -79,11 +79,11 @@ # usb tests variants: - usb_boot: - type = boot + type = usb_basic_check usb_devices += " testdev" check_func = "check_usb_device" - usb_reboot: - type = boot + type = usb_basic_check reboot_method = shell usb_devices += " testdev" check_func = "check_usb_device" diff --git a/qemu/tests/usb_basic_check.py b/qemu/tests/usb_basic_check.py new file mode 100644 index 00000000..9ad64a8d --- /dev/null +++ b/qemu/tests/usb_basic_check.py @@ -0,0 +1,74 @@ +import time, re, logging +from autotest.client.shared import error + + +def check_usb_device(test, params, env): + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + o = vm.monitor.info("usb") + if isinstance(o, dict): + o = o.get("return") + info_usb_name = params.get("info_usb_name") + if info_usb_name and (info_usb_name not in o): + raise error.TestFail("Could not find '%s' device, monitor " + "returns: \n%s" % (params.get("product"), o)) + + timeout = float(params.get("login_timeout", 240)) + session = vm.wait_for_login(timeout=timeout) + + chk_list = ["%s:%s" % (params.get("vendor_id"), params.get("product_id"))] + if params.get("vendor"): + chk_list.append(params.get("vendor")) + if params.get("product"): + chk_list.append(params.get("product")) + + o = session.cmd("lsusb -v") + for item in chk_list: + if not re.findall(item, o): + raise error.TestFail("Could not find item '%s' in guest, " + "'lsusb -v' output:\n %s" % (item, o)) + + +@error.context_aware +def run_usb_basic_check(test, params, env): + """ + KVM usb_basic_check test: + 1) Log into a guest + 2) Verify device(s) work well in guest (optional) + 3) Send a reboot command or a system_reset monitor command (optional) + 4) Wait until the guest is up again + 5) Log into the guest to verify it's up again + 6) Verify device(s) again after guest reboot (optional) + + @param test: kvm test object + @param params: Dictionary with the test parameters + @param env: Dictionary with test environment. + """ + + def _check_dev(): + try: + check_usb_device(test, params, env) + except Exception: + session.close() + raise + + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + timeout = float(params.get("login_timeout", 240)) + error.context("Try to log into guest.", logging.info) + session = vm.wait_for_login(timeout=timeout) + + error.context("Verify device(s) before rebooting.") + _check_dev() + + if params.get("reboot_method"): + error.context("Reboot guest.") + if params["reboot_method"] == "system_reset": + time.sleep(int(params.get("sleep_before_reset", 10))) + session = vm.reboot(session, params["reboot_method"], 0, timeout) + + error.context("Verify device(s) after rebooting.") + _check_dev() + + session.close() -- GitLab