From: Peter Krempa <pkre...@redhat.com>

This is purely a devel-time problem in the test suite.

'qemuxmlactivetest' invokes the whole test worker twice, once for
inactive output and second time for active.

Now 'testQemuInfoInitArgs' returns a failure if the XML is invalid and
the test is skipped. On another invocation though it returns 0 if
'testQemuInfoSetArgs' was not invoked meanwhile and thus makes it seem
it succeeded which leads to a crash in the code assuming that some
pointers are valid.

Use same interlocking as 'qemuxmlconftest' to skip the second invocation
on failure of the first one.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 tests/qemuxmlactivetest.c | 67 +++++++++++++++++++++++++--------------
 1 file changed, 43 insertions(+), 24 deletions(-)

diff --git a/tests/qemuxmlactivetest.c b/tests/qemuxmlactivetest.c
index b132b91623..de2b1e48eb 100644
--- a/tests/qemuxmlactivetest.c
+++ b/tests/qemuxmlactivetest.c
@@ -87,6 +87,45 @@ testRunStatus(const char *name,
 }


+static int
+testqemuActiveXML2XMLCommonPrepare(testQemuInfo *info)
+{
+    if (info->prepared)
+        return 0;
+
+    if (testQemuInfoInitArgs((testQemuInfo *) info) < 0)
+        goto error;
+
+    virFileCacheClear(driver.qemuCapsCache);
+
+    if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
+        goto error;
+
+    if (!(info->def = virDomainDefParseFile(info->infile,
+                                            driver.xmlopt, NULL,
+                                            info->parseFlags)))
+        goto error;
+
+    if (!virDomainDefCheckABIStability(info->def, info->def, driver.xmlopt)) {
+        VIR_TEST_DEBUG("ABI stability check failed on %s", info->infile);
+        goto error;
+    }
+
+    /* make sure that the XML definition looks active, by setting an ID
+     * as otherwise the XML formatter will simply assume that it's inactive */
+    if (info->def->id == -1)
+        info->def->id = 1337;
+
+    info->prepared = true;
+    return 0;
+
+ error:
+    info->prep_skip = true;
+    info->prepared = true;
+    return -1;
+}
+
+
 static int
 testqemuActiveXML2XMLCommon(testQemuInfo *info,
                             bool live)
@@ -95,31 +134,11 @@ testqemuActiveXML2XMLCommon(testQemuInfo *info,
     const char *outfile = info->out_xml_active;
     unsigned int format_flags = VIR_DOMAIN_DEF_FORMAT_SECURE;

-    /* Prepare the test data and parse the input just once */
-    if (!info->def) {
-        if (testQemuInfoInitArgs((testQemuInfo *) info) < 0)
-            return -1;
-
-        virFileCacheClear(driver.qemuCapsCache);
+    if (info->prep_skip)
+        return EXIT_AM_SKIP;

-        if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0)
-            return -1;
-
-        if (!(info->def = virDomainDefParseFile(info->infile,
-                                                driver.xmlopt, NULL,
-                                                info->parseFlags)))
-            return -1;
-
-        if (!virDomainDefCheckABIStability(info->def, info->def, 
driver.xmlopt)) {
-            VIR_TEST_DEBUG("ABI stability check failed on %s", info->infile);
-            return -1;
-        }
-
-        /* make sure that the XML definition looks active, by setting an ID
-         * as otherwise the XML formatter will simply assume that it's 
inactive */
-        if (info->def->id == -1)
-            info->def->id = 1337;
-    }
+    if (testqemuActiveXML2XMLCommonPrepare(info) < 0)
+        return -1;

     if (!live) {
         format_flags |= VIR_DOMAIN_DEF_FORMAT_INACTIVE;
-- 
2.49.0

Reply via email to