-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stop_con_vm_during_virtiofs: add a new testcase
Signed-off-by: Houqi (Nick) Zuo <hzuo@redhat.com>
- Loading branch information
Showing
2 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
- stop_cont_vm_during_virtiofs: | ||
type = stop_cont_vm_during_virtiofs | ||
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' | ||
fs_driver_props = {"queue-size": 1024} | ||
mem_devs = mem1 | ||
backend_mem_mem1 = memory-backend-file | ||
mem-path_mem1 = /dev/shm | ||
size_mem1 = ${mem}M | ||
use_mem_mem1 = no | ||
share_mem = yes | ||
!s390, s390x: | ||
guest_numa_nodes = shm0 | ||
numa_memdev_shm0 = mem-mem1 | ||
numa_nodeid_shm0 = 0 | ||
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=10000 iflag=fullblock' | ||
Windows: | ||
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" | ||
memory_leak_check = yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import time | ||
import os | ||
import threading | ||
|
||
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 | ||
from avocado.utils import process | ||
|
||
|
||
@error_context.context_aware | ||
def run(test, params, env): | ||
""" | ||
Stop/continue the vm during the virtiofs test. | ||
1) Boot guest w/ virtiofs device. | ||
2) For windows guest, enable driver verifier first. | ||
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. | ||
""" | ||
@error_context.context_aware | ||
def stop_resume_vm_when_finding_file(): | ||
start_time = time.time() # record the start time. | ||
# run time expected, the unit is second. | ||
max_run_time = params.get("max_run_time", 15) | ||
while time.time() - start_time < max_run_time: | ||
if os.path.exists(host_data): | ||
error_context.context("The file has been detected: %s" % host_data, | ||
test.log.info) | ||
error_context.context("Going to stop the vm...", test.log.info) | ||
vm.pause() | ||
error_context.context("Going to stop the vm...Done", test.log.info) | ||
time.sleep(3) | ||
error_context.context("Going to resume the vm...", test.log.info) | ||
vm.resume() | ||
error_context.context("Going to resume the vm...Done", | ||
test.log.info) | ||
break | ||
|
||
def dd_on_host_shared_dir(): | ||
virtio_fs_cmd_dd = params.get("virtio_fs_cmd_dd") % host_data | ||
process.run(virtio_fs_cmd_dd) | ||
time.sleep(3) | ||
if os.path.exists(host_data): | ||
process.run("rm -rf %s" % host_data) | ||
|
||
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) | ||
virtio_fs_utils.run_viofs_service(test, params, session) | ||
utils_test.qemu.windrv_verify_running(session, test, driver_running) | ||
session = utils_test.qemu.setup_win_driver_verifier(session, | ||
driver_verifier, | ||
vm) | ||
basic_io_test = threading.Thread(target=dd_on_host_shared_dir) | ||
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 = threading.Thread(target=virtio_fs_utils.basic_io_test, | ||
kwargs={"test": test, | ||
"params": params, | ||
"session": session}) | ||
|
||
pause_vm = ThreadWithFinishFlag(target=stop_resume_vm_when_finding_file) | ||
|
||
error_context.context("Start the two thread's activity....", test.log.info) | ||
basic_io_test.start() | ||
pause_vm.start() | ||
error_context.context("Wait until the two threads terminate...", | ||
test.log.info) | ||
basic_io_test.join() | ||
pause_vm.join() | ||
error_context.context("The threads are terminated...", test.log.info) | ||
session = vm.reboot(session) | ||
|
||
if params.get("os_type") == "windows" and params.get("memory_leak_check", | ||
"no") == "yes": | ||
win_driver_utils.memory_leak_check(vm, test, params) | ||
|
||
if not pause_vm.finished: | ||
test.fail("The operation pause/resume vm was failed...") | ||
else: | ||
error_context.context("The operation pause/resume vm was passed...", | ||
test.log.info) | ||
|
||
|
||
class ThreadWithFinishFlag(threading.Thread): | ||
def __init__(self, group=None, target=None, name=None, | ||
args=(), kwargs=None, *, daemon=None): | ||
super(ThreadWithFinishFlag, self).__init__(group, target, name, args, | ||
kwargs, daemon=daemon) | ||
self.finished = False | ||
|
||
def join(self, timeout=None): | ||
super(ThreadWithFinishFlag, self).join(timeout) | ||
self.finished = True |