Example #1
0
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);
}
Example #2
0
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);
}