From a6f88cbd2d50596ec0a2e9d1bd6fedcaef8e904e Mon Sep 17 00:00:00 2001 From: Jiri Denemark Date: Wed, 21 Dec 2011 14:27:16 +0100 Subject: [PATCH] cpu: Optionally forbid fallback CPU models In case a hypervisor doesn't support the exact CPU model requested by a domain XML, we automatically fallback to a closest CPU model the hypervisor supports (and make sure we add/remove any additional features if needed). This patch adds 'fallback' attribute to model element, which can be used to disable this automatic fallback. --- docs/formatdomain.html.in | 12 ++- docs/schemas/domaincommon.rng | 8 ++ src/conf/cpu_conf.c | 38 +++++++- src/conf/cpu_conf.h | 10 +++ src/cpu/cpu_x86.c | 17 +++- src/qemu/qemu_command.c | 1 + tests/cputest.c | 2 + tests/cputestdata/x86-baseline-1-result.xml | 2 +- tests/cputestdata/x86-baseline-2-result.xml | 2 +- .../x86-baseline-no-vendor-result.xml | 2 +- .../x86-baseline-some-vendors-result.xml | 2 +- tests/cputestdata/x86-guest-nofallback.xml | 18 ++++ .../x86-host+guest,model486-result.xml | 2 +- .../x86-host+guest,models,Penryn-result.xml | 2 +- .../x86-host+guest,models,qemu64-result.xml | 2 +- .../x86-host+guest,models-result.xml | 2 +- tests/cputestdata/x86-host+guest-result.xml | 2 +- tests/cputestdata/x86-host+guest.xml | 2 +- tests/cputestdata/x86-host+min.xml | 2 +- .../x86-host+nehalem-force-result.xml | 2 +- tests/cputestdata/x86-host+pentium3.xml | 2 +- .../x86-host+strict-force-extra-result.xml | 2 +- ...6-host-better+pentium3,core2duo-result.xml | 2 +- ...6-host-better+pentium3,pentium3-result.xml | 2 +- .../x86-host-better+pentium3-result.xml | 2 +- .../x86-host-worse+guest-result.xml | 2 +- .../qemuxml2argv-cpu-exact1.xml | 2 +- .../qemuxml2argv-cpu-exact2-nofallback.args | 4 + .../qemuxml2argv-cpu-exact2-nofallback.xml | 35 ++++++++ .../qemuxml2argv-cpu-fallback.args | 19 ++++ .../qemuxml2argv-cpu-fallback.xml | 25 ++++++ .../qemuxml2argv-cpu-nofallback.xml | 25 ++++++ tests/qemuxml2argvtest.c | 86 ++++++++++++------- .../qemuxml2xmlout-graphics-spice-timeout.xml | 86 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 +- tests/testutilsqemu.c | 1 + 36 files changed, 368 insertions(+), 59 deletions(-) create mode 100644 tests/cputestdata/x86-guest-nofallback.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml create mode 100644 tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 6b06723095..cb7532e2bd 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -559,7 +559,7 @@
   ...
   <cpu match='exact'>
-    <model>core2duo</model>
+    <model fallback='allow'>core2duo</model>
     <vendor>Intel</vendor>
     <topology sockets='1' cores='2' threads='1'/>
     <feature policy='disable' name='lahf_lm'/>
@@ -609,7 +609,15 @@
       
