[libvirt] [PATCH v2 1/3] qemuhotplugtest: Allow testing of live data

Martin Kletzander mkletzan at redhat.com
Thu Apr 28 14:43:40 UTC 2016


For now, the test was dumping an XML of inactive domain (well, setting
the id to '-1' to be precise) when checking the results.  This patch
enables future additions to test the live XML output as well.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 tests/qemuhotplugtest.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index ea6dc361183a..924114668450 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -52,6 +52,7 @@ struct qemuHotplugTestData {
     bool keep;
     virDomainObjPtr vm;
     bool deviceDeletedEvent;
+    bool live;
 };

 static int
@@ -176,12 +177,13 @@ static int
 testQemuHotplugCheckResult(virDomainObjPtr vm,
                            const char *expected,
                            const char *expectedFile,
-                           bool fail)
+                           bool fail, bool live)
 {
     char *actual;
     int ret;

-    vm->def->id = -1;
+    if (!live)
+        vm->def->id = -1;
     actual = virDomainDefFormat(vm->def, driver.caps,
                                 VIR_DOMAIN_DEF_FORMAT_SECURE);
     if (!actual)
@@ -218,6 +220,7 @@ testQemuHotplug(const void *data)
     const char *const *tmp;
     bool fail = test->fail;
     bool keep = test->keep;
+    bool live = test->live;
     unsigned int device_parse_flags = 0;
     virDomainObjPtr vm = NULL;
     virDomainDeviceDefPtr dev = NULL;
@@ -299,14 +302,14 @@ testQemuHotplug(const void *data)
         }
         if (ret == 0 || fail)
             ret = testQemuHotplugCheckResult(vm, result_xml,
-                                             result_filename, fail);
+                                             result_filename, fail, live);
         break;

     case DETACH:
         ret = testQemuHotplugDetach(vm, dev);
         if (ret == 0 || fail)
             ret = testQemuHotplugCheckResult(vm, domain_xml,
-                                             domain_filename, fail);
+                                             domain_filename, fail, live);
         break;

     case UPDATE:
@@ -370,7 +373,7 @@ mymain(void)
     /* wait only 100ms for DEVICE_DELETED event */
     qemuDomainRemoveDeviceWaitTime = 100;

-#define DO_TEST(file, ACTION, dev, event, fial, kep, ...)                   \
+#define DO_TEST(file, ACTION, dev, event, fial, kep, liv, ...)              \
     do {                                                                    \
         const char *my_mon[] = { __VA_ARGS__, NULL};                        \
         const char *name = file " " #ACTION " " dev;                        \
@@ -380,25 +383,29 @@ mymain(void)
         data.fail = fial;                                                   \
         data.mon = my_mon;                                                  \
         data.keep = kep;                                                    \
+        data.live = liv;                                                    \
         data.deviceDeletedEvent = event;                                    \
         if (virtTestRun(name, testQemuHotplug, &data) < 0)                  \
             ret = -1;                                                       \
     } while (0)

 #define DO_TEST_ATTACH(file, dev, fial, kep, ...)                           \
-    DO_TEST(file, ATTACH, dev, false, fial, kep, __VA_ARGS__)
+    DO_TEST(file, ATTACH, dev, false, fial, kep, false, __VA_ARGS__)
+
+#define DO_TEST_ATTACH_LIVE(file, dev, fial, kep, ...)                      \
+    DO_TEST(file, ATTACH, dev, false, fial, kep, true, __VA_ARGS__)

 #define DO_TEST_DETACH(file, dev, fial, kep, ...)                           \
-    DO_TEST(file, DETACH, dev, false, fial, kep, __VA_ARGS__)
+    DO_TEST(file, DETACH, dev, false, fial, kep, false, __VA_ARGS__)

 #define DO_TEST_ATTACH_EVENT(file, dev, fial, kep, ...)                     \
-    DO_TEST(file, ATTACH, dev, true, fial, kep, __VA_ARGS__)
+    DO_TEST(file, ATTACH, dev, true, fial, kep, false, __VA_ARGS__)

 #define DO_TEST_DETACH_EVENT(file, dev, fial, kep, ...)                     \
-    DO_TEST(file, DETACH, dev, true, fial, kep, __VA_ARGS__)
+    DO_TEST(file, DETACH, dev, true, fial, kep, false, __VA_ARGS__)

 #define DO_TEST_UPDATE(file, dev, fial, kep, ...)                           \
-    DO_TEST(file, UPDATE, dev, false, fial, kep, __VA_ARGS__)
+    DO_TEST(file, UPDATE, dev, false, fial, kep, false, __VA_ARGS__)


 #define QMP_OK      "{\"return\": {}}"
-- 
2.8.1




More information about the libvir-list mailing list