diff --git a/ChangeLog b/ChangeLog index ca997200975a942a206a4d894bd81227a0e8b5d2..16cb90a583e329b667bf5b02aa8c065d02c0d1ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Jul 18 17:15:08 EST 2007 Daniel P. Berrange + + * tests/Makefile.am: Added QEMU tests + * tests/qemuxml2argvdata/*: Data files for QEMU tests + * tests/qemuxml2argvtest.c: Test XML -> argv conversion + * tests/qemuxml2xmltest.c: Test XML -> XML roundtrip + Wed Jul 18 17:11:08 EST 2007 Daniel P. Berrange * src/xmlrpctest.c, src/xml2sexprtest.c: More void * to diff --git a/tests/.cvsignore b/tests/.cvsignore index b8ee537d5c23fb1b7518a40fbfebcb47dbe2d4c7..a254efafa11218bf3740fc9301139fb987b1b3cd 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -10,6 +10,8 @@ conftest reconnect xmconfigtest xencapstest +qemuxml2xmltest +qemuxml2argvtest *.gcda *.gcno diff --git a/tests/Makefile.am b/tests/Makefile.am index f4f810c6514e6503fa939a6a70c31a9df033ba60..9eb5e8b5a35f0053baf51d203af0ee2bb195b2a2 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,9 +32,10 @@ LDADDS = \ EXTRA_DIST = xmlrpcserver.py test_conf.sh noinst_PROGRAMS = xmlrpctest xml2sexprtest sexpr2xmltest virshtest conftest \ - reconnect xmconfigtest xencapstest + reconnect xmconfigtest xencapstest qemuxml2argvtest qemuxml2xmltest -TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh xmconfigtest xencapstest +TESTS = xml2sexprtest sexpr2xmltest virshtest test_conf.sh xmconfigtest \ + xencapstest qemuxml2argvtest qemuxml2xmltest if ENABLE_XEN_TESTS TESTS += reconnect endif @@ -70,6 +71,18 @@ xmconfigtest_SOURCES = \ xmconfigtest_LDFLAGS = xmconfigtest_LDADD = $(LDADDS) +qemuxml2argvtest_SOURCES = \ + qemuxml2argvtest.c \ + testutils.c testutils.h +qemuxml2argvtest_LDFLAGS = +qemuxml2argvtest_LDADD = $(LDADDS) + +qemuxml2xmltest_SOURCES = \ + qemuxml2xmltest.c \ + testutils.c testutils.h +qemuxml2xmltest_LDFLAGS = +qemuxml2xmltest_LDADD = $(LDADDS) + virshtest_SOURCES = \ virshtest.c \ testutils.c testutils.h diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.args b/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.args new file mode 100644 index 0000000000000000000000000000000000000000..ed6a8655dc8af0c2179fc236af3fe251fc046f6a --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot d -cdrom /dev/cdrom -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml b/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml new file mode 100644 index 0000000000000000000000000000000000000000..26eeb393307a57619f74033d65b50c51dd1a1085 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-cdrom.xml @@ -0,0 +1,23 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.args b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.args new file mode 100644 index 0000000000000000000000000000000000000000..5e387ff80527b2a541a48d42f6d7d79afba38692 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot a -hda /dev/HostVG/QEMUGuest1 -fda /tmp/firmware.img -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.xml b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.xml new file mode 100644 index 0000000000000000000000000000000000000000..ed00c666dd4c9e4a604539e995d5bfed5cd67813 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-network.args b/tests/qemuxml2argvdata/qemuxml2argv-boot-network.args new file mode 100644 index 0000000000000000000000000000000000000000..e1d285ac3afb0c4b08907c7cd228ab095558f32c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-network.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot n -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-network.xml b/tests/qemuxml2argvdata/qemuxml2argv-boot-network.xml new file mode 100644 index 0000000000000000000000000000000000000000..55d4e8a17264f2a1d0bc7c45c186a0a7168c42c0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-network.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.args b/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.args new file mode 100644 index 0000000000000000000000000000000000000000..555ce3540013574fc4a6cde071f47466550ebec1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -localtime -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.xml b/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.xml new file mode 100644 index 0000000000000000000000000000000000000000..351779da1dbe55f90793d062832b402d2f4ea0f2 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-clock-localtime.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.args b/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.args new file mode 100644 index 0000000000000000000000000000000000000000..dc8e52b0209bdd281f7bde62650c81967e2a688c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml b/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml new file mode 100644 index 0000000000000000000000000000000000000000..816b16138c3a3e86d37a296634df06b522e01bff --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-clock-utc.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.args new file mode 100644 index 0000000000000000000000000000000000000000..298cea8cd6c1e92e6c2a950ec6d23ef9243b4131 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -cdrom /root/boot.iso -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml new file mode 100644 index 0000000000000000000000000000000000000000..e3e5fbf51e0f1f8b01746eab11cb714fa3742ac5 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-cdrom.xml @@ -0,0 +1,27 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.args new file mode 100644 index 0000000000000000000000000000000000000000..f6dad3da00aea7fb6997ab981c45f1ee78b520a0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -fda /dev/fd0 -fdb /tmp/firmware.img -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.xml new file mode 100644 index 0000000000000000000000000000000000000000..37f1433416475748b345ff9fd7f72fe2ba84be3f --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-floppy.xml @@ -0,0 +1,30 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-many.args b/tests/qemuxml2argvdata/qemuxml2argv-disk-many.args new file mode 100644 index 0000000000000000000000000000000000000000..a6a957c4e20a208a55207a529b6d07b773484080 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-many.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -hdb /dev/HostVG/QEMUGuest2 -hdc /tmp/data.img -hdd /tmp/logs.img -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-disk-many.xml b/tests/qemuxml2argvdata/qemuxml2argv-disk-many.xml new file mode 100644 index 0000000000000000000000000000000000000000..1ff0aa20d471931dc5176cdd38930c5627153f99 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-disk-many.xml @@ -0,0 +1,34 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + + + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args new file mode 100644 index 0000000000000000000000000000000000000000..50016c4f07cc69a4385e9ea6b2f446995d9d5ea2 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -sdl \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml new file mode 100644 index 0000000000000000000000000000000000000000..8c795d9cd04acfc51357db57aee3e013dfc7a4b4 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-sdl.xml @@ -0,0 +1,24 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.args b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.args new file mode 100644 index 0000000000000000000000000000000000000000..42a33a47bbd92fa49138feac500142254b533c59 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -vnc 127.0.0.1:3 \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml new file mode 100644 index 0000000000000000000000000000000000000000..2528a0e8c1f9ca54d8114f9abf8d369d00b128f0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-graphics-vnc.xml @@ -0,0 +1,24 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.args b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.args new file mode 100644 index 0000000000000000000000000000000000000000..60b8bbedbc0e18fd5cd7d15973be1c510b688a37 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -usbdevice mouse -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.xml b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.xml new file mode 100644 index 0000000000000000000000000000000000000000..1bbf890078985dda6e222fee60334fdb343a3cad --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-input-usbmouse.xml @@ -0,0 +1,23 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.args b/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.args new file mode 100644 index 0000000000000000000000000000000000000000..5f6f02cfb38e2e7a6afc0eeb389dffe66c81a6ef --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -usbdevice tablet -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.xml b/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.xml new file mode 100644 index 0000000000000000000000000000000000000000..2cfc17401021781d1e596bfb0792c2e4776052c0 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-input-usbtablet.xml @@ -0,0 +1,23 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-minimal.args b/tests/qemuxml2argvdata/qemuxml2argv-minimal.args new file mode 100644 index 0000000000000000000000000000000000000000..dc8e52b0209bdd281f7bde62650c81967e2a688c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-minimal.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-minimal.xml b/tests/qemuxml2argvdata/qemuxml2argv-minimal.xml new file mode 100644 index 0000000000000000000000000000000000000000..816b16138c3a3e86d37a296634df06b522e01bff --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-minimal.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.args b/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.args new file mode 100644 index 0000000000000000000000000000000000000000..600478c0086fce8897916a8527e7a543d9fba16c --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.xml b/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.xml new file mode 100644 index 0000000000000000000000000000000000000000..759b6cf8f337809a03fda51e66dc50f969e79b10 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-acpi.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.args b/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.args new file mode 100644 index 0000000000000000000000000000000000000000..90ade68b7265e9800a0b8b72254852c3b60176d1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-reboot -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.xml b/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.xml new file mode 100644 index 0000000000000000000000000000000000000000..8d1d4b4e22390fc590f38f660b144db1a54881c1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-misc-no-reboot.xml @@ -0,0 +1,22 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + destroy + destroy + + /usr/bin/qemu + + + + + + diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-user.args b/tests/qemuxml2argvdata/qemuxml2argv-net-user.args new file mode 100644 index 0000000000000000000000000000000000000000..bf49035d64e3c2dde7beecfbe5b945ee90d70a9d --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-user.args @@ -0,0 +1 @@ +/usr/bin/qemu -M pc -m 214 -smp 1 -monitor pty -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net nic,macaddr=00:11:22:33:44:55,vlan=0 -net user,vlan=0 -usb -nographic \ No newline at end of file diff --git a/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml b/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml new file mode 100644 index 0000000000000000000000000000000000000000..6a2d256d50fe60684854f42bcf4b16daba7448ce --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-net-user.xml @@ -0,0 +1,25 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219200 + 219200 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c new file mode 100644 index 0000000000000000000000000000000000000000..0cb2238e6ac7423525a53bc04659ebbaab7bf3e4 --- /dev/null +++ b/tests/qemuxml2argvtest.c @@ -0,0 +1,188 @@ +#include +#include + +#include +#include + +#include "testutils.h" +#include "qemu_conf.h" +#include "internal.h" + +static char *progname; +struct qemud_driver driver; + +#define MAX_FILE 4096 + +static int testCompareXMLToArgvFiles(const char *xml, const char *cmd) { + char xmlData[MAX_FILE]; + char argvData[MAX_FILE]; + char *xmlPtr = &(xmlData[0]); + char *expectargv = &(argvData[0]); + char *actualargv = NULL; + char **argv = NULL; + char **tmp = NULL; + int ret = -1, len; + struct qemud_vm_def *vmdef; + struct qemud_vm vm; + + if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) + goto fail; + + if (virtTestLoadFile(cmd, &expectargv, MAX_FILE) < 0) + goto fail; + + if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test"))) + goto fail; + + vm.def = vmdef; + vm.pid = -1; + vm.id = -1; + vmdef->vncActivePort = vmdef->vncPort; + + if (qemudBuildCommandLine(NULL, &driver, &vm, &argv) < 0) + goto fail; + + tmp = argv; + len = 0; + while (*tmp) { + len += strlen(*tmp) + 1; + tmp++; + } + actualargv = malloc(sizeof(char)*len); + actualargv[0] = '\0'; + tmp = argv; + len = 0; + while (*tmp) { + if (actualargv[0]) + strcat(actualargv, " "); + strcat(actualargv, *tmp); + tmp++; + } + + if (strcmp(expectargv, actualargv)) { + if (getenv("DEBUG_TESTS")) { + printf("Expect %4d '%s'\n", (int)strlen(expectargv), expectargv); + printf("Actual %4d '%s'\n", (int)strlen(actualargv), actualargv); + } + goto fail; + } + + ret = 0; + + fail: + free(actualargv); + if (argv) { + tmp = argv; + while (*tmp) { + free(*tmp); + tmp++; + } + free(argv); + } + + return ret; +} + + +static int testCompareXMLToArgvHelper(const void *data) { + char xml[PATH_MAX]; + char args[PATH_MAX]; + snprintf(xml, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.xml", (const char*)data); + snprintf(args, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.args", (const char*)data); + return testCompareXMLToArgvFiles(xml, args); +} + + + +int +main(int argc, char **argv) +{ + int ret = 0; + + progname = argv[0]; + + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", progname); + exit(EXIT_FAILURE); + } + + driver.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1; + driver.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON | + QEMUD_CMD_FLAG_NO_REBOOT; + + if (virtTestRun("QEMU XML-2-ARGV minimal", + 1, testCompareXMLToArgvHelper, "minimal") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot CDROM", + 1, testCompareXMLToArgvHelper, "boot-cdrom") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot Network", + 1, testCompareXMLToArgvHelper, "boot-network") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot Floppy", + 1, testCompareXMLToArgvHelper, "boot-floppy") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Clock UTC", + 1, testCompareXMLToArgvHelper, "clock-utc") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Clock Localtime", + 1, testCompareXMLToArgvHelper, "clock-localtime") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk CDROM", + 1, testCompareXMLToArgvHelper, "disk-cdrom") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk Floppy", + 1, testCompareXMLToArgvHelper, "disk-floppy") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk Many", + 1, testCompareXMLToArgvHelper, "disk-many") < 0) + ret = -1; + + if (0 && virtTestRun("QEMU XML-2-ARGV Graphics VNC", + 1, testCompareXMLToArgvHelper, "graphics-vnc") < 0) + ret = -1; + + if (0 && virtTestRun("QEMU XML-2-ARGV Graphics SDL", + 1, testCompareXMLToArgvHelper, "graphics-sdl") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Input USB Mouse", + 1, testCompareXMLToArgvHelper, "input-usbmouse") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Input USB Tablet", + 1, testCompareXMLToArgvHelper, "input-usbtablet") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Misc ACPI", + 1, testCompareXMLToArgvHelper, "misc-acpi") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Misc No Reboot", + 1, testCompareXMLToArgvHelper, "misc-no-reboot") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Net User", + 1, testCompareXMLToArgvHelper, "net-user") < 0) + ret = -1; + + + exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +} + +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * tab-width: 4 + * End: + */ diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c new file mode 100644 index 0000000000000000000000000000000000000000..fc596b334732d38c5648c18319f49060c6b45213 --- /dev/null +++ b/tests/qemuxml2xmltest.c @@ -0,0 +1,153 @@ +#include +#include + +#include +#include + +#include "testutils.h" +#include "qemu_conf.h" +#include "internal.h" + +static char *progname; +struct qemud_driver driver; + +#define MAX_FILE 4096 + + +static int testCompareXMLToXMLFiles(const char *xml) { + char xmlData[MAX_FILE]; + char *xmlPtr = &(xmlData[0]); + char *actual = NULL; + int ret = -1; + struct qemud_vm_def *vmdef; + struct qemud_vm vm; + + if (virtTestLoadFile(xml, &xmlPtr, MAX_FILE) < 0) + goto fail; + + if (!(vmdef = qemudParseVMDef(NULL, &driver, xmlData, "test"))) + goto fail; + + vm.def = vmdef; + vm.pid = -1; + vm.id = -1; + vmdef->vncActivePort = vmdef->vncPort; + + if (!(actual = qemudGenerateXML(NULL, &driver, &vm, vmdef, 0))) + goto fail; + + if (strcmp(xmlData, actual)) { + if (getenv("DEBUG_TESTS")) { + printf("Expect %4d '%s'\n", (int)strlen(xmlData), xmlData); + printf("Actual %4d '%s'\n", (int)strlen(actual), actual); + } + goto fail; + } + + ret = 0; + + fail: + free(actual); + + return ret; +} + +static int testCompareXMLToXMLHelper(const void *data) { + char xml[PATH_MAX]; + snprintf(xml, PATH_MAX, "qemuxml2argvdata/qemuxml2argv-%s.xml", (const char*)data); + return testCompareXMLToXMLFiles(xml); +} + + +int +main(int argc, char **argv) +{ + int ret = 0; + + progname = argv[0]; + + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", progname); + exit(EXIT_FAILURE); + } + + driver.qemuVersion = 0 * 1000 * 100 + (8 * 1000) + 1; + driver.qemuCmdFlags = QEMUD_CMD_FLAG_VNC_COLON | + QEMUD_CMD_FLAG_NO_REBOOT; + + if (virtTestRun("QEMU XML-2-ARGV minimal", + 1, testCompareXMLToXMLHelper, "minimal") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot CDROM", + 1, testCompareXMLToXMLHelper, "boot-cdrom") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot Network", + 1, testCompareXMLToXMLHelper, "boot-network") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Boot Floppy", + 1, testCompareXMLToXMLHelper, "boot-floppy") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Clock UTC", + 1, testCompareXMLToXMLHelper, "clock-utc") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Clock Localtime", + 1, testCompareXMLToXMLHelper, "clock-localtime") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk CDROM", + 1, testCompareXMLToXMLHelper, "disk-cdrom") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk Floppy", + 1, testCompareXMLToXMLHelper, "disk-floppy") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Disk Many", + 1, testCompareXMLToXMLHelper, "disk-many") < 0) + ret = -1; + + if (0 && virtTestRun("QEMU XML-2-ARGV Graphics VNC", + 1, testCompareXMLToXMLHelper, "graphics-vnc") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Graphics SDL", + 1, testCompareXMLToXMLHelper, "graphics-sdl") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Input USB Mouse", + 1, testCompareXMLToXMLHelper, "input-usbmouse") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Input USB Tablet", + 1, testCompareXMLToXMLHelper, "input-usbtablet") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Misc ACPI", + 1, testCompareXMLToXMLHelper, "misc-acpi") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Misc No Reboot", + 1, testCompareXMLToXMLHelper, "misc-no-reboot") < 0) + ret = -1; + + if (virtTestRun("QEMU XML-2-ARGV Net User", + 1, testCompareXMLToXMLHelper, "net-user") < 0) + ret = -1; + + + exit(ret==0 ? EXIT_SUCCESS : EXIT_FAILURE); +} + +/* + * Local variables: + * indent-tabs-mode: nil + * c-indent-level: 4 + * c-basic-offset: 4 + * tab-width: 4 + * End: + */