Re: [PATCH v2 1/7] tests: qemu: Add helper code to lookup most recent capability file

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

 



On Wed, Apr 18, 2018 at 11:38:41AM +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@xxxxxxxxxx>
---
tests/testutilsqemu.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/testutilsqemu.h |  5 +++
2 files changed, 99 insertions(+)

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

#endif
+
+
+static bool
+testQemuCapsIsNewerVersion(char **cur,
+                           char **max)
+{
+    size_t i;
+    int rc;
+
+    for (i = 0; i < 3; i++) {
+        rc = strlen(cur[i]) - strlen(max[i]);
+
+        if (rc > 0)
+            return true;
+
+        if (rc < 0)
+            return false;
+
+        rc = strcmp(cur[i], max[i]);
+
+        if (rc > 0)
+            return true;
+
+        if (rc < 0)
+            return false;
+    }
+
+    return false;
+}
+
+
+char *
+testQemuGetNewestCapsForArch(const char *dirname,
+                             const char *arch,
+                             const char *suffix)
+{
+    struct dirent *ent;
+    int rc;
+    DIR *dir = NULL;
+    char *ret = NULL;
+    const char *tmp;
+    char **max = NULL;
+    size_t nmax = 0;
+    const char *maxname = NULL;
+    char **cur = NULL;
+    size_t ncur = 0;
+
+    if (virDirOpen(&dir, dirname) < 0)
+        goto cleanup;
+
+    while ((rc = virDirRead(dir, &ent, dirname)) > 0) {
+        virStringListFreeCount(cur, ncur);
+        cur = NULL;
+        ncur = 0;
+
+        if (!(tmp = STRSKIP(ent->d_name, "caps_")))
+            continue;
+
+        if (!strstr(tmp, suffix) || !strstr(tmp, arch))
+            continue;
+

This helper assumes the prefix is "caps_" but leaves the suffix
configurable.

You can concatenate arch and suffix into some real_suffix, then
1. STRDUP(tmp, STRSKIP( "caps_"))
2. virFileStripSuffix(tmp, real_suffix)
3. Either use virParseVersionString and a plain numeric comparison,
  or import strverscmp from gnulib instead of subjecting the reader
  to testQemuCapsIsNewerVersion.

Jano

+        if (!(cur = virStringSplitCount(tmp, ".", 4, &ncur)))
+            goto cleanup;
+
+        if (ncur != 4) {
+            VIR_TEST_DEBUG("skipping caps file '%s'\n", ent->d_name);
+            continue;
+        }
+
+        if (!max || testQemuCapsIsNewerVersion(cur, max)) {
+            VIR_STEAL_PTR(max, cur);
+            maxname = ent->d_name;
+            nmax = ncur;
+            ncur = 0;
+        }
+    }
+
+    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:
+    virStringListFreeCount(max, nmax);
+    virStringListFreeCount(cur, ncur);
+    virDirClose(&dir);
+    return ret;
+}
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 7ae8324933..6490db4b95 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -39,4 +39,9 @@ int qemuTestCapsCacheInsert(virFileCachePtr cache,

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

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

Attachment: signature.asc
Description: Digital signature

--
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]

  Powered by Linux