[libvirt] [PATCH 0/2] Add tests for CPU selection in qemu driver

Some more CPU tests that can make use of recently introduced cpuMapOverride(). Jiri Denemark (2): tests: Support for faking emulator in qemuxml2argv tests: Add tests for CPU selection in qemu driver tests/qemuxml2argvdata/qemu.sh | 64 ++++++++++++++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-exact1.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml | 28 +++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-exact2.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml | 35 +++++++++++ .../qemuxml2argv-cpu-minimum1.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml | 21 +++++++ .../qemuxml2argv-cpu-minimum2.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml | 25 ++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-strict1.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml | 38 ++++++++++++ .../qemuxml2argv-cpu-topology1.args | 1 + .../qemuxml2argv-cpu-topology1.xml | 21 +++++++ .../qemuxml2argv-cpu-topology2.args | 1 + .../qemuxml2argv-cpu-topology2.xml | 22 +++++++ .../qemuxml2argv-cpu-topology3.args | 1 + .../qemuxml2argv-cpu-topology3.xml | 21 +++++++ tests/qemuxml2argvtest.c | 38 ++++++++++++ 18 files changed, 321 insertions(+), 0 deletions(-) create mode 100755 tests/qemuxml2argvdata/qemu.sh create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.xml -- 1.7.3.2

This patch allows for using custom scripts instead of /usr/bin/qemu emulator in domain XML. To do so, one would specify relative path to the custom script in <emulator/>. The path needs to be relative to qemuxml2argvdata directory and it will be transparently made absolute in runtime. The expected command line needs to contain the exact relative path as was used in domain XML. The problem is RelaxNG schema for domain XML only allows for absolute path within <emulator/>. To workaround it, an extra '/' must be added at the beginning of the path. That is, instead of "./qemu.sh" or "../emulator/qemu.sh" one would use "/./qemu.sh" or "/../emulator/qemu.sh". The extra slash is removed before further processing. I don't like this workaround, it's very ugly but it's the best option I was able to come up with. Relaxing domain XML schema is not an option IMO. --- tests/qemuxml2argvtest.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e6174be..dd07001 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -41,6 +41,7 @@ static int testCompareXMLToArgvFiles(const char *xml, virDomainChrDef monitor_chr; virConnectPtr conn; char *log = NULL; + char *emulator = NULL; if (!(conn = virGetConnect())) goto fail; @@ -52,6 +53,16 @@ static int testCompareXMLToArgvFiles(const char *xml, VIR_DOMAIN_XML_INACTIVE))) goto fail; + if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { + if (!(emulator = strdup(vmdef->emulator + 1))) + goto fail; + free(vmdef->emulator); + vmdef->emulator = NULL; + if (virAsprintf(&vmdef->emulator, "%s/qemuxml2argvdata/%s", + abs_srcdir, emulator) < 0) + goto fail; + } + if (extraFlags & QEMUD_CMD_FLAG_DOMID) vmdef->id = 6; else @@ -104,6 +115,12 @@ static int testCompareXMLToArgvFiles(const char *xml, virResetLastError(); } + if (emulator && *argv) { + free(*(char**) argv); + *argv = emulator; + emulator = NULL; + } + len = 1; /* for trailing newline */ tmp = qenv; while (*tmp) { @@ -144,6 +161,7 @@ static int testCompareXMLToArgvFiles(const char *xml, fail: free(log); + free(emulator); free(actualargv); if (argv) { tmp = argv; -- 1.7.3.2

