From b279d526d2ac8955c027e06f04028690dccefbe3 Mon Sep 17 00:00:00 2001 From: "Houqi (Nick) Zuo" Date: Tue, 31 Oct 2023 12:55:11 +0800 Subject: [PATCH 1/2] virtio_fs_utils.py: add @error_context.context_aware to function Add @error_context.context_aware to function basic_io_test() Signed-off-by: Houqi (Nick) Zuo --- provider/virtio_fs_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/provider/virtio_fs_utils.py b/provider/virtio_fs_utils.py index 207c4089ab..d209bc8fb0 100644 --- a/provider/virtio_fs_utils.py +++ b/provider/virtio_fs_utils.py @@ -29,6 +29,7 @@ def get_virtiofs_driver_letter(test, fs_target, session): return driver_letter +@error_context.context_aware def basic_io_test(test, params, session): """ Virtio_fs basic io test. Create file on guest and then compare two md5 From 25abdadce7275da73ec0042771b09f1e05200cd8 Mon Sep 17 00:00:00 2001 From: "Houqi (Nick) Zuo" Date: Wed, 11 Oct 2023 15:38:07 +0800 Subject: [PATCH 2/2] stop_con_vm_during_virtiofs: add a new testcase Signed-off-by: Houqi (Nick) Zuo --- .../tests/cfg/virtio_fs_subtest_during_io.cfg | 31 ++++++ qemu/tests/virtio_fs_subtest_during_io.py | 102 ++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 qemu/tests/cfg/virtio_fs_subtest_during_io.cfg create mode 100644 qemu/tests/virtio_fs_subtest_during_io.py diff --git a/qemu/tests/cfg/virtio_fs_subtest_during_io.cfg b/qemu/tests/cfg/virtio_fs_subtest_during_io.cfg new file mode 100644 index 0000000000..791bf3c5bf --- /dev/null +++ b/qemu/tests/cfg/virtio_fs_subtest_during_io.cfg @@ -0,0 +1,31 @@ +- virtio_fs_subtest_during_io: + type = virtio_fs_subtest_during_io + virt_test_type = qemu + required_qemu = [4.2.0,) + kill_vm = yes + filesystems = fs + fs_driver = virtio-fs + force_create_fs_source = yes + remove_fs_source = yes + fs_target = 'myfs' + vm_mem_share = yes + vm_mem_backend = memory-backend-file + vm_mem_backend_path = /dev/shm + io_timeout = 600 + fs_dest = '/mnt/${fs_target}' + fs_source_dir = virtio_fs_test/ + driver_name = viofs + virtio_win_media_type = iso + cdroms += " virtio" + virtio_fs_test_file = "virtio_fs_test_file" + virtio_fs_cmd_dd = "dd if=/dev/urandom of=%s bs=1M count=700 iflag=fullblock" + Windows: + virtio_fs_cmd_dd = 'dd if=/dev/random of=%s bs=1M count=700' + i386, i686: + install_winfsp_path = 'C:\Program Files' + devcon_dirname = "x86" + x86_64: + install_winfsp_path = 'C:\Program Files (x86)' + devcon_dirname = "amd64" + devcon_path = "WIN_UTILS:\devcon\${devcon_dirname}\devcon.exe" + fs_driver_props = {"queue-size": 16} diff --git a/qemu/tests/virtio_fs_subtest_during_io.py b/qemu/tests/virtio_fs_subtest_during_io.py new file mode 100644 index 0000000000..700f00274f --- /dev/null +++ b/qemu/tests/virtio_fs_subtest_during_io.py @@ -0,0 +1,102 @@ +import time +import os + +from virttest import utils_test, utils_misc, utils_disk +from virttest import error_context +from virttest import data_dir + +from provider import win_driver_utils +from provider import virtio_fs_utils + + +@error_context.context_aware +def run(test, params, env): + """ + Stop/continue the vm during the virtiofs test. + + 1) Boot guest with virtiofs device. + 2) For windows guest, enable driver verifier first. + For the linux guest, skip this step. + 3) Run virtiofs function test. + 4) During steps 3, stop vm and then resume vm. + 5) Memory leak check. + + :param test: QEMU test object + :param params: Dictionary with the test parameters + :param env: Dictionary with test environment. + """ + def sleep_before_basic_io_test(test, params, session): + # The reason that sleeping 3 seconds at here is to let the main thread + # running into file detection logic. + time.sleep(3) + virtio_fs_utils.basic_io_test(test, params, session) + + driver = params["driver_name"] + driver_verifier = params.get("driver_verifier", driver) + driver_running = params.get('driver_running', driver_verifier) + timeout = int(params.get("login_timeout", 360)) + fs_dest = params.get("fs_dest") + fs_target = params.get("fs_target") + test_file = params.get('virtio_fs_test_file') + fs_source = params.get("fs_source_dir") + base_dir = params.get("fs_source_base_dir", data_dir.get_data_dir()) + if not os.path.isabs(fs_source): + fs_source = os.path.join(base_dir, fs_source) + host_data = os.path.join(fs_source, test_file) + + vm_name = params['main_vm'] + vm = env.get_vm(vm_name) + vm.verify_alive() + error_context.context("Boot guest with %s device" % driver, test.log.info) + session = vm.wait_for_login(timeout=timeout) + + if params["os_type"] == "windows": + error_context.context("Run the viofs service", test.log.info) + utils_test.qemu.windrv_verify_running(session, test, driver_running) + session = utils_test.qemu.setup_win_driver_verifier(session, + driver_verifier, + vm) + virtio_fs_utils.run_viofs_service(test, params, session) + else: + error_context.context("Create a destination directory %s " + "inside guest." % fs_dest, test.log.info) + if not utils_misc.make_dirs(fs_dest, session=session): + test.fail("Creating directory was failed!") + error_context.context("Mount virtiofs target %s to %s inside" + " guest." % (fs_target, fs_dest), + test.log.info) + if not utils_disk.mount(fs_target, fs_dest, 'virtiofs', + session=session): + test.fail('Mount virtiofs target failed.') + + basic_io_test = utils_misc.InterruptedThread(target=sleep_before_basic_io_test, + kwargs={"test": test, + "params": params, + "session": session}) + basic_io_test.daemon = True + + error_context.context("Start the io test thread's activity....", + test.log.info) + basic_io_test.start() + test.log.info("The io test thread is running...") + + start_time = time.time() # record the start time. + # run time expected, the unit is second. + max_run_time = params.get_numeric("max_run_time", 30) + while time.time() - start_time < max_run_time: + if os.path.exists(host_data) and os.path.getsize(host_data) > 0: + test.log.info("The file has been detected: %s" % host_data) + error_context.context("Going to stop the vm...", test.log.info) + vm.pause() + time.sleep(2) + error_context.context("Going to resume the vm...", test.log.info) + vm.resume() + if not basic_io_test.is_alive(): + test.fail("The io test thread is NOT alive!") + break + + basic_io_test.join() + test.log.info("The io test thread is terminated...") + + if params.get("os_type") == "windows": + win_driver_utils.memory_leak_check(vm, test, params)