Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotplug_mem_share_discard_data: new auto case for memory hotplug with share and discard-data options #3349

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions qemu/tests/cfg/hotplug_mem_share_discard_data.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
- hotplug_mem_share_discard_data:
only Linux
mcasquer marked this conversation as resolved.
Show resolved Hide resolved
type = hotplug_mem_share_discard_data
virt_test_type = qemu
login_timeout = 240
prealloc_mem = yes
not_preprocess = yes
slots_mem = 4
maxmem_mem = 32G
mem_fixed = 4096
use_mem_mem0 = no
mem_devs = 'mem0'
guest_numa_nodes = 'node0'
size_mem_mem0 = ${mem_fixed}M
numa_memdev_node0 = mem-mem0
backend_mem = memory-backend-file
target_mems = "plug1"
share_mem_plug1 = yes
size_mem_plug1 = 1G
pre_command = "sync && echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory"
mem-path = /mnt/kvm_hugepage
threshold = 0.15
variants:
- backend_ram:
yanan-fu marked this conversation as resolved.
Show resolved Hide resolved
required_qemu = [6.1.0, )
backend_mem_plug1 = memory-backend-ram
yanan-fu marked this conversation as resolved.
Show resolved Hide resolved
- backend_file:
backend_mem_plug1 = memory-backend-file
mem-path_plug1 = /mnt/kvm_hugepage/test_file
pre_command += " && rm -rf ${mem-path_plug1}"
variants:
mcasquer marked this conversation as resolved.
Show resolved Hide resolved
- discard_data_on:
discard-data_plug1 = yes
- discard_data_off:
discard-data_plug1 = no
88 changes: 88 additions & 0 deletions qemu/tests/hotplug_mem_share_discard_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from avocado.utils import process

from virttest import error_context
from virttest import env_process

from virttest.utils_numeric import normalize_data_size
from virttest.utils_test.qemu import MemoryHotplugTest
from virttest.staging import utils_memory


@error_context.context_aware
def run(test, params, env):
"""
Memory share and discard-data hotplug test
1) Setup hugepages
2) Mount /mnt/kvm_hugepage
3) Boot guest with one numa node
4) Hotplug 1G memory
5) Check memory
6) Unplug memory
7) Check memory
8) Check results for discard-data value

:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment
"""

timeout = int(params.get("login_timeout", 240))

mem_dev = params.get('mem_devs')
size_mem = int(normalize_data_size(params['size_mem_%s' % mem_dev], 'K'))
total_hg_size = size_mem

target_mem = params.get("target_mems")
if params.get('backend_mem_%s' % target_mem) == 'memory-backend-file':
size_target_mem = int(normalize_data_size(params['size_mem_%s' % target_mem], 'K'))
total_hg_size += size_target_mem

hp_size = utils_memory.read_from_meminfo("Hugepagesize")
params['target_hugepages'] = int(total_hg_size // hp_size)
params['setup_hugepages'] = "yes"
params['not_preprocess'] = "no"

env_process.preprocess(test, params, env)

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

hotplug_test = MemoryHotplugTest(test, params, env)
hotplug_test.hotplug_memory(vm, target_mem)
hotplug_test.check_memory(vm)
hotplug_test.unplug_memory(vm, target_mem)
hotplug_test.check_memory(vm)

session.close()
error_context.context("Shutdown guest...", test.log.debug)
vm.destroy()
yanan-fu marked this conversation as resolved.
Show resolved Hide resolved

hp_total = int(utils_memory.read_from_meminfo("HugePages_Total"))
hp_free = int(utils_memory.read_from_meminfo('HugePages_Free'))

error_context.context("hp_total: %s" % str(hp_total), test.log.debug)
error_context.context("hp_free: %s" % str(hp_free), test.log.debug)

if params.get("backend_mem_plug1") == "memory-backend-file":
if not params.get_boolean("discard-data_plug1", True):
yanan-fu marked this conversation as resolved.
Show resolved Hide resolved
try:
process.system("ls %s" % params["mem-path_plug1"])
except process.CmdError:
test.fail("Error, %s not found." % params["mem-path_plug1"])

op = (hp_total - hp_free) * (hp_size / 1024)
hp_used = int(normalize_data_size("%sM" % str(op), "K"))

error_context.context("hp_used: %s" % str(hp_used), test.log.debug)

if hp_used != size_target_mem:
test.fail("Error, total hugepages doesn't match with used memory")
elif hp_total != hp_free:
test.fail("Error, free hugepages doesn't match with total hugepages")
# Deletes the mem-path file to avoid test error
process.system("rm -rf %s" % params["mem-path_plug1"])
yanan-fu marked this conversation as resolved.
Show resolved Hide resolved
# Compares free and total memory values after deleting mem-path file
hp_free_after_delete = int(utils_memory.read_from_meminfo('HugePages_Free'))
if hp_total != hp_free_after_delete:
test.fail("Error, free hugepages doesn't match with total hugepages after deleting mem-path file")