[08/12] tests: add testQemuGetCapsLatest

Message ID 2c2e42731c05ba2c59fccc483e1a079bc99b4f4b.1554137098.git.crobinso@redhat.com
State New
Headers show
Series
  • tests: qemuxml2xml: add DO_TEST_CAPS*
Related show

Commit Message

Cole Robinson April 1, 2019, 4:47 p.m.
Move the capslatest building from qemuxml2argv to testutilsqemu

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 tests/qemuxml2argvtest.c | 25 ++-----------------------
 tests/testutilsqemu.c    | 37 +++++++++++++++++++++++++++++++++++++
 tests/testutilsqemu.h    |  1 +
 3 files changed, 40 insertions(+), 23 deletions(-)

-- 
2.21.0

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

Comments

Andrea Bolognani April 10, 2019, 4:39 p.m. | #1
On Mon, 2019-04-01 at 12:47 -0400, Cole Robinson wrote:
[...]
> +virHashTablePtr

> +testQemuGetCapsLatest(void)


A better name for this would be testQemuGetLatestCaps(), since it's
literally calling testQemuGetLatestCapsForArch() over a number of
architectures.

Incidentally, both these functions could use TEST_QEMU_CAPS_PATH
once it's introduced, and lose an hardcoded string and a parameter
respectively O:-)

[...]
> +++ b/tests/testutilsqemu.h

> @@ -109,6 +109,7 @@ int testQemuCapsIterate(const char *dirname,

>  int testQemuInfoSetArgs(struct testQemuInfo *info,

>                          virHashTablePtr capslatest, ...);

>  void testQemuInfoClear(struct testQemuInfo *info);

> +virHashTablePtr testQemuGetCapsLatest(void);


Both in the source and in the header file, order this new function
right after the existing testQemuGetLatestCapsForArch().

With the function named and placed appropriately,

  Reviewed-by: Andrea Bolognani <abologna@redhat.com>


-- 
Andrea Bolognani / Red Hat / Virtualization

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

Patch

diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index a51bdb2453..b2dda3845d 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -590,15 +590,8 @@  testInfoSetPaths(struct testQemuInfo *info, const char *suffix)
 static int
 mymain(void)
 {
-    int ret = 0, i;
+    int ret = 0;
     char *fakerootdir;
-    const char *archs[] = {
-        "aarch64",
-        "ppc64",
-        "riscv64",
-        "s390x",
-        "x86_64",
-    };
     virHashTablePtr capslatest = NULL;
 
     if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
@@ -667,24 +660,10 @@  mymain(void)
     if (VIR_STRDUP(driver.config->nvramDir, "/var/lib/libvirt/qemu/nvram") < 0)
         return EXIT_FAILURE;
 
-    capslatest = virHashCreate(4, virHashValueFree);
+    capslatest = testQemuGetCapsLatest();
     if (!capslatest)
         return EXIT_FAILURE;
 
-    VIR_TEST_VERBOSE("\n");
-
-    for (i = 0; i < ARRAY_CARDINALITY(archs); ++i) {
-        char *cap = testQemuGetLatestCapsForArch(abs_srcdir "/qemucapabilitiesdata",
-                                                 archs[i], "xml");
-
-        if (!cap || virHashAddEntry(capslatest, archs[i], cap) < 0)
-            return EXIT_FAILURE;
-
-        VIR_TEST_VERBOSE("latest caps for %s: %s\n", archs[i], cap);
-    }
-
-    VIR_TEST_VERBOSE("\n");
-
     virFileWrapperAddPrefix(SYSCONFDIR "/qemu/firmware",
                             abs_srcdir "/qemufirmwaredata/etc/qemu/firmware");
     virFileWrapperAddPrefix(PREFIX "/share/qemu/firmware",
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 6286c7b3c7..66464d4101 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -1062,3 +1062,40 @@  testQemuInfoClear(struct testQemuInfo *info)
     VIR_FREE(info->outfile);
     virObjectUnref(info->qemuCaps);
 }
+
+
+virHashTablePtr
+testQemuGetCapsLatest(void)
+{
+    const char *archs[] = {
+        "aarch64",
+        "ppc64",
+        "riscv64",
+        "s390x",
+        "x86_64",
+    };
+    virHashTablePtr capslatest;
+    size_t i;
+
+    if (!(capslatest = virHashCreate(4, virHashValueFree)))
+        goto error;
+
+    VIR_TEST_VERBOSE("\n");
+
+    for (i = 0; i < ARRAY_CARDINALITY(archs); ++i) {
+        char *cap = testQemuGetLatestCapsForArch(abs_srcdir "/qemucapabilitiesdata",
+                                                 archs[i], "xml");
+
+        if (!cap || virHashAddEntry(capslatest, archs[i], cap) < 0)
+            goto error;
+
+        VIR_TEST_VERBOSE("latest caps for %s: %s\n", archs[i], cap);
+    }
+
+    VIR_TEST_VERBOSE("\n");
+    return capslatest;
+
+ error:
+    virHashFree(capslatest);
+    return NULL;
+}
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index f6ae2a38d3..6d4719dc12 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -109,6 +109,7 @@  int testQemuCapsIterate(const char *dirname,
 int testQemuInfoSetArgs(struct testQemuInfo *info,
                         virHashTablePtr capslatest, ...);
 void testQemuInfoClear(struct testQemuInfo *info);
+virHashTablePtr testQemuGetCapsLatest(void);
 
 # endif