From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Cc: Adam Litke <aglitke@linux.vnet.ibm.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Markus Armbruster <armbru@redhat.com>,
Luiz Capitulino <lcapitulino@redhat.com>
Subject: [Qemu-devel] [PATCH 21/22] qapi: add test-libqmp
Date: Sun, 6 Mar 2011 19:23:03 -0600 [thread overview]
Message-ID: <1299460984-15849-22-git-send-email-aliguori@us.ibm.com> (raw)
In-Reply-To: <1299460984-15849-1-git-send-email-aliguori@us.ibm.com>
This provides a glib-test based testing framework for QMP
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/Makefile b/Makefile
index 5170675..1d363d7 100644
--- a/Makefile
+++ b/Makefile
@@ -72,6 +72,8 @@ defconfig:
-include config-all-devices.mak
+TOOLS += test-libqmp
+
build-all: $(DOCS) $(TOOLS) recurse-all
config-host.h: config-host.h-timestamp
@@ -205,6 +207,15 @@ check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS)
check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS)
check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS)
+LIBQMP_OBJS := qmp-types.o libqmp.o error.o libqmp-core.o
+LIBQMP_OBJS += qmp-marshal-types-core.o qmp-marshal-types.o
+LIBQMP_OBJS += qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o
+LIBQMP_OBJS += qerror.o
+LIBQMP_OBJS += json-streamer.o json-lexer.o json-parser.o
+LIBQMP_OBJS += $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o
+
+test-libqmp: test-libqmp.o $(LIBQMP_OBJS) qemu-timer-common.o
+
clean:
# avoid old build problems by removing potentially incorrect old files
rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
diff --git a/test-libqmp.c b/test-libqmp.c
new file mode 100644
index 0000000..9b73987
--- /dev/null
+++ b/test-libqmp.c
@@ -0,0 +1,170 @@
+/*
+ * QAPI
+ *
+ * Copyright IBM, Corp. 2011
+ *
+ * Authors:
+ * Anthony Liguori <aliguori@us.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2. See
+ * the COPYING.LIB file in the top-level directory.
+ */
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <sys/un.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <sys/wait.h>
+#include "config-host.h"
+#include "libqmp.h"
+#include "qerror.h"
+
+#define g_assert_noerr(err) g_assert(err == NULL);
+#define g_assert_anyerr(err) g_assert(err != NULL);
+#define g_assert_cmperr(err, op, type) do { \
+ g_assert_anyerr(err); \
+ g_assert_cmpstr(error_get_field(err, "class"), op, type); \
+} while (0)
+
+static pid_t last_qemu_pid = -1;
+
+static QmpSession *qemu(const char *fmt, ...)
+{
+ char buffer0[4096];
+ char buffer1[4096];
+ const char *pid_filename = "/tmp/test-libqmp-qemu.pid";
+ const char *path = "/tmp/test-libqmp-qemu.sock";
+ struct sockaddr_un addr;
+ va_list ap;
+ int ret;
+ int fd;
+
+ va_start(ap, fmt);
+ vsnprintf(buffer0, sizeof(buffer0), fmt, ap);
+ va_end(ap);
+
+ snprintf(buffer1, sizeof(buffer1),
+ "i386-softmmu/qemu "
+ "-enable-kvm "
+ "-name test-libqmp "
+ "-qmp2 qmp "
+ "-chardev socket,id=qmp,path=%s,server=on,wait=off "
+ "-vnc none "
+ "-daemonize "
+ "-pidfile %s "
+ "%s", path, pid_filename, buffer0);
+ g_test_message("Executing %s\n", buffer1);
+ ret = system(buffer1);
+ g_assert(ret != -1);
+
+ {
+ FILE *f;
+ char buffer[1024];
+ char *ptr;
+
+ f = fopen(pid_filename, "r");
+ g_assert(f != NULL);
+
+ ptr = fgets(buffer, sizeof(buffer), f);
+ g_assert(ptr != NULL);
+
+ fclose(f);
+
+ last_qemu_pid = atoi(buffer);
+ }
+
+ fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ g_assert(fd != -1);
+
+ addr.sun_family = AF_UNIX;
+ snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path);
+ ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr));
+ g_assert(ret != -1);
+
+ return qmp_session_new(fd);
+}
+
+static void wait_for_pid_exit(pid_t pid)
+{
+ FILE *f = NULL;
+
+ /* This is ugly but I don't know of a better way */
+ do {
+ char buffer[1024];
+
+ if (f) {
+ fclose(f);
+ usleep(10000);
+ }
+
+ snprintf(buffer, sizeof(buffer), "/proc/%d/stat", pid);
+ f = fopen(buffer, "r");
+ } while (f);
+}
+
+static void qemu_destroy(QmpSession *sess)
+{
+ wait_for_pid_exit(last_qemu_pid);
+ last_qemu_pid = -1;
+ qmp_session_destroy(sess);
+}
+
+static void test_version(void)
+{
+ QmpSession *sess = NULL;
+ VersionInfo *info;
+ char version[1024];
+ char *ptr, *end;
+ int major, minor, micro;
+
+ /* Even though we use the same string as the source input, we do parse it
+ * a little bit different for no other reason that to make sure we catch
+ * potential bugs.
+ */
+ snprintf(version, sizeof(version), "%s", QEMU_VERSION);
+ ptr = version;
+
+ end = strchr(ptr, '.');
+ g_assert(end != NULL);
+ *end = 0;
+ major = atoi(ptr);
+ ptr = end + 1;
+
+ end = strchr(ptr, '.');
+ g_assert(end != NULL);
+ *end = 0;
+ minor = atoi(ptr);
+ ptr = end + 1;
+
+ micro = atoi(ptr);
+ while (g_ascii_isdigit(*ptr)) ptr++;
+
+ sess = qemu("-S");
+
+ info = libqmp_query_version(sess, NULL);
+
+ g_assert_cmpint(major, ==, info->qemu.major);
+ g_assert_cmpint(minor, ==, info->qemu.minor);
+ g_assert_cmpint(micro, ==, info->qemu.micro);
+ g_assert_cmpstr(ptr, ==, info->package);
+
+ qmp_free_version_info(info);
+
+ libqmp_quit(sess, NULL);
+
+ qemu_destroy(sess);
+}
+
+int main(int argc, char **argv)
+{
+ g_test_init(&argc, &argv, NULL);
+
+ g_test_add_func("/0.14/misc/version", test_version);
+
+ g_test_run();
+
+ return 0;
+}
--
1.7.0.4
next prev parent reply other threads:[~2011-03-07 1:23 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-07 1:22 [Qemu-devel] [PATCH 00/22] QAPI Round 1 Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 01/22] Add hard build dependency on glib Anthony Liguori
2011-03-07 10:59 ` Daniel P. Berrange
2011-03-07 13:55 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 02/22] qerror: expose a function to format an error Anthony Liguori
2011-03-07 11:14 ` Stefan Hajnoczi
2011-03-07 13:38 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 03/22] qapi: add Error object Anthony Liguori
2011-03-07 11:06 ` Daniel P. Berrange
2011-03-07 13:59 ` Anthony Liguori
2011-03-07 14:24 ` Anthony Liguori
2011-03-07 11:38 ` Stefan Hajnoczi
2011-03-07 13:36 ` Anthony Liguori
2011-03-07 13:55 ` Stefan Hajnoczi
2011-03-07 1:22 ` [Qemu-devel] [PATCH 04/22] qerror: split out the reporting bits of QError Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 05/22] qerror: add new error message for invalid enum values Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 06/22] qapi: add JSON parsing error message Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 07/22] json: propagate error from parser Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 08/22] qapi: add code generator for qmp-types Anthony Liguori
2011-03-07 1:57 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 09/22] qapi: add code generator for type marshallers Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 10/22] qapi: add core QMP server support Anthony Liguori
2011-03-07 13:09 ` Stefan Hajnoczi
2011-03-07 13:39 ` Anthony Liguori
2011-03-07 13:46 ` Daniel P. Berrange
2011-03-07 13:54 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 11/22] qapi: add signal support to core QMP server Anthony Liguori
2011-03-07 13:21 ` Stefan Hajnoczi
2011-03-07 13:53 ` Anthony Liguori
2011-03-07 14:36 ` Stefan Hajnoczi
2011-03-07 14:41 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 12/22] qapi: add QAPI module type Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 13/22] qapi: add code generators for QMP command marshaling Anthony Liguori
2011-03-07 13:27 ` Stefan Hajnoczi
2011-03-07 13:44 ` Anthony Liguori
2011-03-07 14:38 ` Stefan Hajnoczi
2011-03-07 1:22 ` [Qemu-devel] [PATCH 14/22] qapi: add query-version QMP command Anthony Liguori
2011-03-07 13:35 ` Stefan Hajnoczi
2011-03-07 13:41 ` Anthony Liguori
2011-03-09 13:28 ` Avi Kivity
2011-03-09 13:44 ` Anthony Liguori
2011-03-09 13:51 ` Avi Kivity
2011-03-09 14:13 ` Anthony Liguori
2011-03-09 13:36 ` Avi Kivity
2011-03-09 14:11 ` Anthony Liguori
2011-03-09 14:37 ` Avi Kivity
2011-03-09 14:47 ` Anthony Liguori
2011-03-10 12:41 ` Avi Kivity
2011-03-10 12:46 ` Avi Kivity
2011-03-10 13:52 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 15/22] qapi: add new QMP server that uses CharDriverState Anthony Liguori
2011-03-07 13:52 ` Stefan Hajnoczi
2011-03-07 14:02 ` Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 16/22] vl: add a new -qmp2 option to expose experimental QMP server Anthony Liguori
2011-03-07 1:22 ` [Qemu-devel] [PATCH 17/22] qapi: add QMP quit command Anthony Liguori
2011-03-07 1:23 ` [Qemu-devel] [PATCH 18/22] qapi: add QMP qmp_capabilities command Anthony Liguori
2011-03-07 1:23 ` [Qemu-devel] [PATCH 19/22] qapi: add QMP put-event command Anthony Liguori
2011-03-09 13:31 ` Avi Kivity
2011-03-09 13:48 ` Anthony Liguori
2011-03-09 13:58 ` Avi Kivity
2011-03-09 14:26 ` Anthony Liguori
2011-03-10 12:39 ` Avi Kivity
2011-03-10 14:12 ` Anthony Liguori
2011-03-10 14:24 ` Avi Kivity
2011-03-10 15:30 ` Avi Kivity
2011-03-10 15:41 ` Anthony Liguori
2011-03-10 15:49 ` Avi Kivity
2011-03-10 16:42 ` Anthony Liguori
2011-03-12 20:37 ` Avi Kivity
2011-03-10 15:33 ` Anthony Liguori
2011-03-10 15:45 ` Avi Kivity
2011-03-10 16:04 ` Anthony Liguori
2011-03-12 20:42 ` Avi Kivity
2011-03-12 23:30 ` Anthony Liguori
2011-03-07 1:23 ` [Qemu-devel] [PATCH 20/22] qapi: add code generator for libqmp Anthony Liguori
2011-03-07 1:23 ` Anthony Liguori [this message]
2011-03-07 1:23 ` [Qemu-devel] [PATCH 22/22] qapi: generate HTML report for test-libqmp Anthony Liguori
2011-03-07 2:11 ` Anthony Liguori
2011-03-07 1:26 ` [Qemu-devel] [PATCH] qapi: qmp-types.c and qmp-types.h Anthony Liguori
2011-03-07 1:27 ` [Qemu-devel] [PATCH] qapi: qmp-marshal-types.c and qmp-marshal-types.h Anthony Liguori
2011-03-07 1:28 ` [Qemu-devel] [PATCH] qapi: add qmp-marshal.c and qmp.h Anthony Liguori
2011-03-07 1:29 ` [Qemu-devel] [PATCH] qapi: add libqmp.c and libqmp.h Anthony Liguori
2011-03-07 15:08 ` [Qemu-devel] [PATCH 00/22] QAPI Round 1 Stefan Hajnoczi
2011-03-07 15:59 ` Anthony Liguori
2011-03-08 11:12 ` Avi Kivity
2011-03-08 13:35 ` Anthony Liguori
2011-03-08 13:45 ` Avi Kivity
2011-03-08 13:54 ` Anthony Liguori
2011-03-08 14:00 ` Avi Kivity
2011-03-08 14:10 ` Anthony Liguori
2011-03-08 14:17 ` Avi Kivity
2011-03-08 14:20 ` Anthony Liguori
2011-03-08 14:38 ` Anthony Liguori
2011-03-08 14:52 ` Avi Kivity
2011-03-08 15:03 ` Anthony Liguori
2011-03-08 17:44 ` Avi Kivity
2011-03-08 19:19 ` Anthony Liguori
2011-03-09 8:51 ` Avi Kivity
2011-03-09 13:12 ` Anthony Liguori
2011-03-09 13:14 ` Avi Kivity
2011-03-09 13:51 ` Anthony Liguori
2011-03-09 13:55 ` Avi Kivity
2011-03-09 14:15 ` Anthony Liguori
2011-03-09 13:51 ` Michael Roth
2011-03-07 20:59 ` Anthony Liguori
2011-03-07 22:00 ` Stefan Hajnoczi
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=1299460984-15849-22-git-send-email-aliguori@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=aglitke@linux.vnet.ibm.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).