Gather query-cpu-definitions results and use them for testing CPU model
usability blockers in CPUID to virCPUDef translation.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
Reviewed-by: John Ferlan <jferlan(a)redhat.com>
---
Notes:
Version 2:
- no change
src/qemu/qemu_capabilities.c | 2 +-
src/qemu/qemu_capspriv.h | 5 +++++
tests/cputest.c | 12 +++++++++++-
tests/cputestdata/cpu-cpuid.py | 26 +++++++++++++++++++-------
tests/cputestdata/cpu-gather.sh | 1 +
5 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8803980495..4de411e397 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -2933,7 +2933,7 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps,
}
-static int
+int
virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
qemuMonitorPtr mon,
bool tcg)
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index d05256bd35..f23995ec6e 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -101,4 +101,9 @@ virQEMUCapsParseHelpStr(const char *qemu,
int
virQEMUCapsParseDeviceStr(virQEMUCapsPtr qemuCaps,
const char *str);
+
+int
+virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
+ qemuMonitorPtr mon,
+ bool tcg);
#endif
diff --git a/tests/cputest.c b/tests/cputest.c
index dcfdf57d43..0a07a2da14 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -673,6 +673,7 @@ cpuTestUpdateLive(const void *arg)
typedef enum {
JSON_NONE,
JSON_HOST,
+ JSON_MODELS,
} cpuTestCPUIDJson;
#if WITH_QEMU && WITH_YAJL
@@ -704,10 +705,19 @@ cpuTestJSONCPUID(const void *arg)
if (!(qemuCaps = virQEMUCapsNew()))
goto cleanup;
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_KVM);
+ if (data->flags == JSON_MODELS)
+ virQEMUCapsSet(qemuCaps, QEMU_CAPS_QUERY_CPU_DEFINITIONS);
+
virQEMUCapsSetArch(qemuCaps, data->arch);
virQEMUCapsSetCPUModelInfo(qemuCaps, VIR_DOMAIN_VIRT_KVM, model);
model = NULL;
+ if (virQEMUCapsProbeQMPCPUDefinitions(qemuCaps,
+ qemuMonitorTestGetMonitor(testMon),
+ false) < 0)
+ goto cleanup;
+
if (VIR_ALLOC(cpu) < 0)
goto cleanup;
@@ -870,7 +880,7 @@ mymain(void)
do { \
if (json != JSON_NONE) { \
DO_TEST(arch, cpuTestJSONCPUID, host, host, \
- NULL, NULL, 0, 0); \
+ NULL, NULL, json, 0); \
} \
} while (0)
#else
diff --git a/tests/cputestdata/cpu-cpuid.py b/tests/cputestdata/cpu-cpuid.py
index a2fd938c24..4fe8e8b952 100755
--- a/tests/cputestdata/cpu-cpuid.py
+++ b/tests/cputestdata/cpu-cpuid.py
@@ -228,17 +228,22 @@ def parseFeatureWords(path):
s = f.read()
props = {}
- for i in range(5):
+ rest = []
+ chunk = 0
+ while s != "":
(data, pos) = dec.raw_decode(s)
- if i == 0:
+ if chunk == 0:
features = data["return"]
- else:
+ elif chunk < 5:
keys = ["family", "model", "stepping",
"model-id"]
- props[keys[i - 1]] = data["return"]
+ props[keys[chunk - 1]] = data["return"]
+ else:
+ rest.append(data)
while pos < len(s) and s[pos] != "{":
pos += 1
s = s[pos:]
+ chunk += 1
if props["model-id"].find("Intel") != -1:
props["vendor"] = "GenuineIntel"
@@ -255,13 +260,13 @@ def parseFeatureWords(path):
leaf = cpuidLeaf(cpuid, in_eax, in_ecx)
leaf[feat["cpuid-register"].lower()] = feat["features"]
- return props, cpuid
+ return props, cpuid, rest
def parseQemu(path, features):
cpuid = {}
with open(path, "r") as f:
- data = json.load(f)
+ data, pos = json.JSONDecoder().raw_decode(f.read())
for (prop, val) in
data["return"]["model"]["props"].iteritems():
if val and prop in features:
@@ -288,6 +293,7 @@ def parseCpuid(path):
def formatCpuid(cpuid, path, comment):
+ print path
with open(path, "w") as f:
f.write("<!-- " + comment + " -->\n")
f.write("<cpudata arch='x86'>\n")
@@ -304,19 +310,25 @@ def formatCpuid(cpuid, path, comment):
def convert(path):
- props, cpuid = parseFeatureWords(path)
+ props, cpuid, rest = parseFeatureWords(path)
for feature in cpuidMap:
value = cpuidIsSet(cpuid, feature)
for name in feature["names"]:
props[name] = value
+ print path
with open(path, "w") as f:
json.dump({"return": {"model": {"name":
"base", "props": props}},
"id": "model-expansion"},
f, indent = 2, separators = (',', ': '))
f.write("\n")
+ for chunk in rest:
+ f.write("\n")
+ json.dump(chunk, f, indent = 2, separators = (',', ': '))
+ f.write("\n")
+
def diff(features, path):
base = path.replace(".json", "")
diff --git a/tests/cputestdata/cpu-gather.sh b/tests/cputestdata/cpu-gather.sh
index 83963557ec..9c696f57bd 100755
--- a/tests/cputestdata/cpu-gather.sh
+++ b/tests/cputestdata/cpu-gather.sh
@@ -58,5 +58,6 @@ $(
qom_get model-id
fi
)
+{"execute":"query-cpu-definitions","id":"definitions"}
{"execute":"quit"}
EOF
--
2.14.2