From 7020fc74a6e76fc9d766c8dc5aa77f836b13c1b2 Mon Sep 17 00:00:00 2001 From: Qingtang Zhou Date: Tue, 5 Feb 2013 15:03:24 +0800 Subject: [PATCH] virttest.usb_boot: make this case run on windows guest The previous usb boot test only works on linux guest. This patch updates them and make them work on windows guest. Also changes: - Add error context to check usb device functions. Signed-off-by: Qingtang Zhou --- qemu/tests/cfg/usb.cfg | 20 +++++++++++++++---- qemu/tests/usb_basic_check.py | 36 +++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/qemu/tests/cfg/usb.cfg b/qemu/tests/cfg/usb.cfg index 79623dbf..51e2b864 100644 --- a/qemu/tests/cfg/usb.cfg +++ b/qemu/tests/cfg/usb.cfg @@ -55,7 +55,7 @@ only usb_boot, usb_reboot, usb_hotplug usb_type_testdev = "usb-ccid" info_usb_name = "QEMU USB CCID" - vendor_id = "08e6" + vendor_id = "08E6" product_id = "4433" vendor = "Gemplus" product = "QEMU USB CCID" @@ -63,7 +63,7 @@ only usb_boot, usb_reboot, usb_hotplug usb_type_testdev = usb-audio info_usb_name = "QEMU USB Audio" - vendor_id = "46f4" + vendor_id = "46F4" product_id = "0002" vendor = "" product = "QEMU USB Audio" @@ -81,12 +81,24 @@ - usb_boot: type = usb_basic_check usb_devices += " testdev" - check_func = "check_usb_device" + deviceid_str = "%s:%s" + chk_usb_info_cmd = "lsusb -v" + Windows: + deviceid_str = "VID_%s&PID_%s" + chk_usb_info_cmd = 'wmic path Win32_USBControllerDevice get Dependent | find "USB"' + vendor_equal = "" + product_equal = "" - usb_reboot: type = usb_basic_check reboot_method = shell usb_devices += " testdev" - check_func = "check_usb_device" + deviceid_str = "%s:%s" + chk_usb_info_cmd = "lsusb -v" + Windows: + deviceid_str = "VID_%s&PID_%s" + chk_usb_info_cmd = 'wmic path Win32_USBControllerDevice get Dependent | find "USB"' + vendor_equal = "" + product_equal = "" - usb_hotplug: type = usb_hotplug - usb_storage: diff --git a/qemu/tests/usb_basic_check.py b/qemu/tests/usb_basic_check.py index 9ad64a8d..c09ab643 100644 --- a/qemu/tests/usb_basic_check.py +++ b/qemu/tests/usb_basic_check.py @@ -2,10 +2,12 @@ import time, re, logging from autotest.client.shared import error -def check_usb_device(test, params, env): +@error.context_aware +def check_usb_device_monitor(test, params, env): vm = env.get_vm(params["main_vm"]) vm.verify_alive() + error.context("Verify USB device in monitor.", logging.info) o = vm.monitor.info("usb") if isinstance(o, dict): o = o.get("return") @@ -14,20 +16,34 @@ def check_usb_device(test, params, env): raise error.TestFail("Could not find '%s' device, monitor " "returns: \n%s" % (params.get("product"), o)) +@error.context_aware +def check_usb_device(test, params, env): + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + check_usb_device_monitor(test, params, env) + 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")) + deviceid_str = params.get("deviceid_str") + vendor_id = params.get("vendor_id") + product_id = params.get("product_id") + vendor = params.get("vendor") + product = params.get("product") + + chk_list = [deviceid_str % (vendor_id, product_id)] + if vendor: + chk_list.append(vendor) + if product: + chk_list.append(product) - o = session.cmd("lsusb -v") + error.context("Verify USB device in guest.") + o = session.cmd_output(params.get("chk_usb_info_cmd")) for item in chk_list: - if not re.findall(item, o): + if not re.findall(item, o, re.I): raise error.TestFail("Could not find item '%s' in guest, " - "'lsusb -v' output:\n %s" % (item, o)) + "Output:\n %s" % (item, o)) @error.context_aware @@ -63,7 +79,7 @@ def run_usb_basic_check(test, params, env): _check_dev() if params.get("reboot_method"): - error.context("Reboot guest.") + error.context("Reboot guest.", logging.info) if params["reboot_method"] == "system_reset": time.sleep(int(params.get("sleep_before_reset", 10))) session = vm.reboot(session, params["reboot_method"], 0, timeout) -- GitLab