]> xenbits.xensource.com Git - people/aperard/libvirt.git/commitdiff
qemuxml2argvtest: Check for duplicate invocation of tests
authorPeter Krempa <pkrempa@redhat.com>
Fri, 1 Dec 2023 15:27:26 +0000 (16:27 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 4 Jan 2024 21:26:10 +0000 (22:26 +0100)
Prevent duplicated invocation of tests by tracking use of output files.
Some cases need to be exempt from this for now.

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

index f1589345c3d8b47a4a328e52a9df4f39c5852172..4796b628537267f356fb335308305161f416d49a 100644 (file)
@@ -73,7 +73,7 @@ mymain(void)
 {
     int ret = 0;
     g_autoptr(virConnect) conn = NULL;
-    struct testQemuConf testConf = { NULL, NULL, NULL };
+    struct testQemuConf testConf = { NULL, NULL, NULL, NULL };
 
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
index e58858f50b5f105a70469e0b1a753c77710c9557..04abf5cd1a67519f3a534b6244f1435b19e3474a 100644 (file)
@@ -273,6 +273,7 @@ testCheckExclusiveFlags(int flags)
                   FLAG_FIPS_HOST |
                   FLAG_REAL_CAPS |
                   FLAG_SLIRP_HELPER |
+                  FLAG_ALLOW_DUPLICATE_OUTPUT |
                   0, -1);
 
     return 0;
@@ -477,6 +478,28 @@ testCompareXMLToArgvValidateSchema(virCommand *cmd,
 }
 
 
+static int
+testInfoCheckDuplicate(struct testQemuInfo *info)
+{
+    const char *path = info->outfile;
+
+    if (info->flags & FLAG_ALLOW_DUPLICATE_OUTPUT)
+        return 0;
+
+    if (info->flags & (FLAG_EXPECT_FAILURE | FLAG_EXPECT_PARSE_ERROR))
+        path = info->errfile;
+
+    if (g_hash_table_contains(info->conf->duplicateTests, path)) {
+        fprintf(stderr, "\nduplicate invocation of test case: %s\n'", path);
+        return -1;
+    }
+
+    g_hash_table_insert(info->conf->duplicateTests, g_strdup(path), NULL);
+
+    return 0;
+}
+
+
 static int
 testCompareXMLToArgv(const void *data)
 {
@@ -503,6 +526,9 @@ testCompareXMLToArgv(const void *data)
     if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0)
         goto cleanup;
 
+    if (testInfoCheckDuplicate(info) < 0)
+        goto cleanup;
+
     if (info->arch != VIR_ARCH_NONE && info->arch != VIR_ARCH_X86_64)
         qemuTestSetHostArch(&driver, info->arch);
 
@@ -688,12 +714,14 @@ static int
 mymain(void)
 {
     int ret = 0;
+    g_autoptr(GHashTable) duplicateTests = 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 };
+                                     .qapiSchemaCache = qapiSchemaCache,
+                                     .duplicateTests = duplicateTests };
 
     if (!capslatest)
         return EXIT_FAILURE;
@@ -852,7 +880,7 @@ mymain(void)
     DO_TEST_CAPS_ARCH_VER_PARSE_ERROR(name, "x86_64", ver)
 
 # define DO_TEST_GIC(name, ver, gic) \
-    DO_TEST_CAPS_ARCH_VER_FULL(name, "aarch64", ver, ARG_GIC, gic, ARG_END)
+    DO_TEST_CAPS_ARCH_VER_FULL(name, "aarch64", ver, ARG_GIC, gic, ARG_FLAGS, FLAG_ALLOW_DUPLICATE_OUTPUT, ARG_END)
 
     /* Unset or set all envvars here that are copied in qemudBuildCommandLine
      * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected
@@ -1344,7 +1372,7 @@ mymain(void)
     DO_TEST_CAPS_LATEST("net-vhostuser-multiq");
     DO_TEST_CAPS_LATEST_FAILURE("net-vhostuser-fail");
     DO_TEST_CAPS_LATEST("net-user");
-    DO_TEST_CAPS_ARCH_LATEST_FULL("net-user", "x86_64", ARG_FLAGS, FLAG_SLIRP_HELPER);
+    DO_TEST_CAPS_ARCH_LATEST_FULL("net-user", "x86_64", ARG_FLAGS, FLAG_SLIRP_HELPER | FLAG_ALLOW_DUPLICATE_OUTPUT);
     DO_TEST_CAPS_LATEST("net-user-addr");
     DO_TEST_CAPS_LATEST("net-user-passt");
     DO_TEST_CAPS_VER("net-user-passt", "7.2.0");
@@ -1595,7 +1623,8 @@ mymain(void)
                                   ARG_MIGRATE_FD, 7);
     DO_TEST_CAPS_ARCH_LATEST_FULL("restore-v2-fd", "x86_64",
                                   ARG_MIGRATE_FROM, "fd:7",
-                                  ARG_MIGRATE_FD, 7);
+                                  ARG_MIGRATE_FD, 7,
+                                  ARG_FLAGS, FLAG_ALLOW_DUPLICATE_OUTPUT);
     DO_TEST_CAPS_ARCH_LATEST_FULL("migrate", "x86_64",
                                   ARG_MIGRATE_FROM, "tcp:10.0.0.1:5000");
     DO_TEST_CAPS_ARCH_LATEST_FULL("migrate-numa-unaligned", "x86_64",
index 8dbc48075623d71adbdd6345ebbc442b95db25ee..71e220de3a1ae57a898e5335116914adeb3f14a5 100644 (file)
@@ -62,12 +62,14 @@ typedef enum {
     FLAG_REAL_CAPS          = 1 << 3,
     FLAG_SLIRP_HELPER       = 1 << 4,
     FLAG_SKIP_CONFIG_ACTIVE = 1 << 5, /* Skip 'active' config test in qemuxml2xmltest */
+    FLAG_ALLOW_DUPLICATE_OUTPUT = 1 << 6, /* allow multiple tests with the same output file */
 } testQemuInfoFlags;
 
 struct testQemuConf {
     GHashTable *capscache;
     GHashTable *capslatest;
     GHashTable *qapiSchemaCache;
+    GHashTable *duplicateTests; /* for checking duplicated invocations */
 };
 
 typedef enum {