Skip to content

Commit

Permalink
hotplug_mem_share_discard_data: new memory auto case
Browse files Browse the repository at this point in the history
hotplug with share and discard-data options

Signed-off-by: mcasquer <mcasquer@redhat.com>
  • Loading branch information
mcasquer committed Jun 22, 2022
1 parent 7b7e8f6 commit 697807b
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 0 deletions.
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
type = hotplug_mem_share_discard_data
virt_test_type = qemu
login_timeout = 240
start_vm = no
not_preprocess = yes
prealloc_mem = yes
slots_mem = 4
maxmem_mem = 32G
mem_fixed = 4096
mem_devs = mem0
use_mem_mem0 = no
size_mem_mem0 = ${mem_fixed}M
guest_numa_nodes = "node0"
node_num = 1
numa_memdev_node0 = mem-mem0
backend_mem = memory-backend-file
set_node_hugepage = yes
mem-path = /dev/hugepages
target_mems = "plug1"
share_mem_plug1 = yes
size_mem_plug1 = 1G
mem-path_plug1 = /dev/hugepages/test_file
pre_command = "sync && echo 3 > /proc/sys/vm/drop_caches && echo 1 > /proc/sys/vm/compact_memory"
variants:
- backend_ram:
backend_mem_plug1 = memory-backend-ram
- backend_file:
backend_mem_plug1 = memory-backend-file
variants:
- discard_data_on:
discard-data_plug1 = yes
- discard_data_off:
discard-data_plug1 = no
132 changes: 132 additions & 0 deletions qemu/tests/hotplug_mem_share_discard_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import math

from avocado.core import exceptions

from virttest import error_context
from virttest import env_process
from virttest import test_setup

from avocado.utils import memory
from avocado.utils import 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
"""

# Deletes mem-path file to avoid test error
process.system("rm -rf %s" % params["mem-path_plug1"])
hugepage_size = memory.get_huge_page_size()
mem_size = int(normalize_data_size("%sM" % params["mem_fixed"], "K"))

node_num = params.get_numeric("node_num")
prealloc_mem = params.get("prealloc_mem", "yes")
mem_devs = ""
guest_numa_nodes = ""
node_size = params["size_mem_mem0"]

for index in range(node_num):
guest_numa_nodes += "node%s " % index
mem_devs += "mem%s " % index
params["numa_memdev_node%s" % index] = "mem-mem%s" % index
params["size_mem%s" % index] = node_size
params["prealloc_mem%s" % index] = prealloc_mem

timeout = float(params.get("login_timeout", 240))
error_context.base_context("Specify qemu process only allocate HugePages from node0.", test.log.info)
params["target_nodes"] = "0"
params["target_num_node0"] = math.ceil(mem_size / hugepage_size)
error_context.context("Setup huge pages for specify node0.", test.log.info)
error_context.base_context("")

params["guest_numa_nodes"] = guest_numa_nodes
params["mem_devs"] = mem_devs
params["setup_hugepages"] = "yes"
hp_config = test_setup.HugePageConfig(params)
hp_config.setup()
params["start_vm"] = "yes"
params["hugepage_path"] = hp_config.hugepage_path

vm = params['main_vm']
env_process.preprocess_vm(test, params, env, vm)

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

mem_name = params["target_mems"]
hp_size = utils_memory.read_from_meminfo("Hugepagesize")
hp_free = int(utils_memory.read_from_meminfo('HugePages_Free'))
size_target_mem = params["size_mem_%s" % mem_name]

hp_total = int(utils_memory.read_from_meminfo("HugePages_Total"))
hp_plugged = int(normalize_data_size(size_target_mem, "K"))
hp_target = int(hp_plugged / hp_size)\
+ int(hp_total)
process.system("echo %s > /proc/sys/vm/nr_hugepages" % hp_target, shell=True)

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

# Checks if hotplugged device has share: True option
mem_dev_name = "mem-%s" % params["target_mems"]
query_list = vm.monitor.info("memdev")
for dev in query_list:
error_context.context("device id: %s has share: %s" % (dev['id'], dev['share']), test.log.debug)
if dev['id'] == mem_dev_name and dev['share'] is not True:
raise exceptions.TestFail("dev %s has share option: %s" % (dev['id'], dev['share']))

hotplug_test.unplug_memory(vm, mem_name)
hotplug_test.check_memory(vm)

is_discard_data = params.get("discard-data_plug1", "yes")
is_backend_file = params["backend_mem_plug1"]

session.close()
error_context.context("Shutdown guest...")
vm.destroy()

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 is_backend_file == "memory-backend-file":
if is_discard_data == "no":
try:
process.system("ls %s" % params["mem-path_plug1"])
except process.CmdError:
raise exceptions.TestError("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 != hp_plugged:
raise exceptions.TestError("Error, total hugepages doesn't match with used memory")
elif hp_total != hp_free:
raise exceptions.TestError("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"])

0 comments on commit 697807b

Please sign in to comment.