[PATCH 3/5] Introduce a test suite for the JSON monitor

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Take advantage of the previously added monitor helpers to
create a test suite for the QEMU JSON monitor impl. As a
proof of concept, this tests the 'qemuMonitorGetStatus'
implementation
---
 .gitignore                  |   1 +
 tests/Makefile.am           |  11 +++-
 tests/qemumonitorjsontest.c | 150 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 161 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemumonitorjsontest.c

diff --git a/.gitignore b/.gitignore
index 17dcae4..661509e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -140,6 +140,7 @@
 /tests/openvzutilstest
 /tests/qemuargv2xmltest
 /tests/qemuhelptest
+/tests/qemumonitorjsontest
 /tests/qemumonitortest
 /tests/qemuxmlnstest
 /tests/qparamtest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 22a7a26..884bb7d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -109,7 +109,7 @@ endif
 if WITH_QEMU
 test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
 	qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
-	qemumonitortest
+	qemumonitortest qemumonitorjsontest
 endif
 
 if WITH_LXC
@@ -346,6 +346,14 @@ qemuhelptest_LDADD = $(qemu_LDADDS)
 qemumonitortest_SOURCES = qemumonitortest.c testutils.c testutils.h
 qemumonitortest_LDADD = $(qemu_LDADDS)
 
+qemumonitorjsontest_SOURCES = \
+	qemumonitorjsontest.c \
+	testutils.c testutils.h \
+	testutilsqemu.c testutilsqemu.h \
+	$(NULL)
+qemumonitorjsontest_LDADD = $(qemu_LDADDS) libqemumonitortestutils.la
+qemumonitorjsontest_CFLAGS = -Dabs_builddir="\"$(abs_builddir)\""  $(AM_CFLAGS)
+
 domainsnapshotxml2xmltest_SOURCES = \
 	domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \
 	testutils.c testutils.h
@@ -354,6 +362,7 @@ else
 EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
 	qemuxmlnstest.c qemuhelptest.c domainsnapshotxml2xmltest.c \
 	qemumonitortest.c testutilsqemu.c testutilsqemu.h \
+	qemumonitorjsontest.c \
 	$(QEMUMONITORTESTUTILS_SOURCES)
 endif
 
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
new file mode 100644
index 0000000..ea69feb
--- /dev/null
+++ b/tests/qemumonitorjsontest.c
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2011-2012 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+
+#include "testutils.h"
+#include "testutilsqemu.h"
+#include "qemumonitortestutils.h"
+#include "threads.h"
+#include "virterror_internal.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static int
+testQemuMonitorJSONGetStatus(const void *data)
+{
+    virCapsPtr caps = (virCapsPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNew(true, caps);
+    int ret = -1;
+    bool running = false;
+    virDomainPausedReason reason = 0;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddItem(test, "query-status",
+                               "{ "
+                               "    \"return\": { "
+                               "        \"status\": \"running\", "
+                               "        \"singlestep\": false, "
+                               "        \"running\": true "
+                               "    } "
+                               "}") < 0)
+        goto cleanup;
+    if (qemuMonitorTestAddItem(test, "query-status",
+                               "{ "
+                               "    \"return\": { "
+                               "        \"singlestep\": false, "
+                               "        \"running\": false "
+                               "    } "
+                               "}") < 0)
+        goto cleanup;
+    if (qemuMonitorTestAddItem(test, "query-status",
+                               "{ "
+                               "    \"return\": { "
+                               "        \"status\": \"inmigrate\", "
+                               "        \"singlestep\": false, "
+                               "        \"running\": false "
+                               "    } "
+                               "}") < 0)
+        goto cleanup;
+
+    if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test),
+                             &running, &reason) < 0)
+        goto cleanup;
+
+    if (!running) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Running was not true");
+        goto cleanup;
+    }
+
+    if (reason != VIR_DOMAIN_PAUSED_UNKNOWN) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Reason was unexpectedly set to %d", reason);
+        goto cleanup;
+    }
+
+    if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test),
+                             &running, &reason) < 0)
+        goto cleanup;
+
+    if (running) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Running was not false");
+        goto cleanup;
+    }
+
+    if (reason != VIR_DOMAIN_PAUSED_UNKNOWN) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Reason was unexpectedly set to %d", reason);
+        goto cleanup;
+    }
+
+    if (qemuMonitorGetStatus(qemuMonitorTestGetMonitor(test),
+                             &running, &reason) < 0)
+        goto cleanup;
+
+    if (running) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "Running was not false");
+        goto cleanup;
+    }
+
+    if (reason != VIR_DOMAIN_PAUSED_MIGRATION) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "Reason was unexpectedly set to %d", reason);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+static int
+mymain(void)
+{
+    int ret = 0;
+    virCapsPtr caps;
+
+    if (virThreadInitialize() < 0)
+        exit(EXIT_FAILURE);
+
+    if (!(caps = testQemuCapsInit()))
+        exit(EXIT_FAILURE);
+
+    virEventRegisterDefaultImpl();
+
+#define DO_TEST(name) \
+    if (virtTestRun(# name, 1, testQemuMonitorJSON ## name, caps) < 0) \
+        ret = -1
+
+    DO_TEST(GetStatus);
+
+    virCapabilitiesFree(caps);
+
+    return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
-- 
1.7.11.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]