The content of the model element specifies CPU model requested by the guest. The list of available CPU models and their definition can be found in cpu_map.xml file installed - in libvirt's data directory.
+ in libvirt's data directory. If a hypervisor is not able to use the + exact CPU model, libvirt automatically falls back to a closest model + supported by the hypervisor while maintaining the list of CPU + features. Since 0.9.10, an optional + fallback attribute can be used to forbid this behavior, + in which case an attempt to start a domain requesting an unsupported + CPU model will fail. Supported values for fallback + attribute are: allow (this is the default), and + forbid.
vendor
Since 0.8.3 the content of the diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index b54fd68ac7..133b7f7a82 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2571,6 +2571,14 @@ + + + + allow + forbid + + + diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 348299b5fc..c8e29e4cd8 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -44,6 +44,10 @@ VIR_ENUM_IMPL(virCPUMatch, VIR_CPU_MATCH_LAST, "exact", "strict") +VIR_ENUM_IMPL(virCPUFallback, VIR_CPU_FALLBACK_LAST, + "allow", + "forbid") + VIR_ENUM_IMPL(virCPUFeaturePolicy, VIR_CPU_FEATURE_LAST, "force", "require", @@ -97,6 +101,7 @@ virCPUDefCopy(const virCPUDefPtr cpu) copy->type = cpu->type; copy->match = cpu->match; + copy->fallback = cpu->fallback; copy->sockets = cpu->sockets; copy->cores = cpu->cores; copy->threads = cpu->threads; @@ -209,6 +214,21 @@ virCPUDefParseXML(const xmlNodePtr node, goto error; } + if (def->model && def->type == VIR_CPU_TYPE_GUEST) { + const char *fallback; + + fallback = virXPathString("string(./model[1]/@fallback)", ctxt); + if (fallback) { + def->fallback = virCPUFallbackTypeFromString(fallback); + VIR_FREE(fallback); + if (def->fallback < 0) { + virCPUReportError(VIR_ERR_XML_ERROR, "%s", + _("Invalid fallback attribute")); + goto error; + } + } + } + def->vendor = virXPathString("string(./vendor[1])", ctxt); if (def->vendor && !def->model) { virCPUReportError(VIR_ERR_INTERNAL_ERROR, @@ -455,8 +475,22 @@ virCPUDefFormatBuf(virBufferPtr buf, return -1; } - if (def->model) - virBufferAsprintf(buf, "%s\n", def->model); + if (def->model) { + virBufferAddLit(buf, "type == VIR_CPU_TYPE_GUEST) { + const char *fallback; + + fallback = virCPUFallbackTypeToString(def->fallback); + if (!fallback) { + virCPUReportError(VIR_ERR_INTERNAL_ERROR, + _("Unexpected CPU fallback value: %d"), + def->fallback); + return -1; + } + virBufferAsprintf(buf, " fallback='%s'", fallback); + } + virBufferAsprintf(buf, ">%s\n", def->model); + } if (def->vendor) { virBufferAsprintf(buf, "%s\n", def->vendor); diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index efff47378a..0c50f90b15 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -48,6 +48,15 @@ enum virCPUMatch { VIR_ENUM_DECL(virCPUMatch) +enum virCPUFallback { + VIR_CPU_FALLBACK_ALLOW, + VIR_CPU_FALLBACK_FORBID, + + VIR_CPU_FALLBACK_LAST +}; + +VIR_ENUM_DECL(virCPUFallback) + enum virCPUFeaturePolicy { VIR_CPU_FEATURE_FORCE, VIR_CPU_FEATURE_REQUIRE, @@ -83,6 +92,7 @@ struct _virCPUDef { int match; /* enum virCPUMatch */ char *arch; char *model; + int fallback; /* enum virCPUFallback */ char *vendor; unsigned int sockets; unsigned int cores; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 4a4272e839..ad2d5cda45 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1294,8 +1294,21 @@ x86Decode(virCPUDefPtr cpu, } if (!allowed) { - VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring", - candidate->name); + if (preferred && STREQ(candidate->name, preferred)) { + if (cpu->fallback != VIR_CPU_FALLBACK_ALLOW) { + virCPUReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("CPU model %s is not supported by hypervisor"), + preferred); + goto out; + } else { + VIR_WARN("Preferred CPU model %s not allowed by" + " hypervisor; closest supported model will be" + " used", preferred); + } + } else { + VIR_DEBUG("CPU model %s not allowed by hypervisor; ignoring", + candidate->name); + } goto next; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 98824ac95a..d2789263c8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3511,6 +3511,7 @@ qemuBuildCpuArgStr(const struct qemud_driver *driver, preferred = def->cpu->model; guest->type = VIR_CPU_TYPE_GUEST; + guest->fallback = def->cpu->fallback; if (cpuDecode(guest, data, cpus, ncpus, preferred) < 0) goto cleanup; diff --git a/tests/cputest.c b/tests/cputest.c index 5b7b951ccc..2dd89f28be 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -287,6 +287,7 @@ cpuTestGuestData(const void *arg) guest->type = VIR_CPU_TYPE_GUEST; guest->match = VIR_CPU_MATCH_EXACT; + guest->fallback = cpu->fallback; if (cpuDecode(guest, guestData, data->models, data->nmodels, data->preferred) < 0) { if (data->result < 0) { @@ -620,6 +621,7 @@ mymain(void) DO_TEST_GUESTDATA("x86", "host", "guest", models, "Penryn", 0); DO_TEST_GUESTDATA("x86", "host", "guest", models, "qemu64", 0); DO_TEST_GUESTDATA("x86", "host", "guest", nomodel, NULL, -1); + DO_TEST_GUESTDATA("x86", "host", "guest-nofallback", models, "Penryn", -1); free(map); return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE); diff --git a/tests/cputestdata/x86-baseline-1-result.xml b/tests/cputestdata/x86-baseline-1-result.xml index e376f7442f..99e43d018f 100644 --- a/tests/cputestdata/x86-baseline-1-result.xml +++ b/tests/cputestdata/x86-baseline-1-result.xml @@ -1,5 +1,5 @@ - Conroe + Conroe Intel diff --git a/tests/cputestdata/x86-baseline-2-result.xml b/tests/cputestdata/x86-baseline-2-result.xml index 3fd0551ba8..76c13aa505 100644 --- a/tests/cputestdata/x86-baseline-2-result.xml +++ b/tests/cputestdata/x86-baseline-2-result.xml @@ -1,4 +1,4 @@ - core2duo + core2duo diff --git a/tests/cputestdata/x86-baseline-no-vendor-result.xml b/tests/cputestdata/x86-baseline-no-vendor-result.xml index 0fc089256f..8b97d2c130 100644 --- a/tests/cputestdata/x86-baseline-no-vendor-result.xml +++ b/tests/cputestdata/x86-baseline-no-vendor-result.xml @@ -1,5 +1,5 @@ - Opteron_G2 + Opteron_G2 diff --git a/tests/cputestdata/x86-baseline-some-vendors-result.xml b/tests/cputestdata/x86-baseline-some-vendors-result.xml index 2ddfcc5807..bac0e5d38f 100644 --- a/tests/cputestdata/x86-baseline-some-vendors-result.xml +++ b/tests/cputestdata/x86-baseline-some-vendors-result.xml @@ -1,3 +1,3 @@ - Opteron_G1 + Opteron_G1 diff --git a/tests/cputestdata/x86-guest-nofallback.xml b/tests/cputestdata/x86-guest-nofallback.xml new file mode 100644 index 0000000000..babe47d05f --- /dev/null +++ b/tests/cputestdata/x86-guest-nofallback.xml @@ -0,0 +1,18 @@ + + Penryn + + + + + + + + + + + + + + + + diff --git a/tests/cputestdata/x86-host+guest,model486-result.xml b/tests/cputestdata/x86-host+guest,model486-result.xml index fb1bb4b950..9fd67eb1a7 100644 --- a/tests/cputestdata/x86-host+guest,model486-result.xml +++ b/tests/cputestdata/x86-host+guest,model486-result.xml @@ -1,6 +1,6 @@ x86_64 - 486 + 486 diff --git a/tests/cputestdata/x86-host+guest,models,Penryn-result.xml b/tests/cputestdata/x86-host+guest,models,Penryn-result.xml index 955946537c..9ae11c9500 100644 --- a/tests/cputestdata/x86-host+guest,models,Penryn-result.xml +++ b/tests/cputestdata/x86-host+guest,models,Penryn-result.xml @@ -1,6 +1,6 @@ x86_64 - Nehalem + Nehalem diff --git a/tests/cputestdata/x86-host+guest,models,qemu64-result.xml b/tests/cputestdata/x86-host+guest,models,qemu64-result.xml index b41863eb59..7582ddc8c5 100644 --- a/tests/cputestdata/x86-host+guest,models,qemu64-result.xml +++ b/tests/cputestdata/x86-host+guest,models,qemu64-result.xml @@ -1,6 +1,6 @@ x86_64 - qemu64 + qemu64 diff --git a/tests/cputestdata/x86-host+guest,models-result.xml b/tests/cputestdata/x86-host+guest,models-result.xml index 955946537c..9ae11c9500 100644 --- a/tests/cputestdata/x86-host+guest,models-result.xml +++ b/tests/cputestdata/x86-host+guest,models-result.xml @@ -1,6 +1,6 @@ x86_64 - Nehalem + Nehalem diff --git a/tests/cputestdata/x86-host+guest-result.xml b/tests/cputestdata/x86-host+guest-result.xml index 544a388f76..e596c43209 100644 --- a/tests/cputestdata/x86-host+guest-result.xml +++ b/tests/cputestdata/x86-host+guest-result.xml @@ -1,6 +1,6 @@ x86_64 - Penryn + Penryn diff --git a/tests/cputestdata/x86-host+guest.xml b/tests/cputestdata/x86-host+guest.xml index c3fca87754..2a786fd3aa 100644 --- a/tests/cputestdata/x86-host+guest.xml +++ b/tests/cputestdata/x86-host+guest.xml @@ -1,5 +1,5 @@ - Penryn + Penryn diff --git a/tests/cputestdata/x86-host+min.xml b/tests/cputestdata/x86-host+min.xml index d22c7b6c1c..fe55058992 100644 --- a/tests/cputestdata/x86-host+min.xml +++ b/tests/cputestdata/x86-host+min.xml @@ -1,5 +1,5 @@ - Penryn + Penryn diff --git a/tests/cputestdata/x86-host+nehalem-force-result.xml b/tests/cputestdata/x86-host+nehalem-force-result.xml index 162685f022..41e7356796 100644 --- a/tests/cputestdata/x86-host+nehalem-force-result.xml +++ b/tests/cputestdata/x86-host+nehalem-force-result.xml @@ -1,4 +1,4 @@ x86_64 - Nehalem + Nehalem diff --git a/tests/cputestdata/x86-host+pentium3.xml b/tests/cputestdata/x86-host+pentium3.xml index d141d9e333..e122ba53d6 100644 --- a/tests/cputestdata/x86-host+pentium3.xml +++ b/tests/cputestdata/x86-host+pentium3.xml @@ -1,5 +1,5 @@ - pentium3 + pentium3 diff --git a/tests/cputestdata/x86-host+strict-force-extra-result.xml b/tests/cputestdata/x86-host+strict-force-extra-result.xml index e47933cc32..f3d52a14b3 100644 --- a/tests/cputestdata/x86-host+strict-force-extra-result.xml +++ b/tests/cputestdata/x86-host+strict-force-extra-result.xml @@ -1,6 +1,6 @@ x86_64 - Penryn + Penryn diff --git a/tests/cputestdata/x86-host-better+pentium3,core2duo-result.xml b/tests/cputestdata/x86-host-better+pentium3,core2duo-result.xml index c2d8ddd636..5d4528bd6d 100644 --- a/tests/cputestdata/x86-host-better+pentium3,core2duo-result.xml +++ b/tests/cputestdata/x86-host-better+pentium3,core2duo-result.xml @@ -1,6 +1,6 @@ x86_64 - core2duo + core2duo diff --git a/tests/cputestdata/x86-host-better+pentium3,pentium3-result.xml b/tests/cputestdata/x86-host-better+pentium3,pentium3-result.xml index 6e246a8032..1530a07e0a 100644 --- a/tests/cputestdata/x86-host-better+pentium3,pentium3-result.xml +++ b/tests/cputestdata/x86-host-better+pentium3,pentium3-result.xml @@ -1,6 +1,6 @@ x86_64 - pentium3 + pentium3 diff --git a/tests/cputestdata/x86-host-better+pentium3-result.xml b/tests/cputestdata/x86-host-better+pentium3-result.xml index b918363e69..917d63f069 100644 --- a/tests/cputestdata/x86-host-better+pentium3-result.xml +++ b/tests/cputestdata/x86-host-better+pentium3-result.xml @@ -1,6 +1,6 @@ x86_64 - Nehalem + Nehalem diff --git a/tests/cputestdata/x86-host-worse+guest-result.xml b/tests/cputestdata/x86-host-worse+guest-result.xml index 036177a58f..78e170adbc 100644 --- a/tests/cputestdata/x86-host-worse+guest-result.xml +++ b/tests/cputestdata/x86-host-worse+guest-result.xml @@ -1,6 +1,6 @@ x86_64 - Penryn + Penryn diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml index d6db442ad9..b5fd49c5f7 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml @@ -9,7 +9,7 @@ - qemu64 + qemu64 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args new file mode 100644 index 0000000000..198d0d8f17 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.args @@ -0,0 +1,4 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc \ +-cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+ds_cpl,+tm,+ht,+ds,-nx -m 214 -smp 6 \ +-nographic -monitor unix:/tmp/test-monitor,server,nowait -no-acpi -boot n -net \ +none -serial none -parallel none -usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml new file mode 100644 index 0000000000..11de634f3d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2-nofallback.xml @@ -0,0 +1,35 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 6 + + hvm + + + + core2duo + + + + + + + + + + + + + + + + + destroy + restart + destroy + + /./qemu.sh + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args new file mode 100644 index 0000000000..658f1412a7 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.args @@ -0,0 +1,19 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +./qemu.sh \ +-S \ +-M pc \ +-cpu Penryn,-sse4.1 \ +-m 214 \ +-smp 6 \ +-nographic \ +-monitor unix:/tmp/test-monitor,server,nowait \ +-no-acpi \ +-boot n \ +-net none \ +-serial none \ +-parallel none \ +-usb diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml new file mode 100644 index 0000000000..7bd28a87d3 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-fallback.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 6 + + hvm + + + + Westmere + + + + + + + destroy + restart + destroy + + /./qemu.sh + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml new file mode 100644 index 0000000000..7f1f09a900 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-nofallback.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219100 + 219100 + 6 + + hvm + + + + Westmere + + + + + + + destroy + restart + destroy + + /./qemu.sh + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index fd3c9bbd53..e5161938da 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -84,7 +84,8 @@ static int testCompareXMLToArgvFiles(const char *xml, const char *migrateFrom, int migrateFd, bool json, - bool expectError) + bool expectError, + bool expectFailure) { char *expectargv = NULL; int len; @@ -98,19 +99,13 @@ static int testCompareXMLToArgvFiles(const char *xml, virCommandPtr cmd = NULL; if (!(conn = virGetConnect())) - goto fail; + goto out; conn->secretDriver = &fakeSecretDriver; - len = virtTestLoadFile(cmdline, &expectargv); - if (len < 0) - goto fail; - if (len && expectargv[len - 1] == '\n') - expectargv[len - 1] = '\0'; - if (!(vmdef = virDomainDefParseFile(driver.caps, xml, QEMU_EXPECTED_VIRT_TYPES, VIR_DOMAIN_XML_INACTIVE))) - goto fail; + goto out; /* * For test purposes, we may want to fake emulator's output by providing @@ -124,12 +119,12 @@ static int testCompareXMLToArgvFiles(const char *xml, */ if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { if (!(emulator = strdup(vmdef->emulator + 1))) - goto fail; + goto out; free(vmdef->emulator); vmdef->emulator = NULL; if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", abs_srcdir, emulator) < 0) - goto fail; + goto out; } if (qemuCapsGet(extraFlags, QEMU_CAPS_DOMID)) @@ -149,7 +144,7 @@ static int testCompareXMLToArgvFiles(const char *xml, QEMU_CAPS_LAST); if (qemudCanonicalizeMachine(&driver, vmdef) < 0) - goto fail; + goto out; if (qemuCapsGet(extraFlags, QEMU_CAPS_DEVICE)) { qemuDomainPCIAddressSetPtr pciaddrs; @@ -157,14 +152,14 @@ static int testCompareXMLToArgvFiles(const char *xml, if (qemuDomainAssignSpaprVIOAddresses(vmdef)) { if (expectError) goto ok; - goto fail; + goto out; } if (!(pciaddrs = qemuDomainPCIAddressSetCreate(vmdef))) - goto fail; + goto out; if (qemuAssignDevicePCISlots(vmdef, pciaddrs) < 0) - goto fail; + goto out; qemuDomainPCIAddressSetFree(pciaddrs); } @@ -183,35 +178,50 @@ static int testCompareXMLToArgvFiles(const char *xml, } if (qemuAssignDeviceAliases(vmdef, extraFlags) < 0) - goto fail; + goto out; if (!(cmd = qemuBuildCommandLine(conn, &driver, vmdef, &monitor_chr, json, extraFlags, migrateFrom, migrateFd, NULL, - VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) - goto fail; + VIR_NETDEV_VPORT_PROFILE_OP_NO_OP))) { + if (expectFailure) { + ret = 0; + virResetLastError(); + } + goto out; + } else if (expectFailure) { + if (virTestGetDebug()) + fprintf(stderr, "qemuBuildCommandLine should have failed\n"); + goto out; + } if (!!virGetLastError() != expectError) { if (virTestGetDebug() && (log = virtTestLogContentAndReset())) fprintf(stderr, "\n%s", log); - goto fail; + goto out; } if (!(actualargv = virCommandToString(cmd))) - goto fail; + goto out; if (emulator) { /* Skip the abs_srcdir portion of replacement emulator. */ char *start_skip = strstr(actualargv, abs_srcdir); char *end_skip = strstr(actualargv, emulator); if (!start_skip || !end_skip) - goto fail; + goto out; memmove(start_skip, end_skip, strlen(end_skip) + 1); } + len = virtTestLoadFile(cmdline, &expectargv); + if (len < 0) + goto out; + if (len && expectargv[len - 1] == '\n') + expectargv[len - 1] = '\0'; + if (STRNEQ(expectargv, actualargv)) { virtTestDifference(stderr, expectargv, actualargv); - goto fail; + goto out; } ok: @@ -222,7 +232,7 @@ static int testCompareXMLToArgvFiles(const char *xml, ret = 0; - fail: +out: free(log); free(emulator); free(expectargv); @@ -240,6 +250,7 @@ struct testInfo { const char *migrateFrom; int migrateFd; bool expectError; + bool expectFailure; }; static int @@ -260,7 +271,8 @@ testCompareXMLToArgvHelper(const void *data) info->migrateFrom, info->migrateFd, qemuCapsGet(info->extraFlags, QEMU_CAPS_MONITOR_JSON), - info->expectError); + info->expectError, + info->expectFailure); cleanup: free(xml); @@ -299,10 +311,12 @@ mymain(void) return EXIT_FAILURE; } -# define DO_TEST_FULL(name, migrateFrom, migrateFd, expectError, ...) \ +# define DO_TEST_FULL(name, migrateFrom, migrateFd, \ + expectError, expectFailure, ...) \ do { \ struct testInfo info = { \ - name, NULL, migrateFrom, migrateFd, expectError \ + name, NULL, migrateFrom, migrateFd, \ + expectError, expectFailure \ }; \ if (!(info.extraFlags = qemuCapsNew())) \ return EXIT_FAILURE; \ @@ -314,7 +328,10 @@ mymain(void) } while (0) # define DO_TEST(name, expectError, ...) \ - DO_TEST_FULL(name, NULL, -1, expectError, __VA_ARGS__) + DO_TEST_FULL(name, NULL, -1, expectError, false, __VA_ARGS__) + +# define DO_TEST_FAILURE(name, ...) \ + DO_TEST_FULL(name, NULL, -1, false, true, __VA_ARGS__) # define NONE QEMU_CAPS_LAST @@ -643,17 +660,17 @@ mymain(void) DO_TEST("hostdev-pci-address-device", false, QEMU_CAPS_PCIDEVICE, QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); - DO_TEST_FULL("restore-v1", "stdio", 7, false, + DO_TEST_FULL("restore-v1", "stdio", 7, false, false, QEMU_CAPS_MIGRATE_KVM_STDIO); - DO_TEST_FULL("restore-v2", "stdio", 7, false, + DO_TEST_FULL("restore-v2", "stdio", 7, false, false, QEMU_CAPS_MIGRATE_QEMU_EXEC); - DO_TEST_FULL("restore-v2", "exec:cat", 7, false, + DO_TEST_FULL("restore-v2", "exec:cat", 7, false, false, QEMU_CAPS_MIGRATE_QEMU_EXEC); - DO_TEST_FULL("restore-v2-fd", "stdio", 7, false, + DO_TEST_FULL("restore-v2-fd", "stdio", 7, false, false, QEMU_CAPS_MIGRATE_QEMU_FD); - DO_TEST_FULL("restore-v2-fd", "fd:7", 7, false, + DO_TEST_FULL("restore-v2-fd", "fd:7", 7, false, false, QEMU_CAPS_MIGRATE_QEMU_FD); - DO_TEST_FULL("migrate", "tcp:10.0.0.1:5000", -1, false, + DO_TEST_FULL("migrate", "tcp:10.0.0.1:5000", -1, false, false, QEMU_CAPS_MIGRATE_QEMU_TCP); DO_TEST("qemu-ns", false, NONE); @@ -667,6 +684,9 @@ mymain(void) DO_TEST("cpu-minimum2", false, NONE); DO_TEST("cpu-exact1", false, NONE); DO_TEST("cpu-exact2", false, NONE); + DO_TEST("cpu-exact2-nofallback", false, NONE); + DO_TEST("cpu-fallback", false, NONE); + DO_TEST_FAILURE("cpu-nofallback", NONE); DO_TEST("cpu-strict1", false, NONE); DO_TEST("cpu-numa1", false, NONE); DO_TEST("cpu-numa2", false, QEMU_CAPS_SMP_TOPOLOGY); diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml new file mode 100644 index 0000000000..caa5f0a0c0 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-graphics-spice-timeout.xml @@ -0,0 +1,86 @@ + + f14 + 553effab-b5e1-2d80-dfe3-da4344826c43 + 1048576 + 1048576 + 2 + + hvm + + + + + + + + + + + core2duo + Intel + + + + + + + + + + + + + + + + + destroy + restart + restart + + /./qemu.sh + + + + +
+ + + + + + +
+ + +
+ + +
+ + + +