Skip to content

Commit

Permalink
KVM: refactor SMP test
Browse files Browse the repository at this point in the history
Signed-off-by: Xudong Hao <xudong.hao@intel.com>
  • Loading branch information
xhao22 committed Feb 25, 2025
1 parent 1910ef2 commit 6fe7185
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 112 deletions.
File renamed without changes.
File renamed without changes.
16 changes: 0 additions & 16 deletions KVM/qemu/mem_coh.cfg

This file was deleted.

9 changes: 7 additions & 2 deletions KVM/qemu/cpuinfo_check.cfg → KVM/qemu/smp.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- cpuinfo_check:
- smp:
no Windows
type = cpuinfo_check
type = smp
virt_test_type = qemu
vm_accelerator = kvm
force_create_image = no
Expand All @@ -9,6 +9,11 @@
kill_vm = yes
auto_cpu_model = "no"
cpu_model = host
variants:
- cpuinfo_chk:
test_tool = cpuinfo_chk.c
- mem_coh:
test_tool = mem_coh.c
variants:
- vm:
- tdvm:
Expand Down
74 changes: 0 additions & 74 deletions KVM/qemu/tests/cpuinfo_check.py

This file was deleted.

47 changes: 27 additions & 20 deletions KVM/qemu/tests/mem_coh.py → KVM/qemu/tests/smp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,50 @@

# Author: Xudong Hao <xudong.hao@intel.com>
#
# History: Jan. 2025 - Xudong Hao - creation
# History: Feb. 2025 - Xudong Hao - creation

import os

from virttest import data_dir, utils_package, utils_misc


def compile_mem_coh(test, vm, session):
def compile_test_tool(test, params, vm, session):
"""
Copy and compile mem_coh on guest
Copy and compile test tool on guest
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param vm: Object qemu_vm.VM
:param session: vm session
:return: Path to binary mem_coh or None if compile failed
:return: Path to test binary or None if compile failed
"""
mem_coh_dir = "/home/"
mem_coh_bin = "mem_coh"
mem_coh_c = "mem_coh.c"
src_file = os.path.join(data_dir.get_deps_dir("mem_coh"), mem_coh_c)
exec_bin = os.path.join(mem_coh_dir, mem_coh_bin)
test_dir = "/home/"
test_src = params["test_tool"]
test_bin = test_src.split(".")[0]
src_file = os.path.join(data_dir.get_deps_dir("smp"), test_src)
exec_bin = os.path.join(test_dir, test_bin)
rm_cmd = "rm -rf %s*" % exec_bin
session.cmd(rm_cmd)
vm.copy_files_to(src_file, mem_coh_dir)
vm.copy_files_to(src_file, test_dir)

if not utils_package.package_install("gcc", session):
test.cancel("Failed to install package gcc.")
compile_cmd = "cd %s && gcc -O2 -lpthread -DCONFIG_SMP -o %s %s" % (mem_coh_dir, mem_coh_bin, mem_coh_c)
compile_cmd = "cd %s && gcc -O2 -lpthread -DCONFIG_SMP -o %s %s" % (test_dir, test_bin, test_src)
guest_status = session.cmd_status(compile_cmd)
if guest_status:
session.cmd_output_safe(rm_cmd)
session.close()
test.fail("Compile mem_coh failed")
test.fail("Compile test tool %s failed." % test_src)
return exec_bin


def run(test, params, env):
"""
Memory coherency function test
SMP(Symmetrical Multi-Processing) function test
1. Boot guest with multiple vCPUs
2. Download and compile mem_coh on guest
3. Run memory coherency test inside guest
2. Download and compile test tool on guest
3. Run test inside guest
4. Shutdown guest
:param test: QEMU test object
Expand All @@ -58,19 +59,25 @@ def run(test, params, env):
def clean(tool_bin):
"""Clean the environment"""
cmd_rm = "rm -rf %s" % tool_bin
cmd_rm += "; rm -rf %s" % tmp_file
if test_tool == "mem_coh.c":
cmd_rm += "; rm -rf %s" % tmp_file
session.cmd_output_safe(cmd_rm)
session.close()

vm = env.get_vm(params["main_vm"])
tmp_file = "/tmp/smp-test-flag1_%s" % utils_misc.generate_random_string(6)
test_tool = params["test_tool"]
if test_tool == "mem_coh.c":
tmp_file = "/tmp/smp-test-flag1_%s" % utils_misc.generate_random_string(6)
vm.verify_alive()
session = vm.wait_for_login()

tool_bin = compile_mem_coh(test, vm, session)
cmd_generate = "dd if=/dev/zero of=%s bs=1M count=10 && %s %s" % (tmp_file, tool_bin, tmp_file)
tool_bin = compile_test_tool(test, params, vm, session)
if test_tool == "mem_coh.c":
cmd_generate = "dd if=/dev/zero of=%s bs=1M count=10 && %s %s" % (tmp_file, tool_bin, tmp_file)
else:
cmd_generate = tool_bin
chk_status = session.cmd_status(cmd_generate)
if chk_status:
clean(tool_bin)
test.fail("Run mem_coh in guest with fail result")
test.fail("Run test %s in guest with fail result." % tool_bin)
clean(tool_bin)

0 comments on commit 6fe7185

Please sign in to comment.