]> xenbits.xensource.com Git - people/dariof/libvirt.git/commitdiff
qemuagenttest: Add tests for CPU plug functions and helpers
authorPeter Krempa <pkrempa@redhat.com>
Tue, 30 Jul 2013 12:09:16 +0000 (14:09 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 31 Jul 2013 12:45:46 +0000 (14:45 +0200)
tests/qemuagenttest.c

index e314bb0997e42400f8af7ce4a77dad4d210d1696..cabd5b7ca0c622275f63743c7a8c068cc4243c75 100644 (file)
@@ -325,6 +325,125 @@ cleanup:
 }
 
 
+static const char testQemuAgentCPUResponse[] =
+    "{\"return\": "
+    "   ["
+    "       {\"online\": true,"
+    "        \"can-offline\": false,"
+    "        \"logical-id\": 0"
+    "       },"
+    "       {\"online\": true,"
+    "        \"can-offline\": true,"
+    "        \"logical-id\": 1"
+    "       },"
+    "       {\"online\": true,"
+    "        \"can-offline\": true,"
+    "        \"logical-id\": 2"
+    "        },"
+    "       {\"online\": false,"
+    "        \"can-offline\": true,"
+    "        \"logical-id\": 3"
+    "       }"
+    "   ]"
+    "}";
+
+static const char testQemuAgentCPUArguments1[] =
+    "[{\"logical-id\":0,\"online\":true},"
+     "{\"logical-id\":1,\"online\":false},"
+     "{\"logical-id\":2,\"online\":true},"
+     "{\"logical-id\":3,\"online\":false}]";
+
+static const char testQemuAgentCPUArguments2[] =
+    "[{\"logical-id\":0,\"online\":true},"
+     "{\"logical-id\":1,\"online\":true},"
+     "{\"logical-id\":2,\"online\":true},"
+     "{\"logical-id\":3,\"online\":true}]";
+
+static int
+testQemuAgentCPU(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+    qemuAgentCPUInfoPtr cpuinfo = NULL;
+    int nvcpus;
+    int ret = -1;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "guest-get-vcpus",
+                               testQemuAgentCPUResponse) < 0)
+        goto cleanup;
+
+    /* get cpus */
+    if ((nvcpus = qemuAgentGetVCPUs(qemuMonitorTestGetAgent(test),
+                                    &cpuinfo)) < 0)
+        goto cleanup;
+
+    if (nvcpus != 4) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Expected '4' cpus, got '%d'", nvcpus);
+        goto cleanup;
+    }
+
+    /* try to unplug one */
+    if (qemuAgentUpdateCPUInfo(2, cpuinfo, nvcpus) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus",
+                                     "{ \"return\" : 4 }",
+                                     "vcpus", testQemuAgentCPUArguments1,
+                                     NULL) < 0)
+        goto cleanup;
+
+    if ((nvcpus = qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test),
+                                    cpuinfo, nvcpus)) < 0)
+        goto cleanup;
+
+    if (nvcpus != 4) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Expected '4' cpus updated , got '%d'", nvcpus);
+        goto cleanup;
+    }
+
+    /* try to hotplug two */
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItemParams(test, "guest-set-vcpus",
+                                     "{ \"return\" : 4 }",
+                                     "vcpus", testQemuAgentCPUArguments2,
+                                     NULL) < 0)
+        goto cleanup;
+
+    if (qemuAgentUpdateCPUInfo(4, cpuinfo, nvcpus) < 0)
+        goto cleanup;
+
+    if ((nvcpus = qemuAgentSetVCPUs(qemuMonitorTestGetAgent(test),
+                                    cpuinfo, nvcpus)) < 0)
+        goto cleanup;
+
+    if (nvcpus != 4) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Expected '4' cpus updated , got '%d'", nvcpus);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(cpuinfo);
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+
 static int
 mymain(void)
 {
@@ -351,6 +470,7 @@ mymain(void)
     DO_TEST(FSTrim);
     DO_TEST(Suspend);
     DO_TEST(Shutdown);
+    DO_TEST(CPU);
 
     virObjectUnref(xmlopt);