]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemumonitortestutils: Store a string identifying test monitor entry
authorPeter Krempa <pkrempa@redhat.com>
Thu, 23 Apr 2020 14:52:12 +0000 (16:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Apr 2020 06:13:52 +0000 (08:13 +0200)
For each test monitor entry store an optional string which will allow to
identify it. This will be used later when checking that all registered
monitor commands were used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/qemuagenttest.c
tests/qemumonitortestutils.c
tests/qemumonitortestutils.h

index 943251df77e0a0fd9e42cdac4283d19928625a5a..2c3a1efb09935a0ba9d2ff3ceb15fc1fbd926f46 100644 (file)
@@ -471,7 +471,8 @@ testQemuAgentShutdown(const void *data)
     priv.event = QEMU_AGENT_EVENT_SHUTDOWN;
     priv.mode = "halt";
 
-    if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
+    if (qemuMonitorTestAddHandler(test, "guest-shutdown",
+                                  qemuAgentShutdownTestMonitorHandler,
                                   &priv, NULL) < 0)
         goto cleanup;
 
@@ -485,7 +486,8 @@ testQemuAgentShutdown(const void *data)
     priv.event = QEMU_AGENT_EVENT_SHUTDOWN;
     priv.mode = "powerdown";
 
-    if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
+    if (qemuMonitorTestAddHandler(test, "guest-shutdown",
+                                  qemuAgentShutdownTestMonitorHandler,
                                   &priv, NULL) < 0)
         goto cleanup;
 
@@ -499,7 +501,9 @@ testQemuAgentShutdown(const void *data)
     priv.event = QEMU_AGENT_EVENT_RESET;
     priv.mode = "reboot";
 
-    if (qemuMonitorTestAddHandler(test, qemuAgentShutdownTestMonitorHandler,
+    if (qemuMonitorTestAddHandler(test,
+                                  "guest-shutdown",
+                                  qemuAgentShutdownTestMonitorHandler,
                                   &priv, NULL) < 0)
         goto cleanup;
 
@@ -720,7 +724,8 @@ testQemuAgentTimeout(const void *data)
         goto cleanup;
     }
 
-    if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
+    if (qemuMonitorTestAddHandler(test, NULL,
+                                  qemuAgentTimeoutTestMonitorHandler,
                                   NULL, NULL) < 0)
         goto cleanup;
 
@@ -734,7 +739,9 @@ testQemuAgentTimeout(const void *data)
     if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
         goto cleanup;
 
-    if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
+    if (qemuMonitorTestAddHandler(test,
+                                  NULL,
+                                  qemuAgentTimeoutTestMonitorHandler,
                                   NULL, NULL) < 0)
         goto cleanup;
 
index 3f827452fc0f72742ccbb878a5c86f9985b6fbd0..74b9cb54546f52ebd85af996fe1f8a900a69a646 100644 (file)
@@ -43,6 +43,7 @@
 VIR_LOG_INIT("tests.qemumonitortestutils");
 
 struct _qemuMonitorTestItem {
+    char *identifier;
     qemuMonitorTestResponseCallback cb;
     void *opaque;
     virFreeCallback freecb;
@@ -88,6 +89,8 @@ qemuMonitorTestItemFree(qemuMonitorTestItemPtr item)
     if (!item)
         return;
 
+    g_free(item->identifier);
+
     if (item->freecb)
         (item->freecb)(item->opaque);
 
@@ -434,6 +437,7 @@ qemuMonitorTestFree(qemuMonitorTestPtr test)
 
 int
 qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
+                          const char *identifier,
                           qemuMonitorTestResponseCallback cb,
                           void *opaque,
                           virFreeCallback freecb)
@@ -443,6 +447,7 @@ qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
     if (VIR_ALLOC(item) < 0)
         goto error;
 
+    item->identifier = g_strdup(identifier);
     item->cb = cb;
     item->freecb = freecb;
     item->opaque = opaque;
@@ -615,6 +620,7 @@ qemuMonitorTestAddItem(qemuMonitorTestPtr test,
     data->response = g_strdup(response);
 
     return qemuMonitorTestAddHandler(test,
+                                     command_name,
                                      qemuMonitorTestProcessCommandDefault,
                                      data, qemuMonitorTestHandlerDataFree);
 }
@@ -698,6 +704,7 @@ qemuMonitorTestAddItemVerbatim(qemuMonitorTestPtr test,
         goto error;
 
     return qemuMonitorTestAddHandler(test,
+                                     command,
                                      qemuMonitorTestProcessCommandVerbatim,
                                      data, qemuMonitorTestHandlerDataFree);
 
@@ -764,6 +771,7 @@ qemuMonitorTestAddAgentSyncResponse(qemuMonitorTestPtr test)
     }
 
     return qemuMonitorTestAddHandler(test,
+                                     "agent-sync",
                                      qemuMonitorTestProcessGuestAgentSync,
                                      NULL, NULL);
 }
@@ -882,6 +890,7 @@ qemuMonitorTestAddItemParams(qemuMonitorTestPtr test,
     va_end(args);
 
     return qemuMonitorTestAddHandler(test,
+                                     cmdname,
                                      qemuMonitorTestProcessCommandWithArgs,
                                      data, qemuMonitorTestHandlerDataFree);
 
@@ -986,6 +995,7 @@ qemuMonitorTestAddItemExpect(qemuMonitorTestPtr test,
     }
 
     return qemuMonitorTestAddHandler(test,
+                                     cmdname,
                                      qemuMonitorTestProcessCommandWithArgStr,
                                      data, qemuMonitorTestHandlerDataFree);
 
index c693b626fc446940fe4daf1f19f56e8a59d0bcea..384002d0862267660f613d5320fe5720d1465664 100644 (file)
@@ -34,6 +34,7 @@ typedef int (*qemuMonitorTestResponseCallback)(qemuMonitorTestPtr test,
                                                const char *message);
 
 int qemuMonitorTestAddHandler(qemuMonitorTestPtr test,
+                              const char *identifier,
                               qemuMonitorTestResponseCallback cb,
                               void *opaque,
                               virFreeCallback freecb);