From: Jason Baron <jbaron@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, pbonzini@redhat.com, aliguori@us.ibm.com,
quintela@redhat.com
Subject: [Qemu-devel] [PATCH 3/3] qtest: add migrate-test
Date: Thu, 13 Dec 2012 17:02:22 -0500 [thread overview]
Message-ID: <09d47ca1eb9dc1391d68d82f3aebd6831328f182.1355435056.git.jbaron@redhat.com> (raw)
In-Reply-To: <cover.1355435056.git.jbaron@redhat.com>
From: Jason Baron <jbaron@redhat.com>
Tests a single 'pc' machine migration on the same host. Currently, the test
fail for q35 since the ahci controller doesn't yet migrate. Will add support
for q35 once the ahci support is accepted.
Would be nice to extend the test matrix to various machine versions, but that
requires building multiple qemu binaries, which is a bit awkward in the
context of qtest. Testing migration between different machine versions with the
same binary doesn't seem too useful.
Signed-off-by: Jason Baron <jbaron@redhat.com>
---
tests/Makefile | 2 +
tests/migrate-test.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 142 insertions(+), 0 deletions(-)
create mode 100644 tests/migrate-test.c
diff --git a/tests/Makefile b/tests/Makefile
index 30a101d..d50dff0 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -25,6 +25,7 @@ check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
check-qtest-i386-y = tests/fdc-test$(EXESUF)
check-qtest-i386-y += tests/hd-geo-test$(EXESUF)
check-qtest-i386-y += tests/rtc-test$(EXESUF)
+check-qtest-i386-y += tests/migrate-test$(EXESUF)
check-qtest-x86_64-y = $(check-qtest-i386-y)
check-qtest-sparc-y = tests/m48t59-test$(EXESUF)
check-qtest-sparc64-y = tests/m48t59-test$(EXESUF)
@@ -78,6 +79,7 @@ tests/rtc-test$(EXESUF): tests/rtc-test.o $(trace-obj-y) qstring.o
tests/m48t59-test$(EXESUF): tests/m48t59-test.o $(trace-obj-y)
tests/fdc-test$(EXESUF): tests/fdc-test.o tests/libqtest.o $(trace-obj-y) qstring.o
tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/libqtest.o $(trace-obj-y) qstring.o
+tests/migrate-test$(EXESUF): tests/migrate-test.o $(test-qapi-obj-y) $(qom-obj-y)
# QTest rules
diff --git a/tests/migrate-test.c b/tests/migrate-test.c
new file mode 100644
index 0000000..c62d5af
--- /dev/null
+++ b/tests/migrate-test.c
@@ -0,0 +1,140 @@
+/*
+ * Migration tests
+ *
+ * Copyright Red Hat, Inc. 2012
+ *
+ * Authors:
+ * Jason Baron <jbaron@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ *
+ */
+#include "libqtest.h"
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "qjson.h"
+#include "error.h"
+#include "qemu/object.h"
+#include "qdict.h"
+#include "qbool.h"
+
+#define migrate_assert(cond) \
+ if (!(cond)) { \
+ migrate_cleanup(); \
+ fprintf(stderr, "%s:%d %s\n", __FILE__, __LINE__, #cond); \
+ abort(); \
+ } \
+
+static QTestState *mach_a;
+static QTestState *mach_b;
+
+static void migrate_cleanup(void)
+{
+ if (mach_a) {
+ qtest_quit(mach_a);
+ }
+ if (mach_b) {
+ qtest_quit(mach_b);
+ }
+}
+
+static int expected_qobject(QObject *obj, qtype_code type)
+{
+ if (!obj) {
+ return 0;
+ }
+ return (qobject_type(obj) == type);
+}
+
+/*
+ * Return vals:
+ * 1: yes
+ * 0: no
+ * -1: retry
+ */
+static int is_running(QTestState *mch)
+{
+ QString *resp = qstring_new();
+ QObject *resp_obj;
+ QObject *ret_obj;
+ QObject *run_obj;
+ int ret;
+
+ resp = qstring_new();
+ qtest_qmp_resp(mch, resp, "{ 'execute': 'query-status' }", NULL);
+
+ resp_obj = qobject_from_json(qstring_get_str(resp));
+ if (!expected_qobject(resp_obj, QTYPE_QDICT)) {
+ ret = -1;
+ goto out;
+ }
+
+ ret_obj = qdict_get(qobject_to_qdict(resp_obj), "return");
+ if (!expected_qobject(ret_obj, QTYPE_QDICT)) {
+ ret = -1;
+ goto out;
+ }
+
+ run_obj = qdict_get(qobject_to_qdict(ret_obj), "running");
+ if (!expected_qobject(run_obj, QTYPE_QBOOL)) {
+ ret = -1;
+ goto out;
+ }
+ ret = qbool_get_int(qobject_to_qbool(run_obj));
+
+out:
+ qobject_decref(resp_obj);
+ QDECREF(resp);
+ return ret;
+}
+
+#define SLEEP_INTERVAL 2
+/* Abort after 2 minutes */
+#define SLEEP_MAX (60 * 2)
+
+static void migrate_a_to_b(void)
+{
+ int a_run = 0;
+ int b_run = 0;
+ int iter = 0;
+
+ /* is running on A ? */
+ migrate_assert(is_running(mach_a));
+
+ /* do migrate */
+ qtest_qmp(mach_a, "{ 'execute': 'migrate',"
+ "'arguments': { 'uri': 'tcp:0:4444' } }", NULL);
+
+ while (iter < SLEEP_MAX) {
+ a_run = is_running(mach_a);
+ b_run = is_running(mach_b);
+ if ((a_run == 0) && (b_run == 1)) {
+ break;
+ }
+ sleep(SLEEP_INTERVAL);
+ iter += SLEEP_INTERVAL;
+ }
+ migrate_assert((a_run == 0) && (b_run == 1));
+}
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ g_test_init(&argc, &argv, NULL);
+
+ mach_a = qtest_start("-display none -machine pc");
+ mach_b = qtest_start("-display none -machine pc -incoming tcp:0:4444");
+
+ qtest_add_func("/migrate/a-to-b", migrate_a_to_b);
+ ret = g_test_run();
+
+ migrate_cleanup();
+ return ret;
+}
--
1.7.1
next prev parent reply other threads:[~2012-12-13 22:02 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-13 22:02 [Qemu-devel] [PATCH 0/3] qtest: add migration testing Jason Baron
2012-12-13 22:02 ` [Qemu-devel] [PATCH 1/3] qtest: Enable creation of multiple qemu instances Jason Baron
2012-12-14 20:30 ` Blue Swirl
2012-12-15 9:14 ` Paolo Bonzini
2012-12-15 9:20 ` Blue Swirl
2012-12-17 17:13 ` Jason Baron
2012-12-19 19:42 ` Blue Swirl
2012-12-13 22:02 ` [Qemu-devel] [PATCH 2/3] qtest: extend qtest_qmp() to fill in the reply Jason Baron
2012-12-14 0:07 ` Andreas Färber
2012-12-14 16:10 ` Jason Baron
2012-12-13 22:02 ` Jason Baron [this message]
2012-12-14 8:08 ` [Qemu-devel] [PATCH 3/3] qtest: add migrate-test Paolo Bonzini
2012-12-14 16:14 ` Jason Baron
2012-12-14 17:25 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=09d47ca1eb9dc1391d68d82f3aebd6831328f182.1355435056.git.jbaron@redhat.com \
--to=jbaron@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).