[libvirt] [PATCH 30/33] cputest: Test virQEMUCapsInitCPUModel

Jiri Denemark jdenemar at redhat.com
Wed Feb 15 10:15:24 UTC 2017


The original test didn't use family/model numbers to make better
decisions about the CPU model and thus mis-detected the model in the two
cases which are modified in this commit. The detected CPU models now
match those obtained from raw CPUID data.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
---
 tests/cputest.c                                    | 28 +++++++++++++++-------
 .../x86_64-cpuid-Core-i7-5600U-json.xml            | 11 +++++----
 .../cputestdata/x86_64-cpuid-Core2-E6850-json.xml  |  4 ++--
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index c0a816b60..8c16fb95c 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -43,7 +43,9 @@
 #if WITH_QEMU && WITH_YAJL
 # include "testutilsqemu.h"
 # include "qemumonitortestutils.h"
-# include "qemu/qemu_monitor_json.h"
+# define __QEMU_CAPSRIV_H_ALLOW__
+# include "qemu/qemu_capspriv.h"
+# undef __QEMU_CAPSRIV_H_ALLOW__
 #endif
 
 #define VIR_FROM_THIS VIR_FROM_CPU
@@ -517,14 +519,15 @@ static int
 cpuTestJSONCPUID(const void *arg)
 {
     const struct data *data = arg;
-    virCPUDataPtr cpuData = NULL;
+    qemuMonitorCPUModelInfoPtr model = NULL;
+    virQEMUCapsPtr qemuCaps = NULL;
     virCPUDefPtr cpu = NULL;
     qemuMonitorTestPtr testMon = NULL;
     char *json = NULL;
     char *result = NULL;
     int ret = -1;
 
-    if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json",
+    if (virAsprintf(&json, "%s/cputestdata/%s-cpuid-%s.json.new",
                     abs_srcdir, virArchToString(data->arch), data->host) < 0 ||
         virAsprintf(&result, "cpuid-%s-json", data->host) < 0)
         goto cleanup;
@@ -532,26 +535,35 @@ cpuTestJSONCPUID(const void *arg)
     if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
         goto cleanup;
 
-    if (qemuMonitorJSONGetCPUx86Data(qemuMonitorTestGetMonitor(testMon),
-                                     "feature-words", &cpuData) < 0)
+    if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon),
+                                        QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC,
+                                        "host", &model) < 0)
         goto cleanup;
 
+    if (!(qemuCaps = virQEMUCapsNew()))
+        goto cleanup;
+
+    virQEMUCapsSetArch(qemuCaps, data->arch);
+    virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
+    model = NULL;
+
     if (VIR_ALLOC(cpu) < 0)
         goto cleanup;
 
-    cpu->arch = cpuData->arch;
+    cpu->arch = data->arch;
     cpu->type = VIR_CPU_TYPE_GUEST;
     cpu->match = VIR_CPU_MATCH_EXACT;
     cpu->fallback = VIR_CPU_FALLBACK_FORBID;
 
-    if (cpuDecode(cpu, cpuData, NULL, 0, NULL) < 0)
+    if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu) != 0)
         goto cleanup;
 
     ret = cpuTestCompareXML(data->arch, cpu, result, false);
 
  cleanup:
+    qemuMonitorCPUModelInfoFree(model);
+    virObjectUnref(qemuCaps);
     qemuMonitorTestFree(testMon);
-    virCPUDataFree(cpuData);
     virCPUDefFree(cpu);
     VIR_FREE(result);
     VIR_FREE(json);
diff --git a/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml b/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
index 159797178..8a6b8283f 100644
--- a/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-Core-i7-5600U-json.xml
@@ -1,12 +1,15 @@
 <cpu mode='custom' match='exact'>
   <arch>x86_64</arch>
-  <model fallback='forbid'>Skylake-Client</model>
+  <model fallback='forbid'>Broadwell</model>
+  <feature policy='require' name='vme'/>
   <feature policy='require' name='ss'/>
   <feature policy='require' name='vmx'/>
+  <feature policy='require' name='f16c'/>
+  <feature policy='require' name='rdrand'/>
   <feature policy='require' name='hypervisor'/>
+  <feature policy='require' name='arat'/>
   <feature policy='require' name='tsc_adjust'/>
+  <feature policy='require' name='xsaveopt'/>
   <feature policy='require' name='pdpe1gb'/>
-  <feature policy='disable' name='mpx'/>
-  <feature policy='disable' name='xsavec'/>
-  <feature policy='disable' name='xgetbv1'/>
+  <feature policy='require' name='abm'/>
 </cpu>
diff --git a/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml b/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
index ddd730735..e93e0a321 100644
--- a/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
+++ b/tests/cputestdata/x86_64-cpuid-Core2-E6850-json.xml
@@ -1,11 +1,11 @@
 <cpu mode='custom' match='exact'>
   <arch>x86_64</arch>
-  <model fallback='forbid'>Penryn</model>
+  <model fallback='forbid'>Conroe</model>
   <feature policy='require' name='vme'/>
   <feature policy='require' name='ss'/>
+  <feature policy='require' name='cx16'/>
   <feature policy='require' name='x2apic'/>
   <feature policy='require' name='tsc-deadline'/>
   <feature policy='require' name='hypervisor'/>
   <feature policy='require' name='tsc_adjust'/>
-  <feature policy='disable' name='sse4.1'/>
 </cpu>
-- 
2.11.1




More information about the libvir-list mailing list