[PATCH 8/8] qemumonitortestutils: Enforce consumption of all items in test monitor

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

 



To prevent unexpected situations where a change in code would stop
looking at some of the tested commands go unnoticed add a mechanism to
force consumption of all test items.

Since there are a few tests which would be hard to fix add also a
mechanism to opt-out of the check.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/cputest.c              |  2 ++
 tests/qemuhotplugtest.c      |  2 ++
 tests/qemumonitorjsontest.c  |  2 ++
 tests/qemumonitortestutils.c | 31 ++++++++++++++++++++++++++++++-
 tests/qemumonitortestutils.h |  2 ++
 5 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/tests/cputest.c b/tests/cputest.c
index 869d016ffc..21f47a6853 100644
--- a/tests/cputest.c
+++ b/tests/cputest.c
@@ -482,6 +482,8 @@ cpuTestMakeQEMUCaps(const struct data *data)
     if (!(testMon = qemuMonitorTestNewFromFile(json, driver.xmlopt, true)))
         goto error;

+    qemuMonitorTestAllowUnusedCommands(testMon);
+
     cpu = virCPUDefNew();

     cpu->model = g_strdup("host");
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 65867a0122..9a215ab303 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -453,6 +453,8 @@ testQemuHotplugCpuPrepare(const char *test,
                                                      &driver, data->vm, qmpschema)))
         goto error;

+    qemuMonitorTestAllowUnusedCommands(data->mon);
+
     priv->mon = qemuMonitorTestGetMonitor(data->mon);
     virObjectUnlock(priv->mon);

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index 615bc8c102..60c816d1d1 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -796,6 +796,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionPtr xmlopt,
     if (!(data.test = qemuMonitorTestNewSchema(xmlopt, schema)))
         goto cleanup;

+    qemuMonitorTestAllowUnusedCommands(data.test);
+
     if (qemuMonitorTestAddItemExpect(data.test, "chardev-add",
                                      expectargs, true, jsonreply) < 0)
         goto cleanup;
diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 1af56c6d87..0b6188b4ca 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -57,6 +57,8 @@ struct _qemuMonitorTest {
     bool running;
     bool started;

+    bool allowUnusedCommands;
+
     char *incoming;
     size_t incomingLength;
     size_t incomingCapacity;
@@ -423,8 +425,15 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
     VIR_FREE(test->incoming);
     VIR_FREE(test->outgoing);

-    for (i = 0; i < test->nitems; i++)
+    for (i = 0; i < test->nitems; i++) {
+        if (!test->allowUnusedCommands) {
+            g_fprintf(stderr,
+                      "\nunused test monitor item '%s'\n",
+                      NULLSTR(test->items[i]->identifier));
+        }
+
         qemuMonitorTestItemFree(test->items[i]);
+    }
     VIR_FREE(test->items);

     if (test->tmpdir && rmdir(test->tmpdir) < 0)
@@ -432,6 +441,11 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)

     VIR_FREE(test->tmpdir);

+    if (!test->allowUnusedCommands &&
+        test->nitems != 0) {
+        qemuMonitorTestError("unused test monitor items are not allowed for this test\n");
+    }
+
     virMutexDestroy(&test->lock);
     VIR_FREE(test);
 }
@@ -1290,6 +1304,21 @@ qemuMonitorTestNewFromFile(const char *fileName,
 }


+/**
+ * qemuMonitorTestAllowUnusedCommands:
+ * @test: test monitor object
+ *
+ * By default all test items/commands must be used by the test. This function
+ * allows to override the requirement for individual tests e.g. if it's necessary
+ * to test some negative scenarios which would not use all commands.
+ */
+void
+qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test)
+{
+    test->allowUnusedCommands = true;
+}
+
+
 static int
 qemuMonitorTestFullAddItem(qemuMonitorTestPtr test,
                            const char *filename,
diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h
index 384002d086..f45e850000 100644
--- a/tests/qemumonitortestutils.h
+++ b/tests/qemumonitortestutils.h
@@ -50,6 +50,8 @@ void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestItemPtr item);

 int qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, const char *errmsg, ...);

+void qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test);
+
 int qemuMonitorTestAddItem(qemuMonitorTestPtr test,
                            const char *command_name,
                            const char *response);
-- 
2.26.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