[PATCH] qemumigparamstest: Validate output parameters against QMP schema

Peter Krempa posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/e8aaedd3be21fb10b263b19d5fa2cae07d267ef6.1598269381.git.pkrempa@redhat.com
tests/qemumigparamstest.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
[PATCH] qemumigparamstest: Validate output parameters against QMP schema
Posted by Peter Krempa 3 years, 7 months ago
Ensure that the migration parameters are formatted properly according to
the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemumigparamstest.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c
index 0f7809d763..c4fd575401 100644
--- a/tests/qemumigparamstest.c
+++ b/tests/qemumigparamstest.c
@@ -22,8 +22,10 @@
 #include "virjson.h"
 #include "virbuffer.h"
 #include "virxml.h"
+#include "virhash.h"
 #include "testutils.h"
 #include "testutilsqemu.h"
+#include "tests/testutilsqemuschema.h"
 #include "qemumonitortestutils.h"
 #include "qemu/qemu_migration_params.h"
 #define LIBVIRT_QEMU_MIGRATION_PARAMSPRIV_H_ALLOW
@@ -36,6 +38,7 @@ typedef struct _qemuMigParamsData qemuMigParamsData;
 struct _qemuMigParamsData {
     virDomainXMLOptionPtr xmlopt;
     const char *name;
+    virHashTablePtr qmpschema;
 };


@@ -141,6 +144,7 @@ qemuMigParamsTestJSON(const void *opaque)
     g_autoptr(virJSONValue) paramsOut = NULL;
     g_autoptr(qemuMigrationParams) migParams = NULL;
     g_autofree char *actualJSON = NULL;
+    g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
     int ret = -1;

     replyFile = g_strdup_printf("%s/qemumigparamsdata/%s.reply",
@@ -162,6 +166,17 @@ qemuMigParamsTestJSON(const void *opaque)
         !(actualJSON = virJSONValueToString(paramsOut, true)))
         goto cleanup;

+    if (testQEMUSchemaValidateCommand("migrate-set-parameters",
+                                      paramsOut,
+                                      data->qmpschema,
+                                      false,
+                                      false,
+                                      &debug) < 0) {
+        VIR_TEST_VERBOSE("failed to validate migration params '%s' against QMP schema: %s",
+                         actualJSON, virBufferCurrentContent(&debug));
+        goto cleanup;
+    }
+
     if (virTestCompareToFile(actualJSON, jsonFile) < 0)
         goto cleanup;

@@ -176,6 +191,7 @@ qemuMigParamsTestJSON(const void *opaque)
 static int
 mymain(void)
 {
+    g_autoptr(virHashTable) qmpschema = NULL;
     virQEMUDriver driver;
     int ret = 0;

@@ -184,10 +200,15 @@ mymain(void)

     virEventRegisterDefaultImpl();

+    if (!(qmpschema = testQEMUSchemaLoadLatest("x86_64"))) {
+        VIR_TEST_VERBOSE("failed to load QMP schema");
+        return EXIT_FAILURE;
+    }
+
 #define DO_TEST(name) \
     do { \
         qemuMigParamsData data = { \
-            driver.xmlopt, name \
+            driver.xmlopt, name, qmpschema \
         }; \
         if (virTestRun(name " (xml)", qemuMigParamsTestXML, &data) < 0) \
             ret = -1; \
-- 
2.26.2

Re: [PATCH] qemumigparamstest: Validate output parameters against QMP schema
Posted by Michal Privoznik 3 years, 7 months ago
On 8/24/20 1:43 PM, Peter Krempa wrote:
> Ensure that the migration parameters are formatted properly according to
> the schema.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>   tests/qemumigparamstest.c | 23 ++++++++++++++++++++++-
>   1 file changed, 22 insertions(+), 1 deletion(-)

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>

Michal