[libvirt] [PATCH v3 1/7] tests: qemu: Add helper code to lookup latest capability file

Peter Krempa posted 7 patches 7 years ago
[libvirt] [PATCH v3 1/7] tests: qemu: Add helper code to lookup latest capability file
Posted by Peter Krempa 7 years ago
The helper iterates the directory with files for the capability test and
looks up the most recent one for the given architecture. This will allow
testing against the newest qemu capabilities so that we can catch
regressions in behaviour more easily.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/testutilsqemu.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 tests/testutilsqemu.h |  5 ++++
 2 files changed, 68 insertions(+)

diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 9671a46f12..3222d7864c 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -674,3 +674,66 @@ testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
 }

 #endif
+
+
+char *
+testQemuGetLatestCapsForArch(const char *dirname,
+                             const char *arch,
+                             const char *suffix)
+{
+    struct dirent *ent;
+    DIR *dir = NULL;
+    int rc;
+    char *fullsuffix = NULL;
+    char *tmp = NULL;
+    unsigned long maxver = 0;
+    unsigned long ver;
+    const char *maxname = NULL;
+    char *ret = NULL;
+
+    if (virAsprintf(&fullsuffix, "%s.%s", arch, suffix) < 0)
+        goto cleanup;
+
+    if (virDirOpen(&dir, dirname) < 0)
+        goto cleanup;
+
+    while ((rc = virDirRead(dir, &ent, dirname)) > 0) {
+        VIR_FREE(tmp);
+
+        if ((rc = VIR_STRDUP(tmp, STRSKIP(ent->d_name, "caps_"))) < 0)
+            goto cleanup;
+
+        if (rc == 0)
+            continue;
+
+        if (virFileStripSuffix(tmp, fullsuffix) != 1)
+            continue;
+
+        if (virParseVersionString(tmp, &ver, false) < 0) {
+            VIR_TEST_DEBUG("skipping caps file '%s'\n", ent->d_name);
+            continue;
+        }
+
+        if (ver > maxver) {
+            maxname = ent->d_name;
+            maxver = ver;
+        }
+    }
+
+    if (rc < 0)
+        goto cleanup;
+
+    if (!maxname) {
+        VIR_TEST_VERBOSE("failed to find capabilities for '%s' in '%s'\n",
+                         arch, dirname);
+        goto cleanup;
+    }
+
+    ignore_value(virAsprintf(&ret, "%s/%s", dirname, maxname));
+
+ cleanup:
+    VIR_FREE(tmp);
+    VIR_FREE(fullsuffix);
+    virDirClose(&dir);
+    return ret;
+}
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 7ae8324933..efb1baeadd 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -39,4 +39,9 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,

 int testQemuCapsSetGIC(virQEMUCapsPtr qemuCaps,
                        int gic);
+
+char *testQemuGetLatestCapsForArch(const char *dirname,
+                                   const char *arch,
+                                   const char *suffix);
+
 #endif
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 1/7] tests: qemu: Add helper code to lookup latest capability file
Posted by Ján Tomko 7 years ago
On Wed, Apr 18, 2018 at 05:33:32PM +0200, Peter Krempa wrote:
>The helper iterates the directory with files for the capability test and
>looks up the most recent one for the given architecture. This will allow
>testing against the newest qemu capabilities so that we can catch
>regressions in behaviour more easily.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> tests/testutilsqemu.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
> tests/testutilsqemu.h |  5 ++++
> 2 files changed, 68 insertions(+)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

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