[libvirt] [PATCH 06/18] qemumonitorjsontest: Test qemuMonitorJSONGetCPUInfo

Michal Privoznik mprivozn at redhat.com
Wed Oct 2 17:09:55 UTC 2013


Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/qemumonitorjsontest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 77 insertions(+)

diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index f52e970..6eb26a1 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -1100,6 +1100,82 @@ GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345)
 GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true)
 GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1")
 
+
+static int
+testQemuMonitorJSONqemuMonitorJSONGetCPUInfo(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+    int ret = -1;
+    pid_t *cpupids = NULL;
+    pid_t expected_cpupids[] = {17622, 17623, 17624, 17625};
+    int ncpupids;
+    size_t i;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddItem(test, "query-cpus",
+                               "{"
+                               "    \"return\": ["
+                               "        {"
+                               "            \"current\": true,"
+                               "            \"CPU\": 0,"
+                               "            \"pc\": -2130530478,"
+                               "            \"halted\": true,"
+                               "            \"thread_id\": 17622"
+                               "        },"
+                               "        {"
+                               "            \"current\": false,"
+                               "            \"CPU\": 1,"
+                               "            \"pc\": -2130530478,"
+                               "            \"halted\": true,"
+                               "            \"thread_id\": 17623"
+                               "        },"
+                               "        {"
+                               "            \"current\": false,"
+                               "            \"CPU\": 2,"
+                               "            \"pc\": -2130530478,"
+                               "            \"halted\": true,"
+                               "            \"thread_id\": 17624"
+                               "        },"
+                               "        {"
+                               "            \"current\": false,"
+                               "            \"CPU\": 3,"
+                               "            \"pc\": -2130530478,"
+                               "            \"halted\": true,"
+                               "            \"thread_id\": 17625"
+                               "        }"
+                               "    ],"
+                               "    \"id\": \"libvirt-7\""
+                               "}") < 0)
+        goto cleanup;
+
+    ncpupids = qemuMonitorJSONGetCPUInfo(qemuMonitorTestGetMonitor(test), &cpupids);
+
+    if (ncpupids != 4) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Expecting ncpupids = 4 but got %d", ncpupids);
+        goto cleanup;
+    }
+
+    for (i = 0; i < ncpupids; i++) {
+        if (cpupids[i] != expected_cpupids[i]) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "Expecting cpupids[%zu] = %d but got %d",
+                           i, expected_cpupids[i], cpupids[i]);
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+cleanup:
+    VIR_FREE(cpupids);
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
 static int
 mymain(void)
 {
@@ -1183,6 +1259,7 @@ mymain(void)
     DO_TEST_GEN(qemuMonitorJSONNBDServerStart);
     DO_TEST_GEN(qemuMonitorJSONNBDServerAdd);
     DO_TEST_GEN(qemuMonitorJSONDetachCharDev);
+    DO_TEST(qemuMonitorJSONGetCPUInfo);
 
     virObjectUnref(xmlopt);
 
-- 
1.8.1.5




More information about the libvir-list mailing list