From bd70448cef62202be8863a0d3a02506769e5c668 Mon Sep 17 00:00:00 2001 From: Yumei Huang Date: Thu, 7 Dec 2017 16:35:14 +0800 Subject: [PATCH] numa_basic: Check node free memory before test Signed-off-by: Yumei Huang --- qemu/tests/numa_basic.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/qemu/tests/numa_basic.py b/qemu/tests/numa_basic.py index 3ba33b8a..33cb168f 100644 --- a/qemu/tests/numa_basic.py +++ b/qemu/tests/numa_basic.py @@ -1,14 +1,13 @@ import logging -from autotest.client.shared import error - from virttest import env_process from virttest import utils_misc from virttest import utils_test +from virttest import error_context from virttest.staging import utils_memory -@error.context_aware +@error_context.context_aware def run(test, params, env): """ Qemu numa basic test: @@ -23,24 +22,28 @@ def run(test, params, env): :param params: Dictionary with the test parameters :param env: Dictionary with test environment. """ - error.context("Get host numa topological structure", logging.info) + error_context.context("Get host numa topological structure", logging.info) timeout = float(params.get("login_timeout", 240)) host_numa_node = utils_misc.NumaInfo() node_list = host_numa_node.online_nodes for node_id in node_list: - error.base_context("Bind qemu process to numa node %s" % node_id, - logging.info) + error_context.base_context("Bind qemu process to numa node %s" % node_id, + logging.info) vm = "vm_bind_to_%s" % node_id params['qemu_command_prefix'] = "numactl --cpunodebind=%s" % node_id utils_memory.drop_caches() + node_MemFree = int(host_numa_node.read_from_node_meminfo(node_id, + "MemFree")) + if node_MemFree < int(params["mem"]) * 1024: + test.cancel("No enough free memory in node %d." % node_id) env_process.preprocess_vm(test, params, env, vm) vm = env.get_vm(vm) vm.verify_alive() session = vm.wait_for_login(timeout=timeout) session.close() - error.context("Check the memory use status of qemu process", - logging.info) + error_context.context("Check the memory use status of qemu process", + logging.info) memory_status, _ = utils_test.qemu.get_numa_status(host_numa_node, vm.get_pid()) node_used_most = 0 @@ -52,9 +55,7 @@ def run(test, params, env): logging.debug("Qemu used %s pages in node" " %s" % (memory_status[index], node_list[index])) if node_used_most != node_id: - raise error.TestFail("Qemu still use memory from other node." - " Expect: %s, used: %s" % (node_id, - node_used_most)) - - error.context("Destroy guest.", logging.info) + test.fail("Qemu still use memory from other node. " + "Expect: %s, used: %s" % (node_id, node_used_most)) + error_context.context("Destroy guest.", logging.info) vm.destroy() -- GitLab