diff mbox series

[2/6] tests: qemuxml2xml: Add basic DO_TEST_CAPS impl

Message ID 0cfd161706183af03ce62bd43b8c4ed062661031.1547420060.git.crobinso@redhat.com
State New
Headers show
Series RFC: qemu: virtio-{non-}transitional support | expand

Commit Message

Cole Robinson Jan. 13, 2019, 11:12 p.m. UTC
Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 tests/qemuxml2xmltest.c | 57 ++++++++++++++++++++++++++++++-----------
 1 file changed, 42 insertions(+), 15 deletions(-)

-- 
2.20.1

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

Comments

Andrea Bolognani Jan. 15, 2019, 4:38 p.m. UTC | #1
On Sun, 2019-01-13 at 18:12 -0500, Cole Robinson wrote:
[...]
> +# define DO_TEST_CAPS(name, arch, ver) \


This is called DO_TEST_CAPS_ARCH_VER() in xml2argv, and we shouldn't
deviate from that unless we have a very compelling reason to do so.

Ideally, you'd implement DO_TEST_CAPS_LATEST() instead, by lifting
all common bits from xml2argv and moving them into testutilsqemu,
but I understand if you don't want to spend your time doing that.

> +    do { \

> +        if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(arch), \

> +                                                       TEST_CAPS_PATH ver "." arch ".xml"))) { \

> +            printf("bad\n"); \


Bad leftover code, bad! :P


Looks reasonable otherwise, at least from a quick look.

-- 
Andrea Bolognani / Red Hat / Virtualization

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

Patch

diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 82e2c0ee0f..b686a585e8 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -117,10 +117,10 @@  testInfoClear(struct testInfo *info)
 
 static int
 testInfoSetCommon(struct testInfo *info,
-                  int gic)
+                  int gic,
+                  virQEMUCapsPtr qemuCaps)
 {
-    if (!(info->qemuCaps = virQEMUCapsNew()))
-        goto error;
+    info->qemuCaps = qemuCaps;
 
     if (testQemuCapsSetGIC(info->qemuCaps, gic) < 0)
         goto error;
@@ -140,9 +140,10 @@  static int
 testInfoSet(struct testInfo *info,
             const char *name,
             int when,
-            int gic)
+            int gic,
+            virQEMUCapsPtr qemuCaps)
 {
-    if (testInfoSetCommon(info, gic) < 0)
+    if (testInfoSetCommon(info, gic, qemuCaps) < 0)
         return -1;
 
     if (virAsprintf(&info->inName, "%s/qemuxml2argvdata/%s.xml",
@@ -194,9 +195,10 @@  static const char *statusPath = abs_srcdir "/qemustatusxml2xmldata/";
 static int
 testInfoSetStatus(struct testInfo *info,
                   const char *name,
-                  int gic)
+                  int gic,
+                  virQEMUCapsPtr qemuCaps)
 {
-    if (testInfoSetCommon(info, gic) < 0)
+    if (testInfoSetCommon(info, gic, qemuCaps) < 0)
         return -1;
 
     if (virAsprintf(&info->inName, "%s%s-in.xml", statusPath, name) < 0 ||
@@ -220,6 +222,7 @@  mymain(void)
     char *fakerootdir;
     struct testInfo info;
     virQEMUDriverConfigPtr cfg = NULL;
+    virQEMUCapsPtr qemuCaps = NULL;
 
     if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
         fprintf(stderr, "Out of memory\n");
@@ -240,14 +243,8 @@  mymain(void)
 
     cfg = virQEMUDriverGetConfig(&driver);
 
-# define DO_TEST_FULL(name, when, gic, ...) \
+# define DO_TEST_RUN(name, info) \
     do { \
-        if (testInfoSet(&info, name, when, gic) < 0) { \
-            VIR_TEST_DEBUG("Failed to generate test data for '%s'", name); \
-            return -1; \
-        } \
-        virQEMUCapsSetList(info.qemuCaps, __VA_ARGS__, QEMU_CAPS_LAST); \
- \
         if (info.outInactiveName) { \
             if (virTestRun("QEMU XML-2-XML-inactive " name, \
                             testXML2XMLInactive, &info) < 0) \
@@ -262,6 +259,34 @@  mymain(void)
         testInfoClear(&info); \
     } while (0)
 
+# define DO_TEST_FULL(name, when, gic, ...) \
+    do { \
+        if (!(qemuCaps = virQEMUCapsNew())) \
+            return -1; \
+        if (testInfoSet(&info, name, when, gic, qemuCaps) < 0) { \
+            VIR_TEST_DEBUG("Failed to generate test data for '%s'", name); \
+            return -1; \
+        } \
+        virQEMUCapsSetList(info.qemuCaps, __VA_ARGS__, QEMU_CAPS_LAST); \
+        DO_TEST_RUN(name, info); \
+    } while (0)
+
+# define TEST_CAPS_PATH abs_srcdir "/qemucapabilitiesdata/caps_"
+
+# define DO_TEST_CAPS(name, arch, ver) \
+    do { \
+        if (!(qemuCaps = qemuTestParseCapabilitiesArch(virArchFromString(arch), \
+                                                       TEST_CAPS_PATH ver "." arch ".xml"))) { \
+            printf("bad\n"); \
+            return -1; \
+        } \
+        if (testInfoSet(&info, name, WHEN_BOTH, GIC_NONE, qemuCaps) < 0) { \
+            VIR_TEST_DEBUG("Failed to generate test data for '%s'", name); \
+            return -1; \
+        } \
+        DO_TEST_RUN(name, info); \
+    } while (0)
+
 # define NONE QEMU_CAPS_LAST
 
 # define DO_TEST(name, ...) \
@@ -1233,7 +1258,9 @@  mymain(void)
 
 # define DO_TEST_STATUS(name) \
     do { \
-        if (testInfoSetStatus(&info, name, GIC_NONE) < 0) { \
+        if (!(qemuCaps = virQEMUCapsNew())) \
+            return -1; \
+        if (testInfoSetStatus(&info, name, GIC_NONE, qemuCaps) < 0) { \
             VIR_TEST_DEBUG("Failed to generate status test data for '%s'", name); \
             return -1; \
         } \