Skip to content

Commit

Permalink
cpu_topology_test: Add test case to test cpu topology
Browse files Browse the repository at this point in the history
Signed-off-by: Qianqian Zhu <qizhu@redhat.com>
  • Loading branch information
vivianQizhu committed Aug 4, 2020
1 parent b9f1a51 commit ae06322
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
9 changes: 9 additions & 0 deletions qemu/tests/cfg/cpu_topology_test.cfg
@@ -0,0 +1,9 @@
- cpu_topology_test:
no smp2
no WinXP WinVista Win7 Win8 Win8.1 Win2000 Win2003
no Win2008 Win2008..r2 Win2012 Win2012..r2
type = cpu_topology_test
start_vm = no
Linux:
x86_64:
check_siblings_cmd = 'cat /proc/cpuinfo |grep siblings |uniq |cut -d ":" -f 2'
59 changes: 59 additions & 0 deletions qemu/tests/cpu_topology_test.py
@@ -0,0 +1,59 @@
import random

from avocado.utils import cpu

from virttest import error_context
from virttest import env_process

from provider.cpu_utils import check_guest_cpu_topology


@error_context.context_aware
def run(test, params, env):
"""
Check guest gets correct vcpu num, cpu cores, processors, sockets, siblings
1) Boot guest with options: -smp n,cores=x,threads=y,sockets=z...
2) Check cpu topology
: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))

vm_name = params['main_vm']
os_type = params['os_type']
vcpu_threads_list = [1, 2]
if params['machine_type'] == 'pseries':
vcpu_threads_list = [1, 2, 4, 8]
params['vcpu_cores'] = vcpu_cores = random.randint(1, 10)
host_cpu = cpu.online_count()
for vcpu_threads in vcpu_threads_list:
vcpu_sockets = min(max(int(host_cpu) * 5 // (vcpu_cores * vcpu_threads), 1),
random.randint(1, 10))
vcpu_sockets = 2 if (os_type == 'Windows' and
vcpu_sockets > 2) else vcpu_sockets
params['vcpu_sockets'] = vcpu_sockets
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_guest_cpu_topology(session, os_type, vm.cpuinfo)
if params.get('check_siblings_cmd'):
check('sibling', vcpu_threads * vcpu_cores, 'check_siblings_cmd')
vm.destroy()

0 comments on commit ae06322

Please sign in to comment.