From 252e9022c0e003a306f101e8ba3f9dbfa824eb2f Mon Sep 17 00:00:00 2001 From: Qianqian Zhu Date: Wed, 29 Jul 2020 16:03:12 +0800 Subject: [PATCH] cpu_topology_test: Add test case to test cpu topology Signed-off-by: Qianqian Zhu --- qemu/tests/cfg/cpu_topology_test.cfg | 12 +++++++ qemu/tests/cpu_topology_test.py | 50 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 qemu/tests/cfg/cpu_topology_test.cfg create mode 100644 qemu/tests/cpu_topology_test.py diff --git a/qemu/tests/cfg/cpu_topology_test.cfg b/qemu/tests/cfg/cpu_topology_test.cfg new file mode 100644 index 00000000000..48560be08c2 --- /dev/null +++ b/qemu/tests/cfg/cpu_topology_test.cfg @@ -0,0 +1,12 @@ +- cpu_topology_test: + no smp2 + only Linux + type = cpu_topology_test + start_vm = no + check_sockets_cmd = 'cat /proc/cpuinfo | grep "physical id" | sort | uniq |wc -l ' + check_cores_cmd = 'cat /proc/cpuinfo | grep "cpu cores" |uniq |cut -d ":" -f 2' + check_siblings_cmd = 'cat /proc/cpuinfo |grep siblings |uniq |cut -d ":" -f 2' + ppc64, ppc64le: + check_sockets_cmd = 'lscpu | grep "Socket(s)" | cut -d ":" -f 2' + check_cores_cmd = 'lscpu | grep "Core(s) per socket" | cut -d ":" -f 2' + check_threads_cmd = 'lscpu | grep "Thread(s) per core" | cut -d ":" -f 2' diff --git a/qemu/tests/cpu_topology_test.py b/qemu/tests/cpu_topology_test.py new file mode 100644 index 00000000000..96a54aedc51 --- /dev/null +++ b/qemu/tests/cpu_topology_test.py @@ -0,0 +1,50 @@ +import random + +from virttest import error_context +from virttest import env_process + + +@error_context.context_aware +def run(test, params, env): + """ + + :param test: QEMU test object. + :param params: Dictionary with test parameters. + :param env: Dictionary with the test environment. + """ + + def check(p_name, exp, check_cmd): + """ + Check the cpu property inside guest + :param p_name: Property name + :param exp: The expect value + :param check_cmd: The param to get check command + """ + res = session.cmd_output(params[check_cmd]).strip() + if int(res) != int(exp): + test.fail('The vcpu %s number inside guest is %s,' + ' while it is set to %s' % (p_name, res, exp)) + + params['vcpu_cores'] = vcpu_cores = random.randint(1, 10) + vcpu_threads_list = [1, 2] + if params['machine_type'] == 'pseries': + vcpu_threads_list = [1, 2, 4, 8] + vcpu_sockets = random.randint(1, 10) + params['vcpu_sockets'] = 2 if ( + params.get("os_type") == 'windows') else vcpu_sockets + vm_name = params['main_vm'] + for vcpu_threads in vcpu_threads_list: + params['vcpu_threads'] = vcpu_threads + params['smp'] = params['vcpu_maxcpus'] = (vcpu_cores * + vcpu_threads * vcpu_sockets) + params['start_vm'] = 'yes' + env_process.preprocess_vm(test, params, env, vm_name) + vm = env.get_vm(vm_name) + session = vm.wait_for_login() + check('socket', vcpu_sockets, 'check_sockets_cmd') + check('core', vcpu_cores, 'check_cores_cmd') + if params.get('check_siblings_cmd'): + check('sibling', vcpu_threads * vcpu_cores, 'check_siblings_cmd') + if params.get('check_threads_cmd'): + check('thread', vcpu_threads, 'check_threads_cmd') + vm.destroy()