From 0da6bd3d87aa5fafe897e751d7a5fa015898495d Mon Sep 17 00:00:00 2001 From: Suqin Huang Date: Mon, 5 Sep 2016 10:31:21 +0800 Subject: [PATCH] hotplug rng devices in loop Signed-off-by: Suqin Huang --- qemu/tests/cfg/rng_hotplug.cfg | 21 ++++++- qemu/tests/rng_hotplug.py | 106 +++++++++++++++++++++++++-------- 2 files changed, 99 insertions(+), 28 deletions(-) diff --git a/qemu/tests/cfg/rng_hotplug.cfg b/qemu/tests/cfg/rng_hotplug.cfg index 2663bde0..29fada0a 100644 --- a/qemu/tests/cfg/rng_hotplug.cfg +++ b/qemu/tests/cfg/rng_hotplug.cfg @@ -4,18 +4,33 @@ monitor_type = qmp monitors = qmp1 repeat_times = 1 - rng_num = 4 - sub_test_after_hotplug = rng_bat + rng_num = 1 read_rng_timeout = 360 + no no_virtio_rng Windows: session_cmd_timeout = 240 read_rng_cmd = "X:\random_%PROCESSOR_ARCHITECTURE%.exe" driver_name = "viorng" rng_data_rex = "0x\w" + driver_id_cmd = X:\devcon\wxp_x86\devcon.exe find * | find "VirtIO" + driver_check_cmd = X:\devcon\wxp_x86\devcon.exe status @DRIVER_ID + driver_id_pattern = "(.*?):.*?VirtIO RNG Device" Linux: session_cmd_timeout = 360 driver_verifier_cmd = "cat /sys/devices/virtual/misc/hw_random/rng_current" read_rng_cmd = "dd if=/dev/hwrng bs=1 count=10 2>/dev/null|hexdump" driver_name = "virtio" rng_data_rex = "\w+" - + restart_rngd = "service rngd restart" + stop_rngd = "service rngd stop" + variants: + - multi_rngs: + repeat_times = 1 + rng_num = 4 + test_after_hotplug = rng_bat + - repeat_in_loop: + repeat_times = 500 + rng_num = 1 + test_before_hotplug = rng_bat + test_after_hotplug = rng_bat + diff --git a/qemu/tests/rng_hotplug.py b/qemu/tests/rng_hotplug.py index ea47b74a..a2419d12 100644 --- a/qemu/tests/rng_hotplug.py +++ b/qemu/tests/rng_hotplug.py @@ -23,47 +23,103 @@ def run(test, params, env): :param env: Dictionary with test environment """ + def get_rng_id(vm): + device_list = [] + for device in vm.devices: + if isinstance(device, qdevices.QDevice): + if device.get_param("driver") == "virtio-rng-pci": + device_list.append(device) + return device_list + + def hotplug_rng(vm, dev): + error_context.context("Hotplug %s" % dev, logging.info) + output = dev.hotplug(vm.monitor) + time.sleep(5) + + error_context.context("Check %s from qtree after hotplug" % dev, + logging.info) + qtree_output = dev.verify_hotplug(output, vm.monitor) + if not qtree_output: + msg = "no % device in qtree after hotplug" % dev + raise exceptions.TestFail(msg) + logging.info("%s is hotpluged successfully" % dev) + + def unplug_rng(vm, dev): + error_context.context("Hot-unplug %s" % dev, logging.info) + output = dev.unplug(vm.monitor) + time.sleep(5) + + error_context.context("Check %s from qtree after unplug" % dev, + logging.info) + qtree_output = dev.verify_unplug(output, vm.monitor) + if not qtree_output: + msg = "Still get %s in qtree after unplug" % dev + raise exceptions.TestFail(msg) + logging.info("%s is unpluged successfully" % dev) + + def restart_rngd(vm): + if params.get("restart_rngd"): + session = vm.wait_for_login() + error_context.context("Restart rngd service", logging.info) + status, output = session.cmd_status_output("service rngd restart") + if status != 0: + raise exceptions.TestError(output) + session.close() + + def stop_rngd(vm): + if params.get("stop_rngd"): + session = vm.wait_for_login() + error_context.context("Disable rngd service before unplug", + logging.info) + status, output = session.cmd_status_output(params.get("stop_rngd")) + if status != 0: + raise exceptions.TestError(output) + session.close() + login_timeout = int(params.get("login_timeout", 360)) repeat_times = int(params.get("repeat_times", 1)) rng_num = int(params.get("rng_num", 1)) + test_before_hotplug = params.get("test_before_hotplug") + test_after_hotplug = params.get("test_after_hotplug") + vm = env.get_vm(params["main_vm"]) vm.verify_alive() vm.wait_for_login(timeout=login_timeout) + if test_before_hotplug: + restart_rngd(vm) + error_context.context("Run %s before hotplug" % test_before_hotplug) + utils_test.run_virt_sub_test(test, params, env, test_before_hotplug) + + # Unplug attached rng device + device_ids = get_rng_id(vm) + if device_ids: + stop_rngd(vm) + time.sleep(5) + for device in device_ids: + unplug_rng(vm, device) + for i in xrange(repeat_times): dev_list = [] - logging.info("Hotplug/unplug rng devices the %sth times", (i+1)) + error_context.context("Hotplug/unplug rng devices the %s time" + % (i+1), logging.info) for num in xrange(rng_num): vm.devices.set_dirty() new_dev = qdevices.QDevice("virtio-rng-pci", {'id': 'virtio-rng-pci-%d' % num}) + hotplug_rng(vm, new_dev) dev_list.append(new_dev) - error_context.context("Hotplug %s" % new_dev, logging.info) - output = new_dev.hotplug(vm.monitor) - time.sleep(2) - error_context.context("Check %sfrom qtree after hotplug" % new_dev, + # Run test after hotplug + if test_after_hotplug and i == xrange(repeat_times)[-1]: + restart_rngd(vm) + error_context.context("Run %s after hotplug" % test_after_hotplug, logging.info) - qtree_output = new_dev.verify_hotplug(output, vm.monitor) - if not qtree_output: - msg = "no % device in qtree after hotplug" - msg += "the %sth time" % (new_dev, i) - raise exceptions.TestFail(msg) - logging.info("virtio-rng-pci-%d is hotpluged successfully" % num) - sub_test = params.get("sub_test_after_hotplug") - if sub_test: - utils_test.run_virt_sub_test(test, params, env, sub_test) + utils_test.run_virt_sub_test(test, params, env, + test_after_hotplug) + stop_rngd(vm) + time.sleep(5) for dev in dev_list: - error_context.context("Unplug %s" % dev, logging.info) - output = dev.unplug(vm.monitor) - time.sleep(2) - - error_context.context("Check rng device from qtree after unplug", - logging.info) - qtree_output = dev.verify_unplug(output, vm.monitor) - if not qtree_output: - msg = "Still get %s in qtree after unplug %s times" % (dev, i) - raise exceptions.TestFail(msg) - logging.info("%s is unpluged successfully" % dev) + unplug_rng(vm, dev) -- GitLab