tests: Allow testing for parse failures in vmx2xmltest

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2021-01-05 14:19:21 +01:00
parent c1286d50e2
commit 152be66eaf
1 changed files with 18 additions and 6 deletions

View File

@ -66,7 +66,7 @@ testCapsInit(void)
} }
static int static int
testCompareFiles(const char *vmx, const char *xml) testCompareFiles(const char *vmx, const char *xml, bool should_fail_parse)
{ {
int ret = -1; int ret = -1;
char *vmxData = NULL; char *vmxData = NULL;
@ -74,9 +74,17 @@ testCompareFiles(const char *vmx, const char *xml)
virDomainDefPtr def = NULL; virDomainDefPtr def = NULL;
if (virTestLoadFile(vmx, &vmxData) < 0) if (virTestLoadFile(vmx, &vmxData) < 0)
goto cleanup; return -1;
if (!(def = virVMXParseConfig(&ctx, xmlopt, caps, vmxData))) def = virVMXParseConfig(&ctx, xmlopt, caps, vmxData);
if (should_fail_parse) {
if (!def)
ret = 0;
else
VIR_TEST_DEBUG("passed instead of expected failure");
goto cleanup;
}
if (!def)
goto cleanup; goto cleanup;
if (!virDomainDefCheckABIStability(def, def, xmlopt)) { if (!virDomainDefCheckABIStability(def, def, xmlopt)) {
@ -104,6 +112,7 @@ testCompareFiles(const char *vmx, const char *xml)
struct testInfo { struct testInfo {
const char *input; const char *input;
const char *output; const char *output;
bool should_fail;
}; };
static int static int
@ -119,7 +128,7 @@ testCompareHelper(const void *data)
xml = g_strdup_printf("%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir, xml = g_strdup_printf("%s/vmx2xmldata/vmx2xml-%s.xml", abs_srcdir,
info->output); info->output);
ret = testCompareFiles(vmx, xml); ret = testCompareFiles(vmx, xml, info->should_fail);
VIR_FREE(vmx); VIR_FREE(vmx);
VIR_FREE(xml); VIR_FREE(xml);
@ -171,9 +180,9 @@ mymain(void)
{ {
int ret = 0; int ret = 0;
# define DO_TEST(_in, _out) \ # define DO_TEST_FULL(_in, _out, _should_fail) \
do { \ do { \
struct testInfo info = { _in, _out }; \ struct testInfo info = { _in, _out, _should_fail }; \
virResetLastError(); \ virResetLastError(); \
if (virTestRun("VMware VMX-2-XML "_in" -> "_out, \ if (virTestRun("VMware VMX-2-XML "_in" -> "_out, \
testCompareHelper, &info) < 0) { \ testCompareHelper, &info) < 0) { \
@ -181,6 +190,9 @@ mymain(void)
} \ } \
} while (0) } while (0)
# define DO_TEST(_in, _out) DO_TEST_FULL(_in, _out, false)
# define DO_TEST_FAIL(_in, _out) DO_TEST_FULL(_in, _out, true)
testCapsInit(); testCapsInit();
if (caps == NULL) if (caps == NULL)