Skip to content

Commit

Permalink
Merge pull request #5335 from dzhengfy/case_cpu_comare
Browse files Browse the repository at this point in the history
virsh_cpu_compare_xml: add case change cpu vendor
  • Loading branch information
Yingshun authored Jan 15, 2024
2 parents 0a4c6d0 + 380433f commit c2527f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
compare_file_type = "domxml"
variants:
- custom_mode:
no aarch64
cpu_mode = "custom"
status_error = "yes"
msg_pattern = "incompatible"
Expand All @@ -19,6 +20,11 @@
variants:
- action_none:
msg_pattern = "identical"
- change_vendor:
no s390_virtio, ppc64le
cpu_compare_mode = "modify"
msg_pattern = "incompatible"
status_error = "yes"
- delete_features:
cpu_compare_mode = "delete"
status_error = "no"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import logging as log

from avocado.utils import cpu

from virttest import virsh
from virttest import libvirt_version
from virttest.libvirt_xml import vm_xml
Expand Down Expand Up @@ -66,11 +68,48 @@ def get_domcapa_xml(extract=False):
return domcapa_xml


def get_capa_xml(operate='', extract=False):
def get_different_cpu_vendor(test, current_cpu_vendor):
"""
Get a different cpu vendor from current host cpu vendor
:param test: test object
:param current_cpu_vendor: str, current host cpu vendor
:return: str, the selected cpu vendor
"""
arch_cpu_vendor_mapping = {'x86_64': ['GenuineIntel', 'AuthenticAMD'],
'aarch64': ['Ampere(R)', 'Ampere(TM)',
'AppliedMicro', 'ARM', 'NVIDIA',
'FUJITSU', 'Cavium Inc.',
'Marvell', 'Qualcomm',
'CN8890-2000BG2601-AAP-PR-Y-G',
'CN8880-1800BG2601-CP-Y-G']}

host_arch = cpu.get_arch()
if host_arch.lower() not in arch_cpu_vendor_mapping:
test.error("The host arch '%s' is not supported for this case" % host_arch)
cpu_vendors = arch_cpu_vendor_mapping[host_arch]
new_vendor = ''
for vendor_index in range(0, len(cpu_vendors)):
if cpu_vendors[vendor_index].count(current_cpu_vendor):
if vendor_index == len(cpu_vendors) - 1:
new_vendor = cpu_vendors[0]
else:
new_vendor = cpu_vendors[vendor_index + 1]
break
if new_vendor:
test.log.debug("Found a different cpu vendor '%s'", new_vendor)
return new_vendor
else:
test.error("Can not find a different one from "
"current cpu vendor '%s'" % current_cpu_vendor)


def get_capa_xml(test, operate='', extract=False):
"""
Get full capabilities xml or the cpu definition
from capabilities xml
:param test: test object
:param operate: Operation mode, decide file's detail
:param extract: Setting True means to extract cpu definition
from capabilities xml
Expand All @@ -79,6 +118,9 @@ def get_capa_xml(operate='', extract=False):
capa_xml = capability_xml.CapabilityXML()
if operate == 'delete':
capa_xml.remove_feature(num=-1)
elif operate == 'modify':
new_vendor = get_different_cpu_vendor(test, capa_xml.vendor)
capa_xml.vendor = new_vendor
if extract:
capa_xml.xmltreefile = capa_xml.xmltreefile.reroot('/host/cpu')
return capa_xml
Expand Down Expand Up @@ -138,7 +180,7 @@ def run(test, params, env):
cpu_compare_xml = get_domcapa_xml(is_extracted)

if file_type == "capa_xml":
cpu_compare_xml = get_capa_xml(cpu_compare_mode, is_extracted)
cpu_compare_xml = get_capa_xml(test, cpu_compare_mode, is_extracted)

if cpu_compare_mode == "invalid_test":
cpu_compare_xml = get_invalid_xml(cpu_compare_xml)
Expand Down

0 comments on commit c2527f0

Please sign in to comment.