Skip to content

Commit

Permalink
Add consume memory repeat times
Browse files Browse the repository at this point in the history
Signed-off-by: liang-cong-red-hat <[email protected]>
  • Loading branch information
liang-cong-red-hat committed Sep 6, 2024
1 parent 37e94de commit bfc55e2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions virttest/utils_libvirt/libvirt_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,20 @@ def normalize_mem_size(mem_size, mem_unit):
return int(mem_size * 1024**mem_unit_idx)


def consume_vm_freememory(vm_session, consume_value=100000):
def consume_vm_freememory(vm_session, consume_value=100000, repeat_times=1):
"""
Verify the free memory of the vm can be consumed normally
:param vm_session: vm session
:param consume_value: consume value , default 100000
:param repeat_times: consume memory times, default 1
"""
vm_session.cmd_status("swapoff -a")
free_mem = utils_memory.freememtotal(vm_session)
if not utils_package.package_install("numactl", vm_session):
raise exceptions.TestError(
"Fail to install package 'numactl' which provides command 'memhog'"
)
cmd = "memhog %dk" % (free_mem - consume_value)
cmd = "memhog -r%d %dk" % (repeat_times, (free_mem - consume_value))
status, stdout = vm_session.cmd_status_output(cmd, timeout=60)
return (status, stdout)

0 comments on commit bfc55e2

Please sign in to comment.