]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemuxml2argvtest: Add checker that all input files are used
authorPeter Krempa <pkrempa@redhat.com>
Fri, 1 Dec 2023 15:47:23 +0000 (16:47 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 4 Jan 2024 21:26:10 +0000 (22:26 +0100)
To prevent regressions when refactoring tests and accidentally forgotten
input files make sure that qemuxml2argvtest is invoked for all input
files in tests/qemuxml2argvdata

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/qemustatusxml2xmltest.c
tests/qemuxml2argvtest.c
tests/testutils.c
tests/testutils.h
tests/testutilsqemu.h

index 4796b628537267f356fb335308305161f416d49a..f60378c6916058b320b43cd13ae07a9605200c54 100644 (file)
@@ -73,7 +73,7 @@ mymain(void)
 {
     int ret = 0;
     g_autoptr(virConnect) conn = NULL;
-    struct testQemuConf testConf = { NULL, NULL, NULL, NULL };
+    struct testQemuConf testConf = { NULL, NULL, NULL, NULL, NULL };
 
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
index 9a93fd8990c1bbb0f766835e5f63f938fdeb482a..cb78465fc23638e51242544f297c951513ff1599 100644 (file)
@@ -623,6 +623,9 @@ testCompareXMLToArgv(const void *data)
     virArch arch = VIR_ARCH_NONE;
     g_autoptr(virIdentity) sysident = virIdentityGetSystem();
 
+    /* mark test case as used */
+    ignore_value(g_hash_table_remove(info->conf->existingTestCases, info->infile));
+
     if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0)
         goto cleanup;
 
@@ -820,22 +823,76 @@ testInfoSetPaths(struct testQemuInfo *info,
                                       abs_srcdir, info->name, suffix ? suffix : "");
 }
 
+
+static int
+testConfXMLCheck(GHashTable *existingTestCases)
+{
+    g_autofree virHashKeyValuePair *items = virHashGetItems(existingTestCases, NULL, true);
+    size_t i;
+    int ret = 0;
+
+    for (i = 0; items[i].key; i++) {
+        if (ret == 0)
+            fprintf(stderr, "\n");
+
+        fprintf(stderr, "unused input file: %s\n", (const char *) items[i].key);
+        ret = -1;
+    }
+
+    return ret;
+}
+
+
+static int
+testConfXMLEnumerate(GHashTable *existingTestCases)
+{
+    struct dirent *ent;
+    g_autoptr(DIR) dir = NULL;
+    int rc;
+
+    /* If VIR_TEST_RANGE is in use don't bother filling in the data, which
+     * also makes testConfXMLCheck succeed. */
+    if (virTestHasRangeBitmap())
+        return 0;
+
+    if (virDirOpen(&dir, abs_srcdir "/qemuxml2argvdata") < 0)
+        return -1;
+
+    while ((rc = virDirRead(dir, &ent, abs_srcdir "/qemuxml2argvdata")) > 0) {
+        if (virStringHasSuffix(ent->d_name, ".xml")) {
+            g_hash_table_insert(existingTestCases,
+                                g_strdup_printf(abs_srcdir "/qemuxml2argvdata/%s", ent->d_name),
+                                NULL);
+        }
+    }
+
+    return rc;
+}
+
+
 static int
 mymain(void)
 {
     int ret = 0;
     g_autoptr(GHashTable) duplicateTests = virHashNew(NULL);
+    g_autoptr(GHashTable) existingTestCases = virHashNew(NULL);
     g_autoptr(GHashTable) capslatest = testQemuGetLatestCaps();
     g_autoptr(GHashTable) qapiSchemaCache = virHashNew((GDestroyNotify) g_hash_table_unref);
     g_autoptr(GHashTable) capscache = virHashNew(virObjectUnref);
     struct testQemuConf testConf = { .capslatest = capslatest,
                                      .capscache = capscache,
                                      .qapiSchemaCache = qapiSchemaCache,
-                                     .duplicateTests = duplicateTests };
+                                     .duplicateTests = duplicateTests,
+                                     .existingTestCases = existingTestCases };
 
     if (!capslatest)
         return EXIT_FAILURE;
 
+    /* enumerate and store all available test cases to verify at the end that
+     * all of them were invoked */
+    if (testConfXMLEnumerate(existingTestCases) < 0)
+        return EXIT_FAILURE;
+
     /* Set the timezone because we are mocking the time() function.
      * If we don't do that, then localtime() may return unpredictable
      * results. In order to detect things that just work by a blind
@@ -2600,6 +2657,10 @@ mymain(void)
     DO_TEST_CAPS_LATEST("tap-vhost-incorrect");
     DO_TEST_CAPS_LATEST("tap-vhost");
 
+    /* check that all input files were actually used here */
+    if (testConfXMLCheck(existingTestCases) < 0)
+        ret = -1;
+
     qemuTestDriverFree(&driver);
     virFileWrapperClearPrefixes();
 
index e5464229419a42e07fedc515c9af879e06c2c0a5..b20e447b99a86050602af26f88936c5a1ce20b9a 100644 (file)
@@ -746,6 +746,20 @@ virTestGetRegenerate(void)
     return testRegenerate;
 }
 
+
+/**
+ * virTestHasRangeBitmap:
+ *
+ * Returns whether the test was invoked with VIR_TEST_RANGE declared thus
+ * limiting the run only on specific test cases.
+ */
+bool
+virTestHasRangeBitmap(void)
+{
+    return !!testBitmap;
+}
+
+
 static int
 virTestSetEnvPath(void)
 {
index cf8a346dffcc37d1e0cbc2f735f7526901154cfb..bb84327b1ea3c7a6148bc8db21501b9c4c929fcf 100644 (file)
@@ -82,6 +82,8 @@ unsigned int virTestGetExpensive(void);
 unsigned int virTestGetRegenerate(void);
 void virTestPropagateLibvirtError(void);
 
+bool virTestHasRangeBitmap(void);
+
 #define VIR_TEST_DEBUG(fmt, ...) \
     do { \
         if (virTestGetDebug()) \
index 71e220de3a1ae57a898e5335116914adeb3f14a5..0d570ec31ef90c66ff28d652ab6637a25faaed0f 100644 (file)
@@ -70,6 +70,7 @@ struct testQemuConf {
     GHashTable *capslatest;
     GHashTable *qapiSchemaCache;
     GHashTable *duplicateTests; /* for checking duplicated invocations */
+    GHashTable *existingTestCases; /* for checking missing invocations */
 };
 
 typedef enum {