[PATCH 15/20] tests: Add qemuagenttest

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

 



Add a basic test framework with two simple tests to test guest agent
interaction.
---
 .gitignore            |   1 +
 tests/Makefile.am     |  11 +++-
 tests/qemuagenttest.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 174 insertions(+), 1 deletion(-)
 create mode 100644 tests/qemuagenttest.c

diff --git a/.gitignore b/.gitignore
index 4c79de3..738c6ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -165,6 +165,7 @@
 /tests/object-locking-files.txt
 /tests/object-locking.cm[ix]
 /tests/openvzutilstest
+/tests/qemuagenttest
 /tests/qemuargv2xmltest
 /tests/qemuhelptest
 /tests/qemuhotplugtest
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5ea806e..9c578fa 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -161,7 +161,8 @@ endif
 if WITH_QEMU
 test_programs += qemuxml2argvtest qemuxml2xmltest qemuxmlnstest \
 	qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
-	qemumonitortest qemumonitorjsontest qemuhotplugtest
+	qemumonitortest qemumonitorjsontest qemuhotplugtest \
+	qemuagenttest
 endif

 if WITH_LXC
@@ -418,6 +419,13 @@ qemumonitorjsontest_SOURCES = \
 	$(NULL)
 qemumonitorjsontest_LDADD = $(qemu_LDADDS) libqemumonitortestutils.la

+qemuagenttest_SOURCES = \
+	qemuagenttest.c \
+	testutils.c testutils.h \
+	testutilsqemu.c testutilsqemu.h \
+	$(NULL)
+qemuagenttest_LDADD = $(qemu_LDADDS) libqemumonitortestutils.la
+
 qemuhotplugtest_SOURCES = \
 	qemuhotplugtest.c \
 	testutils.c testutils.h \
@@ -434,6 +442,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
 	qemuxmlnstest.c qemuhelptest.c domainsnapshotxml2xmltest.c \
 	qemumonitortest.c testutilsqemu.c testutilsqemu.h \
 	qemumonitorjsontest.c qemuhotplugtest.c \
+	qemuagenttest.c \
 	$(QEMUMONITORTESTUTILS_SOURCES)
 endif

diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
new file mode 100644
index 0000000..7f22ff0
--- /dev/null
+++ b/tests/qemuagenttest.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright (C) 2013 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 "qemu/qemu_conf.h"
+#include "qemu/qemu_agent.h"
+#include "virthread.h"
+#include "virerror.h"
+#include "virstring.h"
+
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+static int
+testQemuAgentFSFreeze(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+    int ret = -1;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "guest-fsfreeze-freeze",
+                               "{ \"return\" : 5 }") < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "guest-fsfreeze-freeze",
+                               "{ \"return\" : 7 }") < 0)
+        goto cleanup;
+
+    if ((ret = qemuAgentFSFreeze(qemuMonitorTestGetAgent(test))) < 0)
+        goto cleanup;
+
+    if (ret != 5) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "expected 5 frozen filesystems, got %d", ret);
+        goto cleanup;
+    }
+
+    if ((ret = qemuAgentFSFreeze(qemuMonitorTestGetAgent(test))) < 0)
+        goto cleanup;
+
+    if (ret != 7) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "expected 7 frozen filesystems, got %d", ret);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+
+static int
+testQemuAgentFSThaw(const void *data)
+{
+    virDomainXMLOptionPtr xmlopt = (virDomainXMLOptionPtr)data;
+    qemuMonitorTestPtr test = qemuMonitorTestNewAgent(xmlopt);
+    int ret = -1;
+
+    if (!test)
+        return -1;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "guest-fsfreeze-thaw",
+                               "{ \"return\" : 5 }") < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddAgentSyncResponse(test) < 0)
+        goto cleanup;
+
+    if (qemuMonitorTestAddItem(test, "guest-fsfreeze-thaw",
+                               "{ \"return\" : 7 }") < 0)
+        goto cleanup;
+
+    if ((ret = qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0)
+        goto cleanup;
+
+    if (ret != 5) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "expected 5 thawed filesystems, got %d", ret);
+        goto cleanup;
+    }
+
+    if ((ret = qemuAgentFSThaw(qemuMonitorTestGetAgent(test))) < 0)
+        goto cleanup;
+
+    if (ret != 7) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       "expected 7 thawed filesystems, got %d", ret);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    qemuMonitorTestFree(test);
+    return ret;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+    virDomainXMLOptionPtr xmlopt;
+
+#if !WITH_YAJL
+    fputs("libvirt not compiled with yajl, skipping this test\n", stderr);
+    return EXIT_AM_SKIP;
+#endif
+
+    if (virThreadInitialize() < 0 ||
+        !(xmlopt = virQEMUDriverCreateXMLConf(NULL)))
+        return EXIT_FAILURE;
+
+    virEventRegisterDefaultImpl();
+
+#define DO_TEST(name) \
+    if (virtTestRun(# name, 1, testQemuAgent ## name, xmlopt) < 0) \
+        ret = -1
+
+    DO_TEST(FSFreeze);
+    DO_TEST(FSThaw);
+
+    virObjectUnref(xmlopt);
+
+    return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
-- 
1.8.3.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]