[libvirt] [PATCH 11/11] tests: qemumonitorjson: Do some useful testing in the 'simple' tests

Peter Krempa posted 11 patches 7 years, 1 month ago
[libvirt] [PATCH 11/11] tests: qemumonitorjson: Do some useful testing in the 'simple' tests
Posted by Peter Krempa 7 years, 1 month ago
The 'simple' monitor tests were quite useless, since the code did not
even check whether the correct command was called.

This patch uses the QAPI schema validator to validate that the arguments
are in format according to the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tests/qemumonitorjsontest.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index a7fc814d4a..97c4fb0a02 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -42,6 +42,7 @@ struct _testQemuMonitorJSONSimpleFuncData {
     int (* func) (qemuMonitorPtr mon);
     virDomainXMLOptionPtr xmlopt;
     const char *reply;
+    virHashTablePtr schema;
 };

 const char *queryBlockReply =
@@ -1266,7 +1267,7 @@ testQemuMonitorJSONSimpleFunc(const void *opaque)
     testQemuMonitorJSONSimpleFuncDataPtr data =
         (testQemuMonitorJSONSimpleFuncDataPtr) opaque;
     virDomainXMLOptionPtr xmlopt = data->xmlopt;
-    qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+    qemuMonitorTestPtr test = qemuMonitorTestNewSchema(xmlopt, data->schema);
     const char *reply = data->reply;
     int ret = -1;

@@ -2896,6 +2897,13 @@ mymain(void)

     virEventRegisterDefaultImpl();

+    if (!(qapiData.schema = testQEMUSchemaLoad())) {
+        VIR_TEST_VERBOSE("failed to load qapi schema\n");
+        ret = -1;
+        goto cleanup;
+    }
+    simpleFunc.schema = qapiData.schema;
+
 #define DO_TEST(name) \
     if (virTestRun(# name, testQemuMonitorJSON ## name, driver.xmlopt) < 0) \
         ret = -1
@@ -3042,11 +3050,6 @@ mymain(void)
             ret = -1; \
     } while (0)

-    if (!(qapiData.schema = testQEMUSchemaLoad())) {
-        VIR_TEST_VERBOSE("failed to load qapi schema\n");
-        ret = -1;
-        goto cleanup;
-    }

     DO_TEST_QAPI_SCHEMA("string", "trace-event-get-state/arg-type", true,
                         "{\"name\":\"test\"}");
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 11/11] tests: qemumonitorjson: Do some useful testing in the 'simple' tests
Posted by Ján Tomko 7 years, 1 month ago
On Thu, Mar 22, 2018 at 07:31:48PM +0100, Peter Krempa wrote:
>The 'simple' monitor tests were quite useless, since the code did not
>even check whether the correct command was called.
>
>This patch uses the QAPI schema validator to validate that the arguments
>are in format according to the schema.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> tests/qemumonitorjsontest.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>

ACK

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