Skip to content

Commit

Permalink
Add test case support >=509 memslots
Browse files Browse the repository at this point in the history
Signed-off-by: qcheng-redhat <[email protected]>
  • Loading branch information
qcheng-redhat committed Nov 15, 2024
1 parent c97ee92 commit 2aae8df
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 0 deletions.
74 changes: 74 additions & 0 deletions qemu/tests/cfg/virtio_fs_509_memslots.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
- virtio_fs_509_memslots:
type = virtio_fs_509_memslots
no RHEL.6 RHEL.7 RHEL.8
no Host_RHEL.m6 Host_RHEL.m7 Host_RHEL.m8
no Win2008 Win7 Win2012..r2 Win8 Win8.1
no s390x
required_qemu = [9.0.0,)
start_vm = yes
hmp_timeout = 10

filesystems = fs
fs_driver = virtio-fs
fs_driver_props = {"queue-size": 1024}
fs_source_type = mount
fs_source_dir = /var/tmp/virtio_fs_test
force_create_fs_source = no
remove_fs_source = yes
fs_target = 'myfs'
fs_dest = /mnt/${fs_target}
driver_name = viofs

test_file = "test_file"
test_data = "hello virtiofs"
pre_command = "mkdir -p ${fs_source_dir}"
pre_command += " && echo -e ${test_data} > ${fs_source_dir}/${test_file}"
post_command = "rm -rf ${fs_source_dir}"

vm_mem_share = yes
vm_mem_backend = memory-backend-file
vm_mem_backend_path = /dev/shm
maxmem_mem = 108G
mem_devs = "vmem0"
vm_memdev_model_vmem0 = "virtio-mem"
size_mem_vmem0 = 4G
requested-size_memory_vmem0 = 3G
total_memslots = 3
use_mem_vmem0 = yes
memdev_memory_vmem0 = "mem-vmem0"
backend_mem_vmem0 = memory-backend-memfd
dynamic_memslots = yes
dynamic-memslots_memory_vmem0 = on
pcie_extra_root_port = 1
share_mem = yes

cmd_md5 = 'md5sum %s'
io_timeout = 600
Windows:
cmd_md5 = "%s: && md5sum.exe %s"
# install winfsp tool
i386, i686:
install_winfsp_path = 'C:\Program Files'
devcon_dirname = 'x86'
x86_64:
install_winfsp_path = 'C:\Program Files (x86)'
devcon_dirname = 'amd64'
install_winfsp_cmd = 'msiexec /i WIN_UTILS:\winfsp.msi /qn'
check_installed_cmd = 'dir "%s" |findstr /I winfsp'
viofs_log_file = C:\viofs_log.txt
viofs_svc_name = VirtioFsSvc
viofs_exe_path = C:\virtiofs.exe
viofs_exe_copy_cmd = xcopy %s C:\ /Y
viofs_sc_create_cmd = 'sc create ${viofs_svc_name} binpath=${viofs_exe_path} start=auto'
viofs_sc_create_cmd += ' depend="WinFsp.Launcher/VirtioFsDrv" DisplayName="Virtio FS Service"'
viofs_sc_start_cmd = 'sc start ${viofs_svc_name}'
viofs_sc_query_cmd = 'sc query ${viofs_svc_name}'
viofs_sc_delete_cmd = 'sc delete ${viofs_svc_name}'
debug_log_operation = 'enable'
viofs_debug_enable_cmd = 'reg add HKLM\Software\VirtIO-FS /v DebugFlags /d 0xFFFFFFFF /t REG_DWORD'
viofs_log_enable_cmd = 'reg add HKLM\Software\VirtIO-FS /v DebugLogFile /d ${viofs_log_file} /t REG_SZ'
viofs_debug_delete_cmd = 'reg delete HKLM\Software\VirtIO-FS /v DebugFlags /f'
viofs_log_delete_cmd = 'reg delete HKLM\Software\VirtIO-FS /v DebugLogFile /f'
viofs_reg_query_cmd = 'reg query HKLM\Software\VirtIO-FS'
virtio_win_media_type = iso
cdroms += " virtio"
106 changes: 106 additions & 0 deletions qemu/tests/virtio_fs_509_memslots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import os

from avocado.utils import process
from virttest import error_context, utils_disk, utils_misc, utils_test

from provider import virtio_fs_utils, virtio_mem_utils


@error_context.context_aware
def run(test, params, env):
"""
1) Boot a guest VM with virtio-fs device
2) Check virtiofs basic functionality works
3) Validate the virtio-mem device has the correct number of memslots
4) Clean environment
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""

vm = env.get_vm(params["main_vm"])
vm.verify_alive()
session = vm.wait_for_login()

os_type = params["os_type"]
cmd_md5 = params.get("cmd_md5")
test_file = params.get("test_file")
io_timeout = params.get_numeric("io_timeout")
fs_source = params.get("fs_source_dir")
fs_target = params.get("fs_target")
fs_dest = params.get("fs_dest")
mem_object_id = params.get("mem_devs")
total_memslots = params.get_numeric("total_memslots")
hmp_timeout = params.get_numeric("hmp_timeout", 10)

try:
if os_type == "windows":
driver_name = params["driver_name"]
# Check whether windows driver is running,and enable driver verifier
session = utils_test.qemu.windrv_check_running_verifier(
session, vm, test, driver_name
)
# create virtiofs service
viofs_svc_name = params["viofs_svc_name"]
virtio_fs_utils.create_viofs_service(
test, params, session, service=viofs_svc_name
)

if os_type == "linux":
utils_misc.make_dirs(fs_dest, session)
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):
utils_misc.safe_rmdir(fs_dest, session=session)
test.fail("Failed to mount virtiofs {fs_target}.")
else:
if params["viofs_svc_name"] == "VirtioFsSvc":
error_context.context(
"Start virtiofs service in the windows guest.", test.log.info
)
debug_log_operation = params.get("debug_log_operation")
if debug_log_operation:
session = virtio_fs_utils.operate_debug_log(
test, params, session, vm, debug_log_operation
)
virtio_fs_utils.start_viofs_service(test, params, session)

# Check md5sum for file on guest and host
host_file = os.path.join(fs_source, test_file)

if os_type == "linux":
guest_file = os.path.join(fs_dest, test_file)
cmd_md5_vm = cmd_md5 % guest_file
else:
volume_letter = virtio_fs_utils.get_virtiofs_driver_letter(
test, fs_target, session
)
guest_file = f"\\{test_file}"
cmd_md5_vm = cmd_md5 % (volume_letter, guest_file)

md5_guest = session.cmd_output(cmd_md5_vm, io_timeout).strip().split()[0]
test.log.info(md5_guest)

md5_host = (
process.run("md5sum %s" % host_file, io_timeout)
.stdout_text.strip()
.split()[0]
)
if md5_guest != md5_host:
test.fail("The md5 value of host is not same to guest.")

# Check memslots
virtio_mem_utils.validate_memslots(
total_memslots, test, vm, mem_object_id, hmp_timeout
)
finally:
if os_type == "linux":
utils_disk.umount(fs_target, fs_dest, "virtiofs", session=session)
utils_misc.safe_rmdir(fs_dest, session=session)
if os_type == "windows":
virtio_fs_utils.delete_viofs_serivce(test, params, session)
session.close()

0 comments on commit 2aae8df

Please sign in to comment.