From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZnJD-0003zC-Jr for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:53:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZnJ9-0002qR-7i for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:53:39 -0400 Received: from e37.co.us.ibm.com ([32.97.110.158]:33859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZnJ8-0002om-Vj for qemu-devel@nongnu.org; Wed, 09 Sep 2015 17:53:35 -0400 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 9 Sep 2015 15:53:32 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 76D2D19D801C for ; Wed, 9 Sep 2015 15:44:23 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t89LqMtW52691182 for ; Wed, 9 Sep 2015 14:52:22 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t89LrSoK023875 for ; Wed, 9 Sep 2015 15:53:28 -0600 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1440672727-20231-2-git-send-email-marcandre.lureau@redhat.com> References: <1440672727-20231-1-git-send-email-marcandre.lureau@redhat.com> <1440672727-20231-2-git-send-email-marcandre.lureau@redhat.com> Message-ID: <20150909215319.3885.37547@loki> Date: Wed, 09 Sep 2015 16:53:19 -0500 Subject: Re: [Qemu-devel] [PATCH 2/2] tests: add a local test for guest agent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Quoting marcandre.lureau@redhat.com (2015-08-27 05:52:07) > From: Marc-Andr=C3=A9 Lureau > = > Add some local guest agent tests (as it is better than nothing). > = > They can be run inside or outside a VM, when run inside a VM, they will > do a bit more side effects, such as freezing/thawing the FS or changing > the time. > = > A better test would involve a managed VM (or container), but it might be > better to leave that off to autotest/avocado. > = > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > tests/Makefile | 3 + > tests/test-qga.c | 686 +++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 2 files changed, 689 insertions(+) > create mode 100644 tests/test-qga.c > = > diff --git a/tests/Makefile b/tests/Makefile > index 5271123..35671a1 100644 > --- a/tests/Makefile > +++ b/tests/Makefile > @@ -76,6 +76,7 @@ check-unit-y +=3D tests/test-write-threshold$(EXESUF) > gcov-files-test-write-threshold-y =3D block/write-threshold.c > check-unit-$(CONFIG_GNUTLS_HASH) +=3D tests/test-crypto-hash$(EXESUF) > check-unit-y +=3D tests/test-crypto-cipher$(EXESUF) > +check-unit-y +=3D tests/test-qga$(EXESUF) > = > check-block-$(CONFIG_POSIX) +=3D tests/qemu-iotests-quick.sh > = > @@ -425,6 +426,8 @@ endif > qtest-obj-y =3D tests/libqtest.o libqemuutil.a libqemustub.a > $(check-qtest-y): $(qtest-obj-y) > = > +tests/test-qga: tests/test-qga.o $(qtest-obj-y) > + > .PHONY: check-help > check-help: > @echo "Regression testing targets:" > diff --git a/tests/test-qga.c b/tests/test-qga.c > new file mode 100644 > index 0000000..1fb58ec > --- /dev/null > +++ b/tests/test-qga.c > @@ -0,0 +1,686 @@ > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "libqtest.h" > +#include "config-host.h" > + > +typedef struct { > + char *test_dir; > + GMainLoop *loop; > + int fd; > + GPid pid; > +} TestFixture; > + > +static int connect_qga(char *path) > +{ > + int s, ret, len; > + struct sockaddr_un remote; > + > + s =3D socket(AF_UNIX, SOCK_STREAM, 0); > + g_assert(s !=3D -1); > + > + remote.sun_family =3D AF_UNIX; > + do { > + strcpy(remote.sun_path, path); > + len =3D strlen(remote.sun_path) + sizeof(remote.sun_family); > + ret =3D connect(s, (struct sockaddr *)&remote, len); > + if (ret =3D=3D -1) { > + g_usleep(G_USEC_PER_SEC); > + } > + } while (ret =3D=3D -1); I think we should loop on ECONNREFUSED (or whatever corresponds to the socket not yet being created/bound), and the usual suspects like EINTR. If it's anything else I don't think we'd want this to loop indefinitely. > + > + return s; > +} > + > +static void qga_watch(GPid pid, gint status, gpointer user_data) > +{ > + TestFixture *fixture =3D user_data; > + > + g_assert_cmpint(status, =3D=3D, 0); > + g_main_loop_quit(fixture->loop); > +} > + > +static void > +fixture_setup(TestFixture *fixture, gconstpointer data) > +{ > + const gchar *extra_arg =3D data; > + GError *error =3D NULL; > + gchar *cwd, *path, *cmd, **argv =3D NULL; > + > + fixture->loop =3D g_main_loop_new(NULL, FALSE); > + > + fixture->test_dir =3D g_strdup("/tmp/qgatest.XXXXXX"); > + g_assert_nonnull(g_mkdtemp(fixture->test_dir)); > + > + path =3D g_build_filename(fixture->test_dir, "sock", NULL); > + cwd =3D g_get_current_dir(); > + cmd =3D g_strdup_printf("%s%cqemu-ga -m unix-listen -t %s -p %s %s %= s", Would be nice if we could also run qemu-ga.exe for a w32 build with binfmt set up like some of the other tests, but no idea how we'd get at it through wine. I guess it would have to be a serial connection or something... Probably too environment-specific for a useful unit test. I guess in the future we could plumb in custom qemu-ga invocation/script that does some extra setup on the backend (VM/container/wine) and exposes that via a local socket like we'd get via -chardev. > + cwd, G_DIR_SEPARATOR, > + fixture->test_dir, path, > + getenv("QTEST_LOG") ? "-v" : "", > + extra_arg ?: ""); > + g_shell_parse_argv(cmd, NULL, &argv, &error); > + g_assert_no_error(error); > + > + g_spawn_async(fixture->test_dir, argv, NULL, > + G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, > + NULL, NULL, &fixture->pid, &error); > + g_assert_no_error(error); > + > + g_child_watch_add(fixture->pid, qga_watch, fixture); > + > + fixture->fd =3D connect_qga(path); > + > + g_strfreev(argv); > + g_free(cmd); > + g_free(cwd); > + g_free(path); > +} > + > +static void > +fixture_tear_down(TestFixture *fixture, gconstpointer data) > +{ > + gchar *tmp; > + > + kill(fixture->pid, SIGTERM); > + > + g_main_loop_run(fixture->loop); > + g_main_loop_unref(fixture->loop); > + > + g_spawn_close_pid(fixture->pid); > + > + tmp =3D g_build_filename(fixture->test_dir, "foo", NULL); > + g_unlink(tmp); > + g_free(tmp); Shouldn't the individual unit tests clean these up? I think a flag determining whether or not we're running locally (set by default obviously) would be useful for determining whether it makes sense for us to clean them up or not. > + > + tmp =3D g_build_filename(fixture->test_dir, "qga.state", NULL); > + g_unlink(tmp); > + g_free(tmp); > + > + tmp =3D g_build_filename(fixture->test_dir, "sock", NULL); > + g_unlink(tmp); > + g_free(tmp); > + > + g_rmdir(fixture->test_dir); > + g_free(fixture->test_dir); > +} > + > +static void qmp_assertion_message_error(const char *domain, > + const char *file, > + int line, > + const char *func, > + const char *expr, > + QDict *dict) > +{ > + const char *class, *desc; > + char *s; > + QDict *error; > + > + error =3D qdict_get_qdict(dict, "error"); > + class =3D qdict_get_try_str(error, "class"); > + desc =3D qdict_get_try_str(error, "desc"); > + > + s =3D g_strdup_printf("assertion failed %s: %s %s", expr, class, des= c); > + g_assertion_message(domain, file, line, func, s); > + g_free(s); > +} > + > +#define qmp_assert_no_error(err) do { \ > + if (qdict_haskey(err, "error")) { \ > + qmp_assertion_message_error(G_LOG_DOMAIN, __FILE__, __LINE__, \ > + G_STRFUNC, #err, err); \ > + } \ > +} while (0) > + > +static void test_qga_sync_delimited(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + guint32 v, r =3D g_random_int(); > + unsigned char c; > + QDict *ret; > + gchar *cmd; > + > + cmd =3D g_strdup_printf("%c{'execute': 'guest-sync-delimited'," > + " 'arguments': {'id': %u } }", 0xff, r); > + qmp_fd_send(fixture->fd, cmd); > + g_free(cmd); > + > + v =3D read(fixture->fd, &c, 1); > + g_assert_cmpint(v, =3D=3D, 1); > + g_assert_cmpint(c, =3D=3D, 0xff); > + > + ret =3D qmp_fd_receive(fixture->fd); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + v =3D qdict_get_int(ret, "return"); > + g_assert_cmpint(r, =3D=3D, v); > + > + QDECREF(ret); > +} > + > +static void test_qga_sync(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + guint32 v, r =3D g_random_int(); > + QDict *ret; > + gchar *cmd; > + > + cmd =3D g_strdup_printf("%c{'execute': 'guest-sync'," > + " 'arguments': {'id': %u } }", 0xff, r); > + ret =3D qmp_fd(fixture->fd, cmd); > + g_free(cmd); > + > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + v =3D qdict_get_int(ret, "return"); > + g_assert_cmpint(r, =3D=3D, v); > + > + QDECREF(ret); > +} > + > +static void test_qga_ping(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + QDECREF(ret); > +} > + > +static void test_qga_invalid_cmd(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret, *error; > + const gchar *class, *desc; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}"); > + g_assert_nonnull(ret); > + > + error =3D qdict_get_qdict(ret, "error"); > + class =3D qdict_get_try_str(error, "class"); > + desc =3D qdict_get_try_str(error, "desc"); > + > + g_assert_cmpstr(class, =3D=3D, "CommandNotFound"); > + g_assert_cmpint(strlen(desc), >, 0); > + > + QDECREF(ret); > +} > + > +static void test_qga_info(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret, *val; > + const gchar *version; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + val =3D qdict_get_qdict(ret, "return"); > + version =3D qdict_get_try_str(val, "version"); > + g_assert_cmpstr(version, =3D=3D, QEMU_VERSION); > + > + QDECREF(ret); > +} > + > +static void test_qga_get_vcpus(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + QList *list; > + const QListEntry *entry; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-vcpus'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + /* check there is at least a cpu */ > + list =3D qdict_get_qlist(ret, "return"); > + entry =3D qlist_first(list); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online")); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "logical-id")); > + > + QDECREF(ret); > +} > + > +static void test_qga_get_fsinfo(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + QList *list; > + const QListEntry *entry; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-fsinfo'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + /* check there is at least a fs */ > + list =3D qdict_get_qlist(ret, "return"); > + entry =3D qlist_first(list); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "mountpoint")); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "type")); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "disk")); > + > + QDECREF(ret); > +} > + > +static void test_qga_get_memory_block_info(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret, *val; > + int64_t size; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-inf= o'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + /* check there is at least some memory */ > + val =3D qdict_get_qdict(ret, "return"); > + size =3D qdict_get_int(val, "size"); > + g_assert_cmpint(size, >, 0); > + > + QDECREF(ret); > +} > + > +static void test_qga_get_memory_blocks(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + QList *list; > + const QListEntry *entry; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-blocks'}"= ); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + list =3D qdict_get_qlist(ret, "return"); > + entry =3D qlist_first(list); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "phys-index")); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "online")); > + > + QDECREF(ret); > +} > + > +static void test_qga_network_get_interfaces(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + QList *list; > + const QListEntry *entry; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-network-get-interfac= es'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + /* check there is at least a cpu */ copy/paste artifact > + list =3D qdict_get_qlist(ret, "return"); > + entry =3D qlist_first(list); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "name")); > + > + QDECREF(ret); > +} > + > +static void test_qga_file_ops(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + gchar *cmd, *path; > + const gchar *b64; > + QDict *ret, *val; > + int64_t id, count, eof; > + FILE *f; > + char tmp[100]; > + > + /* open */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," > + " 'arguments': { 'path': 'foo', 'mode': 'w+' } }"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + id =3D qdict_get_int(ret, "return"); > + QDECREF(ret); > + > + /* write */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-write'," > + " 'arguments': { 'handle': %" G_GINT64_FORMAT = "," > + " 'buf-b64': 'aGVsbG8gd29ybGQK' } }", id); > + ret =3D qmp_fd(fixture->fd, cmd); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + val =3D qdict_get_qdict(ret, "return"); > + count =3D qdict_get_int(val, "count"); > + eof =3D qdict_get_bool(val, "eof"); > + g_assert_cmpint(count, =3D=3D, 12); > + g_assert_cmpint(eof, =3D=3D, 0); > + QDECREF(ret); > + g_free(cmd); > + > + /* flush */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-flush'," > + " 'arguments': {'handle': %" G_GINT64_FORMAT "= } }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); > + QDECREF(ret); > + g_free(cmd); > + > + /* close */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," > + " 'arguments': {'handle': %" G_GINT64_FORMAT "= } }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); > + QDECREF(ret); > + g_free(cmd); > + > + /* check content */ > + path =3D g_build_filename(fixture->test_dir, "foo", NULL); > + f =3D fopen(path, "r"); > + g_assert_nonnull(f); > + count =3D fread(tmp, 1, sizeof(tmp), f); > + g_assert_cmpint(count, =3D=3D, 12); > + tmp[count] =3D 0; > + g_assert_cmpstr(tmp, =3D=3D, "hello world\n"); > + fclose(f); > + > + /* open */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," > + " 'arguments': { 'path': 'foo', 'mode': 'r' } }"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + id =3D qdict_get_int(ret, "return"); > + QDECREF(ret); > + > + /* read */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," > + " 'arguments': { 'handle': %" G_GINT64_FORMAT = "} }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); > + val =3D qdict_get_qdict(ret, "return"); > + count =3D qdict_get_int(val, "count"); > + eof =3D qdict_get_bool(val, "eof"); > + b64 =3D qdict_get_str(val, "buf-b64"); > + g_assert_cmpint(count, =3D=3D, 12); > + g_assert(eof); > + g_assert_cmpstr(b64, =3D=3D, "aGVsbG8gd29ybGQK"); > + > + QDECREF(ret); > + g_free(cmd); > + > + /* read eof */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," > + " 'arguments': { 'handle': %" G_GINT64_FORMAT = "} }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); > + val =3D qdict_get_qdict(ret, "return"); > + count =3D qdict_get_int(val, "count"); > + eof =3D qdict_get_bool(val, "eof"); > + b64 =3D qdict_get_str(val, "buf-b64"); > + g_assert_cmpint(count, =3D=3D, 0); > + g_assert(eof); > + g_assert_cmpstr(b64, =3D=3D, ""); > + QDECREF(ret); > + g_free(cmd); > + > + /* seek */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-seek'," > + " 'arguments': { 'handle': %" G_GINT64_FORMAT = ", " > + " 'offset': %d, 'whence': %d } }", > + id, 6, SEEK_SET); > + ret =3D qmp_fd(fixture->fd, cmd); > + qmp_assert_no_error(ret); > + val =3D qdict_get_qdict(ret, "return"); > + count =3D qdict_get_int(val, "position"); > + eof =3D qdict_get_bool(val, "eof"); > + g_assert_cmpint(count, =3D=3D, 6); > + g_assert(!eof); > + QDECREF(ret); > + g_free(cmd); > + > + /* partial read */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-read'," > + " 'arguments': { 'handle': %" G_GINT64_FORMAT = "} }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); > + val =3D qdict_get_qdict(ret, "return"); > + count =3D qdict_get_int(val, "count"); > + eof =3D qdict_get_bool(val, "eof"); > + b64 =3D qdict_get_str(val, "buf-b64"); > + g_assert_cmpint(count, =3D=3D, 6); > + g_assert(eof); > + g_assert_cmpstr(b64, =3D=3D, "d29ybGQK"); > + > + QDECREF(ret); > + g_free(cmd); > + > + /* close */ > + cmd =3D g_strdup_printf("{'execute': 'guest-file-close'," > + " 'arguments': {'handle': %" G_GINT64_FORMAT "= } }", > + id); > + ret =3D qmp_fd(fixture->fd, cmd); I like having a complex test to make sure all the guest-file-* commands interact properly, but would be good if we could preceed this with simpler guest-file-* tests that test each command more granularly. That could be added as a follow-up though, since this is still a good test to have. > + QDECREF(ret); > + g_free(cmd); > +} > + > +static void test_qga_get_time(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + int64_t time; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + time =3D qdict_get_int(ret, "return"); > + g_assert_cmpint(time, >, 0); > + > + QDECREF(ret); > +} > + > +static void test_qga_set_time(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + int64_t current, time; > + gchar *cmd; > + > + /* get current time */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + current =3D qdict_get_int(ret, "return"); > + g_assert_cmpint(current, >, 0); > + QDECREF(ret); > + > + /* set some old time */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-set-time'," > + " 'arguments': { 'time': 1000 } }"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + QDECREF(ret); > + > + /* check old time */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + time =3D qdict_get_int(ret, "return"); > + g_assert_cmpint(time / 1000, <, G_USEC_PER_SEC * 10); > + QDECREF(ret); > + > + /* set back current time */ > + cmd =3D g_strdup_printf("{'execute': 'guest-set-time'," > + " 'arguments': { 'time': %" G_GINT64_FORMAT " = } }", > + current + time * 1000); > + ret =3D qmp_fd(fixture->fd, cmd); Little concerned about playing with host time in our unit tests. Maybe this sort of test should only be enabled if a flag is set, and turned of by default? Ah, I see that's where running_in_virt() comes into play. Nice :) > + g_free(cmd); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + QDECREF(ret); > +} > + > +static void test_qga_fstrim(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + QList *list; > + const QListEntry *entry; > + > + /* get current time */ copy/paste artifact > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fstrim'," > + " arguments: { minimum: 4194304 } }"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + list =3D qdict_get_qlist(ret, "return"); > + entry =3D qlist_first(list); > + g_assert(qdict_haskey(qobject_to_qdict(entry->value), "paths")); > + > + QDECREF(ret); > +} > + > +static void test_qga_blacklist(gconstpointer data) > +{ > + TestFixture fix; > + QDict *ret, *error; > + const gchar *class, *desc; > + > + fixture_setup(&fix, "-b guest-ping,guest-get-time"); > + > + /* check blacklist */ > + ret =3D qmp_fd(fix.fd, "{'execute': 'guest-ping'}"); > + g_assert_nonnull(ret); > + error =3D qdict_get_qdict(ret, "error"); > + class =3D qdict_get_try_str(error, "class"); > + desc =3D qdict_get_try_str(error, "desc"); > + g_assert_cmpstr(class, =3D=3D, "GenericError"); > + g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled")); > + QDECREF(ret); > + > + ret =3D qmp_fd(fix.fd, "{'execute': 'guest-get-time'}"); > + g_assert_nonnull(ret); > + error =3D qdict_get_qdict(ret, "error"); > + class =3D qdict_get_try_str(error, "class"); > + desc =3D qdict_get_try_str(error, "desc"); > + g_assert_cmpstr(class, =3D=3D, "GenericError"); > + g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled")); > + QDECREF(ret); > + > + /* check something work */ > + ret =3D qmp_fd(fix.fd, "{'execute': 'guest-get-fsinfo'}"); > + qmp_assert_no_error(ret); > + QDECREF(ret); > + > + fixture_tear_down(&fix, NULL); > +} > + > +static void test_qga_fsfreeze_status(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + const gchar *status; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + > + status =3D qdict_get_try_str(ret, "return"); > + g_assert_cmpstr(status, =3D=3D, "thawed"); > + > + QDECREF(ret); > +} > + > +static void test_qga_fsfreeze_and_thaw(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret; > + const gchar *status; > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-freeze'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + QDECREF(ret); > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + status =3D qdict_get_try_str(ret, "return"); > + g_assert_cmpstr(status, =3D=3D, "frozen"); > + QDECREF(ret); > + > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-thaw'}"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + QDECREF(ret); > +} > + > +static gboolean running_in_virt(const gchar *virt) > +{ > + gchar *virt_what =3D NULL; > + gint status; > + gboolean success; > + > + success =3D g_spawn_command_line_sync("virt-what", &virt_what, NULL, > + &status, NULL); > + > + success =3D success && status =3D=3D 0 && g_strcmp0(virt_what, virt); > + > + g_free(virt_what); > + > + return success; > +} > +int main(int argc, char **argv) > +{ > + TestFixture fix; > + int ret; > + > + setlocale (LC_ALL, ""); > + g_test_init(&argc, &argv, NULL); > + fixture_setup(&fix, NULL); > + > + g_test_add_data_func("/qga/sync-delimited", &fix, test_qga_sync_deli= mited); > + g_test_add_data_func("/qga/sync", &fix, test_qga_sync); > + g_test_add_data_func("/qga/ping", &fix, test_qga_ping); > + g_test_add_data_func("/qga/info", &fix, test_qga_info); > + g_test_add_data_func("/qga/network-get-interfaces", &fix, > + test_qga_network_get_interfaces); > + g_test_add_data_func("/qga/get-vcpus", &fix, test_qga_get_vcpus); > + g_test_add_data_func("/qga/get-fsinfo", &fix, test_qga_get_fsinfo); > + g_test_add_data_func("/qga/get-memory-block-info", &fix, > + test_qga_get_memory_block_info); > + g_test_add_data_func("/qga/get-memory-blocks", &fix, > + test_qga_get_memory_blocks); > + g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); > + g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); > + g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); > + g_test_add_data_func("/qga/fsfreeze-status", &fix, > + test_qga_fsfreeze_status); > + > + g_test_add_data_func("/qga/blacklist", NULL, test_qga_blacklist); > + > + if (running_in_virt("kvm")) { > + g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, > + test_qga_fsfreeze_and_thaw); > + g_test_add_data_func("/qga/set-time", &fix, test_qga_set_time); > + if (g_test_thorough()) { > + g_test_add_data_func("/qga/fstrim", &fix, test_qga_fstrim); > + } > + } > + > + ret =3D g_test_run(); > + > + fixture_tear_down(&fix, NULL); > + > + return ret; > +} > -- = > 2.4.3 >=20