]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemumonitortestutils: Enforce consumption of all items in test monitor
authorPeter Krempa <pkrempa@redhat.com>
Thu, 23 Apr 2020 14:57:31 +0000 (16:57 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Apr 2020 06:30:27 +0000 (08:30 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/cputest.c
tests/qemuhotplugtest.c
tests/qemumonitorjsontest.c
tests/qemumonitortestutils.c
tests/qemumonitortestutils.h

index 869d016ffc03dd0906bf6c111c66ad45cf4fe552..21f47a6853068b1508b4083c8b036e7f24bba135 100644 (file)
@@ -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");
index 65867a012296f8b70110bfed68aaa51e7e062b0a..9a215ab303f27d7dd27d7bd7e80f4ba0aab8b690 100644 (file)
@@ -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);
 
index 615bc8c102478f10ae7bf460483b3049c1f61a2a..60c816d1d1499a05a9f0f89768a839b4ea434c97 100644 (file)
@@ -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;
index 74b9cb54546f52ebd85af996fe1f8a900a69a646..4ca29ab061b04f545942999e9f95c3d472836111 100644 (file)
@@ -57,6 +57,8 @@ struct _qemuMonitorTest {
     bool running;
     bool started;
 
+    bool allowUnusedCommands;
+
     char *incoming;
     size_t incomingLength;
     size_t incomingCapacity;
@@ -421,8 +423,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'",
+                      NULLSTR(test->items[i]->identifier));
+        }
+
         qemuMonitorTestItemFree(test->items[i]);
+    }
     VIR_FREE(test->items);
 
     if (test->tmpdir && rmdir(test->tmpdir) < 0)
@@ -430,6 +439,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);
 }
@@ -1288,6 +1302,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,
index 384002d0862267660f613d5320fe5720d1465664..f45e85000044ff7b3846cc27556bba150de44aec 100644 (file)
@@ -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);