static void test_qga_sync_delimited(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_random_int(); unsigned char c; QDict *ret; gchar *cmd; cmd = g_strdup_printf("%c{'execute': 'guest-sync-delimited'," " 'arguments': {'id': %u } }", 0xff, r); qmp_fd_send(fixture->fd, cmd); g_free(cmd); v = read(fixture->fd, &c, 1); g_assert_cmpint(v, ==, 1); g_assert_cmpint(c, ==, 0xff); ret = qmp_fd_receive(fixture->fd); g_assert_nonnull(ret); qmp_assert_no_error(ret); v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); QDECREF(ret); }
static void test_qga_sync(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_random_int(); QDict *ret; /* * TODO guest-sync is inherently limited: we cannot distinguish * failure caused by reacting to garbage on the wire prior to this * command, from failure of this actual command. Clients are * supposed to be able to send a raw '\xff' byte to at least * re-synchronize the server's parser prior to this command, but * we are not in a position to test that here because (at least * for now) it causes the server to issue an error message about * invalid JSON. Testing of '\xff' handling is done in * guest-sync-delimited instead. */ ret = qmp_fd(fixture->fd, "{'execute': 'guest-sync', 'arguments': {'id': %u } }", r); g_assert_nonnull(ret); qmp_assert_no_error(ret); v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); qobject_unref(ret); }
static void test_qga_ping(gconstpointer fix) { const TestFixture *fixture = fix; QDict *ret; ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); QDECREF(ret); }
static void test_qga_info(gconstpointer fix) { const TestFixture *fixture = fix; QDict *ret, *val; const gchar *version; ret = qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); val = qdict_get_qdict(ret, "return"); version = qdict_get_try_str(val, "version"); g_assert_cmpstr(version, ==, QEMU_VERSION); QDECREF(ret); }
static void test_qga_get_vcpus(gconstpointer fix) { const TestFixture *fixture = fix; QDict *ret; QList *list; const QListEntry *entry; ret = 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 = qdict_get_qlist(ret, "return"); entry = 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_sync_delimited(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_random_int(); unsigned char c; QDict *ret; qmp_fd_send_raw(fixture->fd, "\xff"); qmp_fd_send(fixture->fd, "{'execute': 'guest-sync-delimited'," " 'arguments': {'id': %u } }", r); /* * Read and ignore garbage until resynchronized. * * Note that the full reset sequence would involve checking the * response of guest-sync-delimited and repeating the loop if * 'id' field of the response does not match the 'id' field of * the request. Testing this fully would require inserting * garbage in the response stream and is left as a future test * to implement. * * TODO: The server shouldn't emit so much garbage (among other * things, it loudly complains about the client's \xff being * invalid JSON, even though it is a documented part of the * handshake. */ do { v = read(fixture->fd, &c, 1); g_assert_cmpint(v, ==, 1); } while (c != 0xff); ret = qmp_fd_receive(fixture->fd); g_assert_nonnull(ret); qmp_assert_no_error(ret); v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); qobject_unref(ret); }
static void test_qga_sync(gconstpointer fix) { const TestFixture *fixture = fix; guint32 v, r = g_random_int(); QDict *ret; gchar *cmd; cmd = g_strdup_printf("%c{'execute': 'guest-sync'," " 'arguments': {'id': %u } }", 0xff, r); ret = qmp_fd(fixture->fd, cmd); g_free(cmd); g_assert_nonnull(ret); qmp_assert_no_error(ret); v = qdict_get_int(ret, "return"); g_assert_cmpint(r, ==, v); QDECREF(ret); }
static void test_qga_get_fsinfo(gconstpointer fix) { const TestFixture *fixture = fix; QDict *ret; QList *list; const QListEntry *entry; ret = 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 = qdict_get_qlist(ret, "return"); entry = 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_fsinfo(gconstpointer fix) { const TestFixture *fixture = fix; QDict *ret; QList *list; const QListEntry *entry; ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-fsinfo'}"); g_assert_nonnull(ret); qmp_assert_no_error(ret); /* sanity-check the response if there are any filesystems */ list = qdict_get_qlist(ret, "return"); entry = qlist_first(list); if (entry) { 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")); } qobject_unref(ret); }