-
Notifications
You must be signed in to change notification settings - Fork 170
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
add case for discard memory content #5074
Merged
chloerh
merged 1 commit into
autotest:master
from
nanli1:add_case_for_discard_memory_content
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
libvirt/tests/cfg/memory/memory_backing/discard_memory_content_setting.cfg
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,55 @@ | ||
- memory.backing.discard: | ||
type = discard_memory_content_setting | ||
start_vm = "no" | ||
set_pagesize = 2048 | ||
set_pagenum = 1024 | ||
numa_mem = 2097152 | ||
qemu_line = '"discard-data":%s' | ||
variants source: | ||
- file: | ||
source_type = 'file' | ||
source_attr = "'source_type':'${source_type}'" | ||
source_path = {'element_attrs': ['./memoryBacking/source/[@type="${source_type}"]']} | ||
- anonymous: | ||
source_type = 'anonymous' | ||
source_attr = "'source_type':'${source_type}'" | ||
source_path = {'element_attrs': ['./memoryBacking/source/[@type="${source_type}"]']} | ||
- memfd: | ||
source_type = 'memfd' | ||
source_attr = "'source_type':'${source_type}'" | ||
source_path = {'element_attrs': ['./memoryBacking/source/[@type="${source_type}"]']} | ||
- hugepaged_file: | ||
aarch64: | ||
set_pagesize = 524288 | ||
set_pagenum = 4 | ||
source_type = 'hugepage' | ||
hugepages_attr = "'hugepages': {}" | ||
hugepages_path = {'element_attrs': ['./memoryBacking/hugepages']} | ||
variants mem_discard: | ||
- mem_discard_yes: | ||
mem_discard_attr = "'discard':'yes'" | ||
mem_discard_path = {'element_attrs': ["./memoryBacking/discard"]} | ||
- mem_discard_not_defined: | ||
variants numa_discard: | ||
- numa_discard_yes: | ||
no s390-virtio | ||
discard = "yes" | ||
numa_attrs = {'vcpu': 4,'cpu': {'numa_cell': [{'id': '0', 'cpus': '0-3', 'memory': '${numa_mem}', 'unit': 'KiB', 'discard':'${discard}'}]}} | ||
numa_path = {'element_attrs': ['./cpu/numa/cell/[@discard="${discard}"]']} | ||
- numa_discard_no: | ||
no s390-virtio | ||
discard = "no" | ||
numa_attrs = {'vcpu': 4,'cpu': {'numa_cell': [{'id': '0', 'cpus': '0-3', 'memory': '${numa_mem}', 'unit': 'KiB', 'discard':'${discard}'}]}} | ||
numa_path = {'element_attrs': ['./cpu/numa/cell/[@discard="${discard}"]']} | ||
- numa_discard_not_defined: | ||
no s390-virtio | ||
numa_attrs = {'vcpu': 4,'cpu': {'numa_cell': [{'id': '0', 'cpus': '0-3', 'memory': '${numa_mem}', 'unit': 'KiB'}]}} | ||
numa_path = {'element_attrs': ['./cpu/numa/cell/[@memory="${numa_mem}"]']} | ||
- no_numa: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Except this no_numa, other cases are not supported on s390x. So could you help handling this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks dzheng, done |
||
variants: | ||
- memory_allocation: | ||
mem_unit = "KiB" | ||
current_mem_unit = "KiB" | ||
current_mem = "2097152" | ||
mem_value = "2097152" | ||
mem_attrs = {'memory_unit':'${mem_unit}','memory':${mem_value},'current_mem':${current_mem},'current_mem_unit':'${current_mem_unit}'} |
166 changes: 166 additions & 0 deletions
166
libvirt/tests/src/memory/memory_backing/discard_memory_content_setting.py
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,166 @@ | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# | ||
# Copyright Redhat | ||
# | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
# Author: Nannan Li<[email protected]> | ||
# | ||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
from virttest import test_setup | ||
from virttest import libvirt_version | ||
|
||
from virttest.libvirt_xml import vm_xml | ||
from virttest.utils_test import libvirt | ||
from virttest.utils_libvirt import libvirt_vmxml | ||
|
||
|
||
def run(test, params, env): | ||
""" | ||
1. Verify memory discard setting takes effect | ||
2. Verify the numa topology discard setting takes effect | ||
against memory backing setting | ||
""" | ||
|
||
def get_init_vm_attrs(): | ||
""" | ||
Get vm attrs. | ||
|
||
:return vm_attrs: expected vm attrs dict. | ||
""" | ||
mb_value = "" | ||
for item in [source_attr, hugepages_attr, mem_discard_attr]: | ||
if item != "": | ||
mb_value = mb_value + item + "," | ||
|
||
vm_attrs = eval("{'mb':{%s}}" % mb_value[:-1]) | ||
|
||
if numa_attrs: | ||
vm_attrs.update(numa_attrs) | ||
vm_attrs.update(mem_attrs) | ||
test.log.debug("Get current vm attrs is :%s", vm_attrs) | ||
|
||
return vm_attrs | ||
|
||
def get_expected_xpath(): | ||
""" | ||
Get expected xpath. | ||
|
||
:return expect_xpath: Get xpath according to the cfg file. | ||
""" | ||
expect_xpath = [] | ||
for xpath in [numa_path, source_path, hugepages_path, mem_xpath, | ||
mem_discard_path]: | ||
if xpath != "": | ||
expect_xpath.append(eval(xpath)) | ||
test.log.debug("Get expected xpath: %s", expect_xpath) | ||
return expect_xpath | ||
|
||
def get_expected_discard(): | ||
""" | ||
Get expected discard value. | ||
|
||
:return expected_discard : the expected discard value, True or False | ||
:return existed: expected the expected_discard exist or not | ||
""" | ||
expected_discard, existed = "true", True | ||
|
||
if source in ["file", "hugepaged_file"]: | ||
if mem_discard == "mem_discard_yes" and numa_discard in \ | ||
["numa_discard_yes", "numa_discard_not_defined", "no_numa"]: | ||
expected_discard = "true" | ||
|
||
elif mem_discard == "mem_discard_not_defined" and \ | ||
numa_discard == "numa_discard_yes": | ||
expected_discard = "true" | ||
|
||
elif mem_discard in ["mem_discard_yes", "mem_discard_not_defined"] \ | ||
and numa_discard == "numa_discard_no": | ||
# Check libvirt version for numa_discard_no scenario | ||
if libvirt_version.version_compare(9, 0, 0): | ||
expected_discard = "false" | ||
else: | ||
existed = False | ||
else: | ||
existed = False | ||
|
||
elif source in ["anonymous", "memfd"]: | ||
existed = False | ||
|
||
test.log.debug("Get expected discard:%s, discard existed: %s", | ||
expected_discard, existed) | ||
return expected_discard, existed | ||
|
||
def setup_test(): | ||
""" | ||
Prepare memory device | ||
""" | ||
test.log.info("TEST_SETUP: Set hugepage.") | ||
hp_cfg.set_kernel_hugepages(set_pagesize, set_pagenum) | ||
|
||
def run_test(): | ||
""" | ||
""" | ||
test.log.info("TEST_STEP1: Define vm.") | ||
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) | ||
vm_attrs = get_init_vm_attrs() | ||
vmxml.setup_attrs(**vm_attrs) | ||
vmxml.sync() | ||
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) | ||
test.log.debug("After define vm, vm xml is:\n:%s", vmxml) | ||
|
||
test.log.info("TEST_STEP2: Start vm.") | ||
vm.start() | ||
vm.wait_for_login().close() | ||
|
||
test.log.info("TEST_STEP3: Check the xml config.") | ||
vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name) | ||
expect_xpath = get_expected_xpath() | ||
libvirt_vmxml.check_guest_xml_by_xpaths(vmxml, expect_xpath) | ||
|
||
test.log.info("TEST_STEP4: Check the qemu cmd line.") | ||
expected_discard, existed = get_expected_discard() | ||
libvirt.check_qemu_cmd_line(qemu_line % expected_discard, | ||
expect_exist=existed) | ||
|
||
def teardown_test(): | ||
""" | ||
Clean data. | ||
""" | ||
test.log.info("TEST_TEARDOWN: Clean up env.") | ||
hp_cfg.cleanup() | ||
bkxml.sync() | ||
|
||
vm_name = params.get("main_vm") | ||
vm = env.get_vm(vm_name) | ||
vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) | ||
bkxml = vmxml.copy() | ||
|
||
qemu_line = params.get("qemu_line") | ||
numa_discard = params.get("numa_discard") | ||
mem_discard = params.get("mem_discard") | ||
set_pagesize = params.get("set_pagesize") | ||
set_pagenum = params.get("set_pagenum") | ||
|
||
source_attr = params.get("source_attr", '') | ||
hugepages_attr = params.get("hugepages_attr", '') | ||
mem_discard_attr = params.get("mem_discard_attr", '') | ||
numa_attrs = eval(params.get("numa_attrs", '{}')) | ||
mem_attrs = eval(params.get("mem_attrs", '{}')) | ||
mem_discard_attr = params.get("mem_discard_attr", '') | ||
|
||
numa_path = params.get("numa_path", '') | ||
source_path = params.get("source_path", '') | ||
hugepages_path = params.get("hugepages_path", '') | ||
mem_xpath = params.get("mem_xpath", '') | ||
mem_discard_path = params.get("mem_discard_path", '') | ||
source = params.get("source", '') | ||
hp_cfg = test_setup.HugePageConfig(params) | ||
|
||
try: | ||
setup_test() | ||
run_test() | ||
|
||
finally: | ||
teardown_test() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default huge pagesize on XXXX-8 aarch64 is 512M, but above setting is for 2M pagesize. Please adjust the test to accommodate aarch64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks hshuai,Done , Please help heck