[PATCH 3/3] tests: qemumigparams: test for zstd compression

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

 



Here we add one more way to test migration parameters, namely: from vir params.
This allows to test the logic of (libvirt) compression->(qemu) multifd-compression

Signed-off-by: Oleg Vasilev <oleg.vasilev@xxxxxxxxxxxxx>
---
 tests/qemumigparamsdata/zstd.json  |  4 ++
 tests/qemumigparamsdata/zstd.reply |  7 +++
 tests/qemumigparamsdata/zstd.xml   |  6 ++
 tests/qemumigparamstest.c          | 90 +++++++++++++++++++++++++++---
 4 files changed, 100 insertions(+), 7 deletions(-)
 create mode 100644 tests/qemumigparamsdata/zstd.json
 create mode 100644 tests/qemumigparamsdata/zstd.reply
 create mode 100644 tests/qemumigparamsdata/zstd.xml

diff --git a/tests/qemumigparamsdata/zstd.json b/tests/qemumigparamsdata/zstd.json
new file mode 100644
index 0000000000..61e8b7c2f1
--- /dev/null
+++ b/tests/qemumigparamsdata/zstd.json
@@ -0,0 +1,4 @@
+{
+  "multifd-compression": "zstd",
+  "multifd-zstd-level": 3
+}
diff --git a/tests/qemumigparamsdata/zstd.reply b/tests/qemumigparamsdata/zstd.reply
new file mode 100644
index 0000000000..8818bc0b3e
--- /dev/null
+++ b/tests/qemumigparamsdata/zstd.reply
@@ -0,0 +1,7 @@
+{
+  "id": "libvirt-1",
+  "return": {
+    "multifd-compression": "zstd",
+    "multifd-zstd-level": 3
+  }
+}
diff --git a/tests/qemumigparamsdata/zstd.xml b/tests/qemumigparamsdata/zstd.xml
new file mode 100644
index 0000000000..38f11bda90
--- /dev/null
+++ b/tests/qemumigparamsdata/zstd.xml
@@ -0,0 +1,6 @@
+<test>
+  <migParams>
+    <param name='multifd-compression' value='zstd'/>
+    <param name='multifd-zstd-level' value='3'/>
+  </migParams>
+</test>
diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c
index 5d45a9dd58..b0e1ad89a0 100644
--- a/tests/qemumigparamstest.c
+++ b/tests/qemumigparamstest.c
@@ -33,11 +33,20 @@
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
+typedef struct _qemuMigParamsSourceData qemuMigParamsSourceData;
+struct _qemuMigParamsSourceData {
+    virTypedParameterPtr params;
+    int nparams;
+    unsigned long flags;
+    qemuMigrationParty party;
+};
+
 typedef struct _qemuMigParamsData qemuMigParamsData;
 struct _qemuMigParamsData {
     virDomainXMLOption *xmlopt;
     const char *name;
     GHashTable *qmpschema;
+    qemuMigParamsSourceData *src;
 };
 
 
@@ -177,6 +186,50 @@ qemuMigParamsTestJSON(const void *opaque)
     return 0;
 }
 
+static int
+qemuMigParamsTestParams(const void *opaque)
+{
+    const qemuMigParamsData *data = opaque;
+    g_autofree char *jsonFile = NULL;
+    g_autoptr(virJSONValue) paramsOut = NULL;
+    g_autoptr(qemuMigrationParams) migParams = NULL;
+    g_autofree char *actualJSON = NULL;
+    g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
+
+    jsonFile = g_strdup_printf("%s/qemumigparamsdata/%s.json",
+                               abs_srcdir, data->name);
+
+    migParams = qemuMigrationParamsFromFlags(data->src->params,
+                                            data->src->nparams,
+                                            data->src->flags,
+                                            data->src->party);
+    if (!migParams) {
+        VIR_TEST_VERBOSE("can't construct params");
+        return -1;
+    }
+
+    if (!(paramsOut = qemuMigrationParamsToJSON(migParams, false)) ||
+        !(actualJSON = virJSONValueToString(paramsOut, true)))
+        return -1;
+
+    if (testQEMUSchemaValidateCommand("migrate-set-parameters",
+                                      paramsOut,
+                                      data->qmpschema,
+                                      false,
+                                      false,
+                                      false,
+                                      &debug) < 0) {
+        VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
+                         actualJSON, virBufferCurrentContent(&debug));
+        return -1;
+    }
+
+    if (virTestCompareToFile(actualJSON, jsonFile) < 0)
+        return -1;
+
+    return 0;
+}
+
 
 static int
 mymain(void)
@@ -184,6 +237,13 @@ mymain(void)
     g_autoptr(GHashTable) qmpschema = NULL;
     virQEMUDriver driver;
     int ret = 0;
+    qemuMigParamsSourceData src = {
+        .params = NULL,
+        .nparams = 0,
+        .flags = 0,
+        .party = QEMU_MIGRATION_SOURCE,
+    };
+    int maxparams = 0;
 
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
@@ -195,10 +255,10 @@ mymain(void)
         return EXIT_FAILURE;
     }
 
-#define DO_TEST(name) \
+#define DO_TEST(name, src) \
     do { \
         qemuMigParamsData data = { \
-            driver.xmlopt, name, qmpschema \
+            driver.xmlopt, name, qmpschema, src \
         }; \
         if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \
             ret = -1; \
@@ -206,13 +266,29 @@ mymain(void)
             ret = -1; \
         if (virTestRun(name " (xml2xml)", qemuMigParamsTestXML2XML, &data) < 0) \
             ret = -1; \
+        if ((src != NULL) && virTestRun(name " (src)", qemuMigParamsTestParams, &data) < 0) \
+            ret = -1; \
     } while (0)
 
-    DO_TEST("empty");
-    DO_TEST("basic");
-    DO_TEST("tls");
-    DO_TEST("tls-enabled");
-    DO_TEST("tls-hostname");
+    DO_TEST("empty", NULL);
+    DO_TEST("basic", NULL);
+    DO_TEST("tls", NULL);
+    DO_TEST("tls-enabled", NULL);
+    DO_TEST("tls-hostname", NULL);
+
+    src.flags |= VIR_MIGRATE_PARALLEL;
+
+    if (virTypedParamsAddString(&src.params, &src.nparams, &maxparams,
+                            VIR_MIGRATE_PARAM_COMPRESSION, "zstd") < 0 ||
+        virTypedParamsAddInt(&src.params, &src.nparams, &maxparams,
+                             VIR_MIGRATE_PARAM_COMPRESSION_ZSTD_LEVEL, 3) < 0) {
+        ret = -1;
+        goto cleanup;
+    }
+    DO_TEST("zstd", &src);
+
+ cleanup:
+    virTypedParamsFree(src.params, src.nparams);
 
     qemuTestDriverFree(&driver);
 
-- 
2.40.0




[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