int ncpus;
unsigned int flags;
int result;
+ GHashTable *existingTestCases;
};
#if WITH_QEMU
static virCPUDef *
-cpuTestLoadXML(virArch arch, const char *name)
+cpuTestLoadXML(virArch arch,
+ const char *name,
+ GHashTable *existingTestCases)
{
g_autofree char *xml = NULL;
g_autoptr(xmlDoc) doc = NULL;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
+ virTestCaseMarkUsed(existingTestCases, xml);
+
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
return NULL;
static virCPUDef **
cpuTestLoadMultiXML(virArch arch,
const char *name,
+ GHashTable *existingTestCases,
unsigned int *count)
{
g_autofree char *xml = NULL;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
+ virTestCaseMarkUsed(existingTestCases, xml);
+
if (!(doc = virXMLParseFileCtxt(xml, &ctxt)))
return NULL;
static int
cpuTestCompareXML(virArch arch,
virCPUDef *cpu,
- const char *name)
+ const char *name,
+ GHashTable *existingTestCases)
{
g_autofree char *xml = NULL;
g_autofree char *actual = NULL;
xml = g_strdup_printf("%s/cputestdata/%s-%s.xml", abs_srcdir,
virArchToString(arch), name);
+ virTestCaseMarkUsed(existingTestCases, xml);
+
if (!(actual = virCPUDefFormat(cpu, NULL)))
return -1;
g_autoptr(virCPUDef) cpu = NULL;
virCPUCompareResult result;
- if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
- !(cpu = cpuTestLoadXML(data->arch, data->name)))
+ if (!(host = cpuTestLoadXML(data->arch, data->host,
+ data->existingTestCases)) ||
+ !(cpu = cpuTestLoadXML(data->arch, data->name,
+ data->existingTestCases))) {
return -1;
+ }
result = virCPUCompare(host->arch, host, cpu, false);
if (data->result == VIR_CPU_COMPARE_ERROR)
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
g_autofree char *result = NULL;
- if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
- !(cpu = cpuTestLoadXML(data->arch, data->name)))
+ if (!(host = cpuTestLoadXML(data->arch, data->host,
+ data->existingTestCases)) ||
+ !(cpu = cpuTestLoadXML(data->arch, data->name,
+ data->existingTestCases))) {
goto cleanup;
+ }
if (virCPUConvertLegacy(host->arch, cpu) < 0)
goto cleanup;
result = virBufferContentAndReset(&buf);
- if (cpuTestCompareXML(data->arch, cpu, result) < 0)
+ if (cpuTestCompareXML(data->arch, cpu, result, data->existingTestCases) < 0)
goto cleanup;
ret = 0;
const char *suffix;
size_t i;
- if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name, &ncpus)))
+ if (!(cpus = cpuTestLoadMultiXML(data->arch, data->name,
+ data->existingTestCases, &ncpus))) {
goto cleanup;
+ }
baseline = virCPUBaseline(data->arch, cpus, ncpus, NULL, NULL,
!!(data->flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE));
suffix = "result";
result = g_strdup_printf("%s-%s", data->name, suffix);
- if (cpuTestCompareXML(data->arch, baseline, result) < 0)
+ if (cpuTestCompareXML(data->arch, baseline, result,
+ data->existingTestCases) < 0) {
goto cleanup;
+ }
for (i = 0; i < ncpus; i++) {
virCPUCompareResult cmp;
g_autoptr(virCPUDef) cpu = NULL;
g_autofree char *result = NULL;
- if (!(host = cpuTestLoadXML(data->arch, data->host)) ||
- !(cpu = cpuTestLoadXML(data->arch, data->name)))
+ if (!(host = cpuTestLoadXML(data->arch, data->host,
+ data->existingTestCases)) ||
+ !(cpu = cpuTestLoadXML(data->arch, data->name,
+ data->existingTestCases))) {
return -1;
+ }
if (!(migHost = virCPUCopyMigratable(data->arch, host)))
return -1;
result = g_strdup_printf("%s+%s", data->host, data->name);
- return cpuTestCompareXML(data->arch, cpu, result);
+ return cpuTestCompareXML(data->arch, cpu, result, data->existingTestCases);
}
g_autoptr(virCPUData) hostData = NULL;
int result;
- if (!(host = cpuTestLoadXML(data->arch, data->host)))
+ if (!(host = cpuTestLoadXML(data->arch, data->host, data->existingTestCases)))
return -1;
if (cpuEncode(host->arch, host, NULL, &hostData,
g_autoptr(virCPUDef) cpu = NULL;
int result;
- if (!(cpu = cpuTestLoadXML(data->arch, data->name)))
+ if (!(cpu = cpuTestLoadXML(data->arch, data->name, data->existingTestCases)))
return -1;
result = virCPUValidateFeatures(data->arch, cpu);
json = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.json", abs_srcdir,
virArchToString(data->arch), data->host);
+ virTestCaseMarkUsed(data->existingTestCases, json);
+
if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
return NULL;
hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
virArchToString(data->arch), data->host);
+ virTestCaseMarkUsed(data->existingTestCases, hostFile);
+
if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host)))
return -1;
result = g_strdup_printf("cpuid-%s-%s", data->host, guest ? "guest" : "host");
- return cpuTestCompareXML(data->arch, cpu, result);
+ return cpuTestCompareXML(data->arch, cpu, result, data->existingTestCases);
}
g_autofree char *name = NULL;
name = g_strdup_printf("cpuid-%s-json", data->cpus[i]);
- if (!(cpus[i] = cpuTestLoadXML(data->arch, name)))
+ if (!(cpus[i] = cpuTestLoadXML(data->arch, name,
+ data->existingTestCases))) {
goto cleanup;
+ }
}
baseline = virCPUBaseline(data->arch, cpus, data->ncpus, NULL, NULL, false);
result = g_strdup_printf("cpuid-baseline-%s", data->name);
- if (cpuTestCompareXML(data->arch, baseline, result) < 0)
+ if (cpuTestCompareXML(data->arch, baseline, result,
+ data->existingTestCases) < 0) {
goto cleanup;
+ }
for (i = 0; i < data->ncpus; i++) {
virCPUCompareResult cmp;
"model: %3$3u (0x%3$02x)\n" "stepping: %4$3u (0x%4$02x)\n",
signature, family, model, stepping);
+ virTestCaseMarkUsed(data->existingTestCases, result);
return virTestCompareToFile(sigStr, result);
}
hostFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s.xml", abs_srcdir,
virArchToString(data->arch), data->host);
+ virTestCaseMarkUsed(data->existingTestCases, hostFile);
+
if (virTestLoadFile(hostFile, &host) < 0 ||
!(hostData = virCPUDataParse(host)))
return -1;
g_autoptr(virDomainCapsCPUModels) models = NULL;
cpuFile = g_strdup_printf("cpuid-%s-guest", data->host);
- if (!(cpu = cpuTestLoadXML(data->arch, cpuFile)))
+ if (!(cpu = cpuTestLoadXML(data->arch, cpuFile, data->existingTestCases)))
return -1;
enabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-enabled.xml",
abs_srcdir, virArchToString(data->arch), data->host);
+ virTestCaseMarkUsed(data->existingTestCases, enabledFile);
if (virTestLoadFile(enabledFile, &enabled) < 0 ||
!(enabledData = virCPUDataParse(enabled)))
return -1;
disabledFile = g_strdup_printf("%s/cputestdata/%s-cpuid-%s-disabled.xml",
abs_srcdir, virArchToString(data->arch), data->host);
+ virTestCaseMarkUsed(data->existingTestCases, disabledFile);
if (virTestLoadFile(disabledFile, &disabled) < 0 ||
!(disabledData = virCPUDataParse(disabled)))
return -1;
expectedFile = g_strdup_printf("cpuid-%s-json", data->host);
- if (!(expected = cpuTestLoadXML(data->arch, expectedFile)))
+ if (!(expected = cpuTestLoadXML(data->arch, expectedFile,
+ data->existingTestCases))) {
return -1;
+ }
/* In case the host CPU signature does not exactly match any CPU model in
* src/cpu_map, the CPU model we detect from CPUID may differ from the one
if (virQEMUCapsInitCPUModel(qemuCaps, VIR_DOMAIN_VIRT_KVM, cpu, false) != 0)
return -1;
- return cpuTestCompareXML(data->arch, cpu, result);
+ return cpuTestCompareXML(data->arch, cpu, result, data->existingTestCases);
}
}
+static bool
+testCaseEnumerate(struct dirent *ent)
+{
+ return virStringHasSuffix(ent->d_name, ".xml") ||
+#if WITH_QEMU
+ virStringHasSuffix(ent->d_name, ".json") ||
+#endif
+ 0;
+}
+
+
static int
mymain(void)
{
+ g_autoptr(GHashTable) existingTestCases = NULL;
virDomainCapsCPUModels *model486 = NULL;
virDomainCapsCPUModels *nomodel = NULL;
virDomainCapsCPUModels *models = NULL;
virDomainCapsCPUModels *ppc_models = NULL;
int ret = 0;
+ if (virTestEnumerateTestCases(abs_srcdir "/cputestdata",
+ testCaseEnumerate,
+ &existingTestCases) < 0) {
+ return EXIT_FAILURE;
+ }
+
#if WITH_QEMU
if (qemuTestDriverInit(&driver) < 0)
return EXIT_FAILURE;
struct data data = { \
arch, host, cpu, models, \
models == NULL ? NULL : #models, \
- cpus, ncpus, flags, result \
+ cpus, ncpus, flags, result, \
+ existingTestCases \
}; \
g_autofree char *testLabel = NULL; \
\
virObjectUnref(haswell);
virObjectUnref(ppc_models);
+ if (virTestCheckUnusedTestCases(existingTestCases) < 0)
+ ret = -1;
+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}