[libvirt] [PATCH 19/20] qemuagenttest: Test arbitrary qemu commands and timeouting of commands

Peter Krempa pkrempa at redhat.com
Tue Jul 30 13:05:54 UTC 2013


Test arbitrary qemu commands and timeouting of the guest agent
synchronisation.
---
 tests/qemuagenttest.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 101 insertions(+)

diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index e314bb0..81c24f2 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -326,6 +326,105 @@ cleanup:


 static int
+qemuAgentTimeoutTestMonitorHandler(qemuMonitorTestPtr test ATTRIBUTE_UNUSED,
+                                   qemuMonitorTestItemPtr item ATTRIBUTE_UNUSED,
+                                   const char *cmdstr ATTRIBUTE_UNUSED)
+{
+    return 0;
+}
+
+static const char testQemuAgentArbitraryCommandResponse[] =
+    "{\"return\":\"bla\"}";
+
+static int
+testQemuAgentArbitraryCommand(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+    int ret = -1;
+    char *reply = NULL;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "ble",
+                               testQemuAgentArbitraryCommandResponse) < 0)
+        goto cleanup;
+
+    if (qemuAgentArbitraryCommand(qemuMonitorTestGetAgent(test),
+                                  "{\"execute\":\"ble\"}",
+                                  &reply,
+                                  VIR_DOMAIN_QEMU_AGENT_COMMAND_BLOCK) < 0)
+        goto cleanup;
+
+    if (STRNEQ(reply, testQemuAgentArbitraryCommandResponse)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "invalid processing of guest agent reply: "
+                       "got '%s' expected '%s'",
+                       reply, testQemuAgentArbitraryCommandResponse);
+        goto cleanup;
+    }
+
+    VIR_FREE(reply);
+
+    /* test timeout */
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
+                                  NULL, NULL) < 0)
+        goto cleanup;
+
+    if (qemuAgentArbitraryCommand(qemuMonitorTestGetAgent(test),
+                                  "{\"execute\":\"ble\"}",
+                                  &reply,
+                                  1) != -2) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "agent command didn't time out");
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(reply);
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+
+static int
+testQemuAgentTimeout(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+    int ret = -1;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddHandler(test, qemuAgentTimeoutTestMonitorHandler,
+                                  NULL, NULL) < 0)
+        goto cleanup;
+
+    if (qemuAgentFSFreeze(qemuMonitorTestGetAgent(test)) != -1) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "agent command should have failed");
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+
+static int
 mymain(void)
 {
     int ret = 0;
@@ -351,6 +450,8 @@ mymain(void)
     DO_TEST(FSTrim);
     DO_TEST(Suspend);
     DO_TEST(Shutdown);
+    DO_TEST(ArbitraryCommand);
+    DO_TEST(Timeout);

     virObjectUnref(xmlopt);

-- 
1.8.3.2




More information about the libvir-list mailing list