]> xenbits.xensource.com Git - libvirt.git/commitdiff
virschematest: Make sure that validator is initialized
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 15 Aug 2016 07:51:10 +0000 (09:51 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 15 Aug 2016 07:51:10 +0000 (09:51 +0200)
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@redhat.com>
tests/virschematest.c

index c9cc314c62e96a7dfc85ecfe39efc4a1b65ce94a..b31a5bca916b7b8e3e3869458fcc719ed55d3804 100644 (file)
@@ -180,6 +180,12 @@ mymain(void)
         data.schema = sch;                                                     \
         if (virTestRun("test schema grammar file: " sch,                       \
                        testSchemaGrammar, &data) == 0) {                       \
+            /* initialize the validator even if the schema test                \
+             * was skipped because of VIR_TEST_RANGE */                        \
+            if (!data.validator && testSchemaGrammar(&data) < 0) {             \
+                ret = -1;                                                      \
+                break;                                                         \
+            }                                                                  \
             if (testSchemaDirs(sch, data.validator, __VA_ARGS__, NULL) < 0)    \
                 ret = -1;                                                      \
                                                                                \