Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx> --- tests/vmx2xmldata/vmx2xml-unsafe.vmx | 2 ++ tests/vmx2xmldata/vmx2xml-unsafe.xml | 18 ++++++++++++++++++ tests/vmx2xmltest.c | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 tests/vmx2xmldata/vmx2xml-unsafe.vmx create mode 100644 tests/vmx2xmldata/vmx2xml-unsafe.xml diff --git a/tests/vmx2xmldata/vmx2xml-unsafe.vmx b/tests/vmx2xmldata/vmx2xml-unsafe.vmx new file mode 100644 index 0000000..a3998ed --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-unsafe.vmx @@ -0,0 +1,2 @@ +config.version = "8" +virtualHW.version = "11" diff --git a/tests/vmx2xmldata/vmx2xml-unsafe.xml b/tests/vmx2xmldata/vmx2xml-unsafe.xml new file mode 100644 index 0000000..38bcf43 --- /dev/null +++ b/tests/vmx2xmldata/vmx2xml-unsafe.xml @@ -0,0 +1,18 @@ +<domain type='vmware'> + <uuid>00000000-0000-0000-0000-000000000000</uuid> + <memory unit='KiB'>32768</memory> + <currentMemory unit='KiB'>32768</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686'>hvm</type> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <video> + <model type='vmvga' vram='4096'/> + </video> + </devices> +</domain> diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c index 1d2e012..6877610 100644 --- a/tests/vmx2xmltest.c +++ b/tests/vmx2xmltest.c @@ -19,6 +19,10 @@ static virCapsPtr caps; static virDomainXMLOptionPtr xmlopt; static virVMXContext ctx; +typedef enum { + FLAG_ALLOW_UNSAFE = 1 << 0, + FLAG_EXPECT_ERROR = 1 << 1, +} testCompareHelperFlags; static void testCapsInit(void) @@ -71,7 +75,7 @@ testCapsInit(void) } static int -testCompareFiles(const char *vmx, const char *xml) +testCompareFiles(const char *vmx, const char *xml, bool allowUnsafe) { int ret = -1; char *vmxData = NULL; @@ -85,7 +89,7 @@ testCompareFiles(const char *vmx, const char *xml) if (virtTestLoadFile(xml, &xmlData) < 0) goto cleanup; - if (!(def = virVMXParseConfig(&ctx, xmlopt, vmxData))) + if (!(def = virVMXParseConfig(&ctx, xmlopt, vmxData, allowUnsafe))) goto cleanup; if (!virDomainDefCheckABIStability(def, def)) { @@ -115,6 +119,8 @@ testCompareFiles(const char *vmx, const char *xml) struct testInfo { const char *input; const char *output; + + unsigned int flags; }; static int @@ -132,7 +138,21 @@ testCompareHelper(const void *data) goto cleanup; } - ret = testCompareFiles(vmx, xml); + ret = testCompareFiles(vmx, xml, info->flags & FLAG_ALLOW_UNSAFE); + + if (info->flags & FLAG_EXPECT_ERROR) { + if (ret == 0) { + ret = -1; + if (virTestGetDebug()) + fprintf(stderr, "qemuBuildCommandLine should have failed\n"); + } else if (ret < 0) { + if (virTestGetDebug() > 1) + fprintf(stderr, "Got expected error: %s\n", + virGetLastErrorMessage()); + virResetLastError(); + ret = 0; + } + } cleanup: VIR_FREE(vmx); @@ -189,9 +209,9 @@ mymain(void) { int ret = 0; -# define DO_TEST(_in, _out) \ +# define DO_TEST_FULL(_in, _out, flags) \ do { \ - struct testInfo info = { _in, _out }; \ + struct testInfo info = { _in, _out, flags}; \ virResetLastError(); \ if (virtTestRun("VMware VMX-2-XML "_in" -> "_out, \ testCompareHelper, &info) < 0) { \ @@ -199,6 +219,9 @@ mymain(void) } \ } while (0) +# define DO_TEST(_in, _out) DO_TEST_FULL(_in, _out, 0) + + testCapsInit(); if (caps == NULL) { @@ -285,6 +308,9 @@ mymain(void) DO_TEST("annotation", "annotation"); + DO_TEST_FULL("unsafe", "unsafe", FLAG_ALLOW_UNSAFE); + DO_TEST_FULL("unsafe", "unsafe", FLAG_EXPECT_ERROR); + DO_TEST("smbios", "smbios"); DO_TEST("svga", "svga"); -- 1.9.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list