Signed-off-by: Mark McLoughlin <markmc@xxxxxxxxxx> --- src/qemu_conf.c | 8 ++-- src/qemu_conf.h | 5 +++ tests/Makefile.am | 9 +++-- tests/qemuvertest.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 tests/qemuvertest.c diff --git a/src/qemu_conf.c b/src/qemu_conf.c index ea0d2f9..4edfedb 100644 --- a/src/qemu_conf.c +++ b/src/qemu_conf.c @@ -431,10 +431,10 @@ virCapsPtr qemudCapsInit(void) { #define QEMU_KVM_VER_PREFIX " (qemu-kvm-" #define KVM_VER_PREFIX " (kvm-" -static int qemudParseVersionStr(const char *str, - unsigned int *version, - unsigned int *is_kvm, - unsigned int *kvm_version) +int qemudParseVersionStr(const char *str, + unsigned int *version, + unsigned int *is_kvm, + unsigned int *kvm_version) { unsigned major, minor, micro; const char *p = str; diff --git a/src/qemu_conf.h b/src/qemu_conf.h index 1001e00..40a4a97 100644 --- a/src/qemu_conf.h +++ b/src/qemu_conf.h @@ -125,6 +125,11 @@ int qemudExtractVersionInfo (const char *qemu, unsigned int *version, unsigned int *flags); +int qemudParseVersionStr (const char *str, + unsigned int *version, + unsigned int *is_kvm, + unsigned int *kvm_version); + int qemudBuildCommandLine (virConnectPtr conn, struct qemud_driver *driver, virDomainDefPtr def, diff --git a/tests/Makefile.am b/tests/Makefile.am index 621a0be..3cf06a8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -61,7 +61,7 @@ noinst_PROGRAMS += xml2sexprtest sexpr2xmltest \ reconnect xmconfigtest xencapstest endif if WITH_QEMU -noinst_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest +noinst_PROGRAMS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuvertest endif if WITH_SECDRIVER_SELINUX @@ -119,7 +119,7 @@ endif endif if WITH_QEMU -TESTS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest +TESTS += qemuxml2argvtest qemuxml2xmltest qemuargv2xmltest qemuvertest endif if WITH_SECDRIVER_SELINUX @@ -199,8 +199,11 @@ qemuargv2xmltest_SOURCES = \ qemuargv2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h qemuargv2xmltest_LDADD = ../src/libvirt_driver_qemu.la $(LDADDS) + +qemuvertest_SOURCES = qemuvertest.c testutils.c testutils.h +qemuvertest_LDADD = ../src/libvirt_driver_qemu.la $(LDADDS) else -EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c testutilsqemu.c testutilsqemu.h +EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c qemuvertest.c testutilsqemu.c testutilsqemu.h endif nodedevxml2xmltest_SOURCES = \ diff --git a/tests/qemuvertest.c b/tests/qemuvertest.c new file mode 100644 index 0000000..bc9b7d6 --- /dev/null +++ b/tests/qemuvertest.c @@ -0,0 +1,89 @@ +#include <config.h> + +#ifdef WITH_QEMU + +#include <stdio.h> +#include <stdlib.h> + +#include "testutils.h" +#include "qemu_conf.h" + +struct testInfo { + const char *name; + const char *str; + unsigned version; + unsigned is_kvm; + unsigned kvm_version; +}; + +static char *progname; + +static int testVersionParsing(const void *data) +{ + const struct testInfo *info = data; + unsigned version, is_kvm, kvm_version; + + if (qemudParseVersionStr(info->str, &version, &is_kvm, &kvm_version) == -1) { + fprintf(stderr, "Failed to parse version string '%s'\n", info->str); + return -1; + } + + if (version != info->version) { + fprintf(stderr, "Parsed versions do not match: got %u, expected %u\n", + version, info->version); + return -1; + } + + if (is_kvm != info->is_kvm) { + fprintf(stderr, "Parsed is_kvm flag does not match: got %u, expected %u\n", + is_kvm, info->is_kvm); + return -1; + } + + if (kvm_version != kvm_version) { + fprintf(stderr, "Parsed KVM versions do not match: got %u, expected %u\n", + version, kvm_version); + return -1; + } + + return 0; + +} + +static int +mymain(int argc, char **argv) +{ + int ret = 0; + + progname = argv[0]; + + if (argc > 1) { + fprintf(stderr, "Usage: %s\n", progname); + return (EXIT_FAILURE); + } + +#define DO_TEST(name, str, version, is_kvm, kvm_version) \ + do { \ + const struct testInfo info = { name, str, version, is_kvm, kvm_version }; \ + if (virtTestRun("QEMU Version Parse " name, \ + 1, testVersionParsing, &info) < 0) \ + ret = -1; \ + } while (0) + + DO_TEST("qemu-0.9.1", "QEMU PC emulator version 0.9.1,", 9001, 0, 0); + DO_TEST("kvm-74", "QEMU PC emulator version 0.9.1 (kvm-74),", 9001, 1, 74); + DO_TEST("qemu-0.10.1", "QEMU PC emulator version 0.10.1,", 10001, 0, 0); + DO_TEST("qemu-kvm-0.10.4", "QEMU PC emulator version 0.10.4 (qemu-kvm-0.10.4),", 10004, 1, 0); + DO_TEST("kvm-85", "QEMU PC emulator version 0.10.50 (kvm-85),", 10050, 1, 85); + DO_TEST("kvm-86", "QEMU PC emulator version 0.10.50 (qemu-kvm-devel-86),", 10050, 1, 0); + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIRT_TEST_MAIN(mymain) + +#else + +int main (void) { return (77); /* means 'test skipped' for automake */ } + +#endif /* WITH_QEMU */ -- 1.6.0.6 -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list