On 12/01/2010 07:56 AM, Jiri Denemark wrote:
This patch allows for using custom scripts instead of /usr/bin/qemu emulator in domain XML. To do so, one would specify relative path to the custom script in <emulator/>. The path needs to be relative to qemuxml2argvdata directory and it will be transparently made absolute in runtime. The expected command line needs to contain the exact relative path as was used in domain XML.
Makes sense as a testing mechanism, while still something we do not want exposed to normal usage.
The problem is RelaxNG schema for domain XML only allows for absolute path within <emulator/>. To workaround it, an extra '/' must be added at the beginning of the path. That is, instead of "./qemu.sh" or "../emulator/qemu.sh" one would use "/./qemu.sh" or "/../emulator/qemu.sh". The extra slash is removed before further processing. I don't like this workaround, it's very ugly but it's the best option I was able to come up with. Relaxing domain XML schema is not an option IMO.
Agreed - relaxing the schema would leak the notion of a relative emulator path, which we don't want to do. The hack looks as good as any to me, as long as it's well documented in the code as well as the commit message.
--- tests/qemuxml2argvtest.c | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index e6174be..dd07001 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -41,6 +41,7 @@ static int testCompareXMLToArgvFiles(const char *xml, virDomainChrDef monitor_chr; virConnectPtr conn; char *log = NULL; + char *emulator = NULL;
if (!(conn = virGetConnect())) goto fail; @@ -52,6 +53,16 @@ static int testCompareXMLToArgvFiles(const char *xml, VIR_DOMAIN_XML_INACTIVE))) goto fail;
+ if (vmdef->emulator && STRPREFIX(vmdef->emulator, "/.")) { + if (!(emulator = strdup(vmdef->emulator + 1)))
In other words, I'd add a comment here explaining that for test purposes only, we massage particular emulator names. ACK, with that nit addressed. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

--- tests/qemuxml2argvdata/qemu.sh | 64 ++++++++++++++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-exact1.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml | 28 +++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-exact2.args | 1 + tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml | 35 +++++++++++ .../qemuxml2argv-cpu-minimum1.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml | 21 +++++++ .../qemuxml2argv-cpu-minimum2.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml | 25 ++++++++ .../qemuxml2argvdata/qemuxml2argv-cpu-strict1.args | 1 + .../qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml | 38 ++++++++++++ .../qemuxml2argv-cpu-topology1.args | 1 + .../qemuxml2argv-cpu-topology1.xml | 21 +++++++ .../qemuxml2argv-cpu-topology2.args | 1 + .../qemuxml2argv-cpu-topology2.xml | 22 +++++++ .../qemuxml2argv-cpu-topology3.args | 1 + .../qemuxml2argv-cpu-topology3.xml | 21 +++++++ tests/qemuxml2argvtest.c | 20 ++++++ 18 files changed, 303 insertions(+), 0 deletions(-) create mode 100755 tests/qemuxml2argvdata/qemu.sh create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.xml create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.xml diff --git a/tests/qemuxml2argvdata/qemu.sh b/tests/qemuxml2argvdata/qemu.sh new file mode 100755 index 0000000..6d5d354 --- /dev/null +++ b/tests/qemuxml2argvdata/qemu.sh @@ -0,0 +1,64 @@ +#! /bin/sh + +candidates="/usr/bin/qemu-kvm + /usr/libexec/qemu-kvm + /usr/bin/qemu-system-x86_64 + /usr/bin/qemu" +qemu= +for candidate in $candidates; do + if test -x $candidate; then + qemu=$candidate + break + fi +done + +real_qemu() +{ + if test x$qemu != x; then + exec $qemu "$@" + else + return 1 + fi +} + +faked_machine() +{ + echo "pc" +} + +faked_cpu() +{ + cat <<EOF +x86 Opteron_G3 +x86 Opteron_G2 +x86 Opteron_G1 +x86 Nehalem +x86 Penryn +x86 Conroe +x86 [n270] +x86 [athlon] +x86 [pentium3] +x86 [pentium2] +x86 [pentium] +x86 [486] +x86 [coreduo] +x86 [qemu32] +x86 [kvm64] +x86 [core2duo] +x86 [phenom] +x86 [qemu64] +x86 [host] +EOF +} + +case $* in +"-M ?") + faked_machine + ;; +"-cpu ?") + faked_cpu + ;; +*) + real_qemu "$@" + ;; +esac diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.args new file mode 100644 index 0000000..448737f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -cpu qemu64,-svm,-lm,-nx,-syscall,-clflush,-pse36,-mca -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-exact1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml new file mode 100644 index 0000000..53d3a8d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact1.xml @@ -0,0 +1,28 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='exact'> + <model>qemu64</model> + <feature policy='disable' name='svm'/> + <feature policy='disable' name='lm'/> + <feature policy='disable' name='nx'/> + <feature policy='disable' name='syscall'/> + <feature policy='disable' name='clflush'/> + <feature policy='disable' name='pse36'/> + <feature policy='disable' name='mca'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.args new file mode 100644 index 0000000..637f2e1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.args @@ -0,0 +1 @@ +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.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml new file mode 100644 index 0000000..cd2a506 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-exact2.xml @@ -0,0 +1,35 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='exact'> + <model>core2duo</model> + <feature name='lahf_lm' policy='require'/> + <feature name='xtpr' policy='require'/> + <feature name='cx16' policy='disable'/> + <feature name='tm2' policy='disable'/> + <feature name='ds_cpl' policy='require'/> + <feature name='pbe' policy='disable'/> + <feature name='tm' policy='optional'/> + <feature name='ht' policy='require'/> + <feature name='ss' policy='disable'/> + <feature name='ds' policy='require'/> + <feature name='nx' policy='disable'/> + <feature name='3dnowext' policy='force'/> + <feature name='sse4a' policy='optional'/> + <feature name='wdt' policy='forbid'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.args new file mode 100644 index 0000000..80940f8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds -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-minimum1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml new file mode 100644 index 0000000..2a163d6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum1.xml @@ -0,0 +1,21 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='minimum'> + <model>486</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.args new file mode 100644 index 0000000..7f4aeee --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -cpu core2duo,+lahf_lm,+xtpr,+cx16,+tm2,+est,+vmx,+ds_cpl,+pbe,+tm,+ht,+ss,+acpi,+ds,-lm,-nx,-syscall -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-minimum2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml new file mode 100644 index 0000000..b3baed7 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-minimum2.xml @@ -0,0 +1,25 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='minimum'> + <model>qemu64</model> + <feature policy='disable' name='svm'/> + <feature policy='disable' name='lm'/> + <feature policy='disable' name='nx'/> + <feature policy='disable' name='syscall'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.args new file mode 100644 index 0000000..a680840 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -cpu core2duo,+lahf_lm,+3dnowext,+xtpr,+est,+vmx,+ds_cpl,+tm,+ht,+acpi,+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-strict1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml new file mode 100644 index 0000000..55f6b3c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-strict1.xml @@ -0,0 +1,38 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='strict'> + <model>core2duo</model> + <feature name='lahf_lm' policy='require'/> + <feature name='xtpr' policy='require'/> + <feature name='cx16' policy='disable'/> + <feature name='tm2' policy='disable'/> + <feature name='est' policy='optional'/> + <feature name='vmx' policy='optional'/> + <feature name='ds_cpl' policy='require'/> + <feature name='pbe' policy='disable'/> + <feature name='tm' policy='optional'/> + <feature name='ht' policy='require'/> + <feature name='ss' policy='disable'/> + <feature name='acpi' policy='optional'/> + <feature name='ds' policy='require'/> + <feature name='nx' policy='disable'/> + <feature name='3dnowext' policy='force'/> + <feature name='sse4a' policy='optional'/> + <feature name='wdt' policy='forbid'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.args new file mode 100644 index 0000000..afe39e8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -m 214 -smp 6,sockets=3,cores=2,threads=1 -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-topology1.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.xml new file mode 100644 index 0000000..ca336b8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology1.xml @@ -0,0 +1,21 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu> + <topology sockets="3" cores="2" threads="1"/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.args new file mode 100644 index 0000000..8e8cd82 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -cpu core2duo -m 214 -smp 6,sockets=1,cores=2,threads=3 -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-topology2.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.xml new file mode 100644 index 0000000..3308965 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology2.xml @@ -0,0 +1,22 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu match='exact'> + <model>core2duo</model> + <topology sockets="1" cores="2" threads="3"/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.args b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.args new file mode 100644 index 0000000..d295238 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.args @@ -0,0 +1 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test ./qemu.sh -S -M pc -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-topology3.xml b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.xml new file mode 100644 index 0000000..ca336b8 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-cpu-topology3.xml @@ -0,0 +1,21 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory>219200</memory> + <currentMemory>219200</currentMemory> + <vcpu>6</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='network'/> + </os> + <cpu> + <topology sockets="3" cores="2" threads="1"/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/./qemu.sh</emulator> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index dd07001..90825a7 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -15,11 +15,13 @@ # include "testutils.h" # include "qemu/qemu_conf.h" # include "datatypes.h" +# include "cpu/cpu_map.h" # include "testutilsqemu.h" static char *progname; static char *abs_srcdir; +static const char *abs_top_srcdir; static struct qemud_driver driver; # define MAX_FILE 4096 @@ -211,6 +213,7 @@ mymain(int argc, char **argv) { int ret = 0; char cwd[PATH_MAX]; + char map[PATH_MAX]; progname = argv[0]; @@ -223,6 +226,10 @@ mymain(int argc, char **argv) if (!abs_srcdir) abs_srcdir = getcwd(cwd, sizeof(cwd)); + abs_top_srcdir = getenv("abs_top_srcdir"); + if (!abs_top_srcdir) + abs_top_srcdir = ".."; + if ((driver.caps = testQemuCapsInit()) == NULL) return EXIT_FAILURE; if ((driver.stateDir = strdup("/nowhere")) == NULL) @@ -237,6 +244,10 @@ mymain(int argc, char **argv) if (!(driver.spicePassword = strdup("123456"))) return EXIT_FAILURE; + snprintf(map, PATH_MAX, "%s/src/cpu/cpu_map.xml", abs_top_srcdir); + if (cpuMapOverride(map) < 0) + return EXIT_FAILURE; + # define DO_TEST_FULL(name, extraFlags, migrateFrom, expectError) \ do { \ const struct testInfo info = { \ @@ -442,6 +453,15 @@ mymain(int argc, char **argv) DO_TEST("smp", QEMUD_CMD_FLAG_SMP_TOPOLOGY, false); + DO_TEST("cpu-topology1", QEMUD_CMD_FLAG_SMP_TOPOLOGY, false); + DO_TEST("cpu-topology2", QEMUD_CMD_FLAG_SMP_TOPOLOGY, false); + DO_TEST("cpu-topology3", 0, false); + DO_TEST("cpu-minimum1", 0, false); + DO_TEST("cpu-minimum2", 0, false); + DO_TEST("cpu-exact1", 0, false); + DO_TEST("cpu-exact2", 0, false); + DO_TEST("cpu-strict1", 0, false); + free(driver.stateDir); virCapabilitiesFree(driver.caps); -- 1.7.3.2

On 12/01/2010 07:56 AM, Jiri Denemark wrote:
--- diff --git a/tests/qemuxml2argvdata/qemu.sh b/tests/qemuxml2argvdata/qemu.sh new file mode 100755 index 0000000..6d5d354 --- /dev/null +++ b/tests/qemuxml2argvdata/qemu.sh @@ -0,0 +1,64 @@ +#! /bin/sh
+real_qemu() +{ + if test x$qemu != x; then + exec $qemu "$@" + else + return 1 + fi +} + +faked_machine() +{ + echo "pc" +}
+case $* in +"-M ?") + faked_machine + ;; +"-cpu ?") + faked_cpu + ;; +*) + real_qemu "$@" + ;; +esac
Nice - you can control the output of possible machines and cpus, even if a qemu upgrade gains support for more names later.
@@ -223,6 +226,10 @@ mymain(int argc, char **argv) if (!abs_srcdir) abs_srcdir = getcwd(cwd, sizeof(cwd));
+ abs_top_srcdir = getenv("abs_top_srcdir"); + if (!abs_top_srcdir) + abs_top_srcdir = "..";
Not really absolute, is it? But it matches other tests, and does the job, so no need to change it. ACK. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Jiri Denemark