[PATCH 2/2] virschematest: Make sure that validator is initialized

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It may happen that a developer wants to run just a specific
subset of tests:

tests $ VIR_TEST_RANGE=22 ../run ./virschematest

This now fails miserably:

    ==6840== Invalid read of size 8
    ==6840==    at 0x4F397C0: virXMLValidatorValidate (virxml.c:1216)
    ==6840==    by 0x402B72: testSchemaFile (virschematest.c:53)
    ==6840==    by 0x403737: virTestRun (testutils.c:180)
    ==6840==    by 0x402CF5: testSchemaDir (virschematest.c:98)
    ==6840==    by 0x402EB1: testSchemaDirs (virschematest.c:131)
    ==6840==    by 0x40314D: mymain (virschematest.c:194)
    ==6840==    by 0x4051AF: virTestMain (testutils.c:982)
    ==6840==    by 0x4035A9: main (virschematest.c:217)
    ==6840==  Address 0x10 is not stack'd, malloc'd or (recently) free'd

Problem is, we are trying to do two types of tests here: validate
RNG schema itself, and validate XML files against RNG schemas.
And the latter tries to re-use a resource allocated in the
former. Therefore if the former is skipped (due to
VIR_TEST_RANGE) we have to allocate the resource manually.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/virschematest.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tests/virschematest.c b/tests/virschematest.c
index c9cc314..1b55dad 100644
--- a/tests/virschematest.c
+++ b/tests/virschematest.c
@@ -38,6 +38,14 @@ struct testSchemaData {
     const char *xml_path;
 };
 
+static char *
+testGetSchemaPath(const char *schema)
+{
+    char *schema_path;
+    ignore_value(virAsprintf(&schema_path, "%s/docs/schemas/%s",
+                             abs_topsrcdir, schema));
+    return schema_path;
+}
 
 static int
 testSchemaFile(const void *args)
@@ -120,6 +128,20 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...)
     int ret = 0;
     char *dir_path = NULL;
     const char *dir;
+    bool freeValidator = false;
+
+    if (!validator) {
+        char *schema_path = testGetSchemaPath(schema);
+
+        if (!schema_path ||
+            !(validator = virXMLValidatorInit(schema_path))) {
+            VIR_FREE(schema_path);
+            goto cleanup;
+        }
+
+        VIR_FREE(schema_path);
+        freeValidator = true;
+    }
 
     va_start(args, validator);
 
@@ -134,6 +156,8 @@ testSchemaDirs(const char *schema, virXMLValidatorPtr validator, ...)
     }
 
  cleanup:
+    if (freeValidator)
+        virXMLValidatorFree(validator);
     VIR_FREE(dir_path);
     va_end(args);
     return ret;
@@ -152,8 +176,7 @@ testSchemaGrammar(const void *opaque)
     char *schema_path;
     int ret = -1;
 
-    if (virAsprintf(&schema_path, "%s/docs/schemas/%s",
-                    abs_topsrcdir, data->schema) < 0)
+    if (!(schema_path = testGetSchemaPath(data->schema)))
         return -1;
 
     if (!(data->validator = virXMLValidatorInit(schema_path)))
-- 
2.8.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]