]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemumonitorjsontest: Test qemuMonitorJSONGetPtyPaths
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 2 Oct 2013 15:11:30 +0000 (17:11 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 3 Oct 2013 09:31:17 +0000 (11:31 +0200)
tests/qemumonitorjsontest.c

index d93cc5246b0999c1866300ac42ba252bc983ffe9..6ff521d72b6042cf4226532bb69bb971e6b2e9fd 100644 (file)
@@ -1550,6 +1550,72 @@ cleanup:
     return ret;
 }
 
+static int
+testHashEqualString(const void *value1, const void *value2)
+{
+    return strcmp(value1, value2);
+}
+
+static int
+testQemuMonitorJSONqemuMonitorJSONGetPtyPaths(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewSimple(true, xmlopt);
+    int ret = -1;
+    virHashTablePtr paths = NULL, expectedPaths = NULL;
+
+    if (!test)
+        return -1;
+
+    if (!(paths = virHashCreate(32, (virHashDataFree) free)) ||
+        !(expectedPaths = virHashCreate(32, NULL)))
+        goto cleanup;
+
+    if (virHashAddEntry(expectedPaths, "charserial1", (void *) "/dev/pts/21") < 0 ||
+        virHashAddEntry(expectedPaths, "charserial0", (void *) "/dev/pts/20") < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Unable to create expectedPaths hash table");
+        goto cleanup;
+    }
+
+    if (qemuMonitorTestAddItem(test, "query-chardev",
+                               "{"
+                               "    \"return\": ["
+                               "        {"
+                               "            \"filename\": \"pty:/dev/pts/21\","
+                               "            \"label\": \"charserial1\""
+                               "        },"
+                               "        {"
+                               "            \"filename\": \"pty:/dev/pts/20\","
+                               "            \"label\": \"charserial0\""
+                               "        },"
+                               "        {"
+                               "            \"filename\": \"unix:/var/lib/libvirt/qemu/gentoo.monitor,server\","
+                               "            \"label\": \"charmonitor\""
+                               "        }"
+                               "    ],"
+                               "    \"id\": \"libvirt-15\""
+                               "}") < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONGetPtyPaths(qemuMonitorTestGetMonitor(test),
+                                   paths) < 0)
+        goto cleanup;
+
+    if (!virHashEqual(paths, expectedPaths, testHashEqualString)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Hashtable is different to the expected one");
+        goto cleanup;
+    }
+
+    ret = 0;
+cleanup:
+    virHashFree(paths);
+    virHashFree(expectedPaths);
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
 static int
 mymain(void)
 {
@@ -1605,6 +1671,7 @@ mymain(void)
     DO_TEST(qemuMonitorJSONGetMigrationCacheSize);
     DO_TEST(qemuMonitorJSONGetMigrationStatus);
     DO_TEST(qemuMonitorJSONGetSpiceMigrationStatus);
+    DO_TEST(qemuMonitorJSONGetPtyPaths);
 
     virObjectUnref(xmlopt);