Ejemplo n.º 1
0
static void test_baddest(void)
{
    QTestState *from, *to;
    QDict *rsp, *rsp_return;
    const char *status;
    bool failed;

    test_migrate_start(&from, &to, "tcp:0:0", true);
    migrate(from, "tcp:0:0");
    do {
        rsp = wait_command(from, "{ 'execute': 'query-migrate' }");
        rsp_return = qdict_get_qdict(rsp, "return");

        status = qdict_get_str(rsp_return, "status");

        g_assert(!strcmp(status, "setup") || !(strcmp(status, "failed")));
        failed = !strcmp(status, "failed");
        qobject_unref(rsp);
    } while (!failed);

    /* Is the machine currently running? */
    rsp = wait_command(from, "{ 'execute': 'query-status' }");
    g_assert(qdict_haskey(rsp, "return"));
    rsp_return = qdict_get_qdict(rsp, "return");
    g_assert(qdict_haskey(rsp_return, "running"));
    g_assert(qdict_get_bool(rsp_return, "running"));
    qobject_unref(rsp);

    test_migrate_end(from, to, false);
}
Ejemplo n.º 2
0
static void qdict_crumple_test_recursive(void)
{
    QDict *src, *dst, *rule, *vnc, *acl, *listen;
    QList *rules;

    src = qdict_new();
    qdict_put(src, "vnc.listen.addr", qstring_from_str("127.0.0.1"));
    qdict_put(src, "vnc.listen.port", qstring_from_str("5901"));
    qdict_put(src, "vnc.acl.rules.0.match", qstring_from_str("fred"));
    qdict_put(src, "vnc.acl.rules.0.policy", qstring_from_str("allow"));
    qdict_put(src, "vnc.acl.rules.1.match", qstring_from_str("bob"));
    qdict_put(src, "vnc.acl.rules.1.policy", qstring_from_str("deny"));
    qdict_put(src, "vnc.acl.default", qstring_from_str("deny"));
    qdict_put(src, "vnc.acl..name", qstring_from_str("acl0"));
    qdict_put(src, "vnc.acl.rule..name", qstring_from_str("acl0"));

    dst = qobject_to_qdict(qdict_crumple(src, &error_abort));
    g_assert(dst);
    g_assert_cmpint(qdict_size(dst), ==, 1);

    vnc = qdict_get_qdict(dst, "vnc");
    g_assert(vnc);
    g_assert_cmpint(qdict_size(vnc), ==, 3);

    listen = qdict_get_qdict(vnc, "listen");
    g_assert(listen);
    g_assert_cmpint(qdict_size(listen), ==, 2);
    g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr"));
    g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port"));

    acl = qdict_get_qdict(vnc, "acl");
    g_assert(acl);
    g_assert_cmpint(qdict_size(acl), ==, 3);

    rules = qdict_get_qlist(acl, "rules");
    g_assert(rules);
    g_assert_cmpint(qlist_size(rules), ==, 2);

    rule = qobject_to_qdict(qlist_pop(rules));
    g_assert(rule);
    g_assert_cmpint(qdict_size(rule), ==, 2);
    g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match"));
    g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));
    QDECREF(rule);

    rule = qobject_to_qdict(qlist_pop(rules));
    g_assert(rule);
    g_assert_cmpint(qdict_size(rule), ==, 2);
    g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match"));
    g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
    QDECREF(rule);

    /* With recursive crumpling, we should see all names unescaped */
    g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name"));
    g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));

    QDECREF(src);
    QDECREF(dst);
}
Ejemplo n.º 3
0
/* test commands that involve both input parameters and return values */
static void test_dispatch_cmd_io(void)
{
    QDict *req = qdict_new();
    QDict *args = qdict_new();
    QDict *args3 = qdict_new();
    QDict *ud1a = qdict_new();
    QDict *ud1b = qdict_new();
    QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef;
    QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
    QNum *ret3;
    int64_t val;

    qdict_put_int(ud1a, "integer", 42);
    qdict_put_str(ud1a, "string", "hello");
    qdict_put_int(ud1b, "integer", 422);
    qdict_put_str(ud1b, "string", "hello2");
    qdict_put(args, "ud1a", ud1a);
    qdict_put(args, "ud1b", ud1b);
    qdict_put(req, "arguments", args);
    qdict_put_str(req, "execute", "user_def_cmd2");

    ret = qobject_to(QDict, test_qmp_dispatch(req));

    assert(!strcmp(qdict_get_str(ret, "string0"), "blah1"));
    ret_dict = qdict_get_qdict(ret, "dict1");
    assert(!strcmp(qdict_get_str(ret_dict, "string1"), "blah2"));
    ret_dict_dict = qdict_get_qdict(ret_dict, "dict2");
    ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef");
    assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42);
    assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello"));
    assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3"));
    ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict3");
    ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef");
    assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422);
    assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2"));
    assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4"));
    qobject_unref(ret);

    qdict_put_int(args3, "a", 66);
    qdict_put(req, "arguments", args3);
    qdict_put_str(req, "execute", "guest-get-time");

    ret3 = qobject_to(QNum, test_qmp_dispatch(req));
    g_assert(qnum_get_try_int(ret3, &val));
    g_assert_cmpint(val, ==, 66);
    qobject_unref(ret3);

    qobject_unref(req);
}
Ejemplo n.º 4
0
/* test commands that involve both input parameters and return values */
static void test_dispatch_cmd_io(void)
{
    QDict *req = qdict_new();
    QDict *args = qdict_new();
    QDict *args3 = qdict_new();
    QDict *ud1a = qdict_new();
    QDict *ud1b = qdict_new();
    QDict *ret, *ret_dict, *ret_dict_dict, *ret_dict_dict_userdef;
    QDict *ret_dict_dict2, *ret_dict_dict2_userdef;
    QInt *ret3;

    qdict_put_obj(ud1a, "integer", QOBJECT(qint_from_int(42)));
    qdict_put_obj(ud1a, "string", QOBJECT(qstring_from_str("hello")));
    qdict_put_obj(ud1b, "integer", QOBJECT(qint_from_int(422)));
    qdict_put_obj(ud1b, "string", QOBJECT(qstring_from_str("hello2")));
    qdict_put_obj(args, "ud1a", QOBJECT(ud1a));
    qdict_put_obj(args, "ud1b", QOBJECT(ud1b));
    qdict_put_obj(req, "arguments", QOBJECT(args));
    qdict_put_obj(req, "execute", QOBJECT(qstring_from_str("user_def_cmd2")));

    ret = qobject_to_qdict(test_qmp_dispatch(req));

    assert(!strcmp(qdict_get_str(ret, "string0"), "blah1"));
    ret_dict = qdict_get_qdict(ret, "dict1");
    assert(!strcmp(qdict_get_str(ret_dict, "string1"), "blah2"));
    ret_dict_dict = qdict_get_qdict(ret_dict, "dict2");
    ret_dict_dict_userdef = qdict_get_qdict(ret_dict_dict, "userdef");
    assert(qdict_get_int(ret_dict_dict_userdef, "integer") == 42);
    assert(!strcmp(qdict_get_str(ret_dict_dict_userdef, "string"), "hello"));
    assert(!strcmp(qdict_get_str(ret_dict_dict, "string"), "blah3"));
    ret_dict_dict2 = qdict_get_qdict(ret_dict, "dict3");
    ret_dict_dict2_userdef = qdict_get_qdict(ret_dict_dict2, "userdef");
    assert(qdict_get_int(ret_dict_dict2_userdef, "integer") == 422);
    assert(!strcmp(qdict_get_str(ret_dict_dict2_userdef, "string"), "hello2"));
    assert(!strcmp(qdict_get_str(ret_dict_dict2, "string"), "blah4"));
    QDECREF(ret);

    qdict_put(args3, "a", qint_from_int(66));
    qdict_put(req, "arguments", args3);
    qdict_put(req, "execute", qstring_from_str("guest-get-time"));

    ret3 = qobject_to_qint(test_qmp_dispatch(req));
    assert(qint_get_int(ret3) == 66);
    QDECREF(ret3);

    QDECREF(req);
}
Ejemplo n.º 5
0
static uint64_t get_migration_pass(QTestState *who)
{
    QDict *rsp, *rsp_return, *rsp_ram;
    uint64_t result;

    rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
    rsp_return = qdict_get_qdict(rsp, "return");
    if (!qdict_haskey(rsp_return, "ram")) {
        /* Still in setup */
        result = 0;
    } else {
        rsp_ram = qdict_get_qdict(rsp_return, "ram");
        result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
    }
    qobject_unref(rsp);
    return result;
}
Ejemplo n.º 6
0
static uint64_t get_migration_pass(void)
{
    QDict *rsp, *rsp_return, *rsp_ram;
    uint64_t result;

    rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
    rsp_return = qdict_get_qdict(rsp, "return");
    if (!qdict_haskey(rsp_return, "ram")) {
        /* Still in setup */
        result = 0;
    } else {
        rsp_ram = qdict_get_qdict(rsp_return, "ram");
        result = qdict_get_try_int(rsp_ram, "dirty-sync-count", 0);
    }
    QDECREF(rsp);
    return result;
}
Ejemplo n.º 7
0
static void read_blocktime(QTestState *who)
{
    QDict *rsp, *rsp_return;

    rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
    rsp_return = qdict_get_qdict(rsp, "return");
    g_assert(qdict_haskey(rsp_return, "postcopy-blocktime"));
    qobject_unref(rsp);
}
Ejemplo n.º 8
0
const char *error_get_field(Error *err, const char *field)
{
    if (strcmp(field, "class") == 0) {
        return qdict_get_str(err->obj, field);
    } else {
        QDict *dict = qdict_get_qdict(err->obj, "data");
        return qdict_get_str(dict, field);
    }
}
Ejemplo n.º 9
0
static QDict *get_watchdog_action(void)
{
    QDict *ev = qmp_eventwait_ref("WATCHDOG");
    QDict *data;

    data = qdict_get_qdict(ev, "data");
    qobject_ref(data);
    qobject_unref(ev);
    return data;
}
Ejemplo n.º 10
0
static void migrate_check_parameter(QTestState *who, const char *parameter,
                                    const char *value)
{
    QDict *rsp, *rsp_return;
    char *result;

    rsp = wait_command(who, "{ 'execute': 'query-migrate-parameters' }");
    rsp_return = qdict_get_qdict(rsp, "return");
    result = g_strdup_printf("%" PRId64,
                             qdict_get_try_int(rsp_return,  parameter, -1));
    g_assert_cmpstr(result, ==, value);
    g_free(result);
    qobject_unref(rsp);
}
Ejemplo n.º 11
0
static QObject *do_qmp_dispatch(QObject *request, Error **errp)
{
    Error *local_err = NULL;
    const char *command;
    QDict *args, *dict;
    QmpCommand *cmd;
    QObject *ret = NULL;

    dict = qmp_dispatch_check_obj(request, errp);
    if (!dict) {
        return NULL;
    }

    command = qdict_get_str(dict, "execute");
    cmd = qmp_find_command(command);
    if (cmd == NULL) {
        error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
                  "The command %s has not been found", command);
        return NULL;
    }
    if (!cmd->enabled) {
        error_setg(errp, "The command %s has been disabled for this instance",
                   command);
        return NULL;
    }

    if (!qdict_haskey(dict, "arguments")) {
        args = qdict_new();
    } else {
        args = qdict_get_qdict(dict, "arguments");
        QINCREF(args);
    }

    switch (cmd->type) {
    case QCT_NORMAL:
        cmd->fn(args, &ret, &local_err);
        if (local_err) {
            error_propagate(errp, local_err);
        } else if (cmd->options & QCO_NO_SUCCESS_RESP) {
            g_assert(!ret);
        } else if (!ret) {
            ret = QOBJECT(qdict_new());
        }
        break;
    }

    QDECREF(args);

    return ret;
}
Ejemplo n.º 12
0
static void test_qga_invalid_id(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    QDict *ret, *error;
    const char *class;

    ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}");
    g_assert_nonnull(ret);

    error = qdict_get_qdict(ret, "error");
    class = qdict_get_try_str(error, "class");
    g_assert_cmpstr(class, ==, "GenericError");

    qobject_unref(ret);
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
0
static void test_qga_get_memory_block_info(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    QDict *ret, *val;
    int64_t size;

    ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'}");
    g_assert_nonnull(ret);

    /* some systems might not expose memory block info in sysfs */
    if (!qdict_haskey(ret, "error")) {
        /* check there is at least some memory */
        val = qdict_get_qdict(ret, "return");
        size = qdict_get_int(val, "size");
        g_assert_cmpint(size, >, 0);
    }
Ejemplo n.º 15
0
static void wait_for_migration_complete(void)
{
    QDict *rsp, *rsp_return;
    bool completed;

    do {
        const char *status;

        rsp = return_or_event(qmp("{ 'execute': 'query-migrate' }"));
        rsp_return = qdict_get_qdict(rsp, "return");
        status = qdict_get_str(rsp_return, "status");
        completed = strcmp(status, "completed") == 0;
        g_assert_cmpstr(status, !=,  "failed");
        QDECREF(rsp);
        usleep(1000 * 100);
    } while (!completed);
}
Ejemplo n.º 16
0
static void test_qga_invalid_cmd(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    QDict *ret, *error;
    const gchar *class, *desc;

    ret = qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}");
    g_assert_nonnull(ret);

    error = qdict_get_qdict(ret, "error");
    class = qdict_get_try_str(error, "class");
    desc = qdict_get_try_str(error, "desc");

    g_assert_cmpstr(class, ==, "CommandNotFound");
    g_assert_cmpint(strlen(desc), >, 0);

    QDECREF(ret);
}
Ejemplo n.º 17
0
static void test_panic(void)
{
    uint8_t val;
    QDict *response, *data;

    val = inb(0x505);
    g_assert_cmpuint(val, ==, 1);

    outb(0x505, 0x1);

    response = qmp_receive();
    g_assert(qdict_haskey(response, "event"));
    g_assert_cmpstr(qdict_get_str(response, "event"), ==, "GUEST_PANICKED");
    g_assert(qdict_haskey(response, "data"));
    data = qdict_get_qdict(response, "data");
    g_assert(qdict_haskey(data, "action"));
    g_assert_cmpstr(qdict_get_str(data, "action"), ==, "pause");
}
Ejemplo n.º 18
0
static QObject *do_qmp_dispatch(QObject *request, Error **errp)
{
    const char *command;
    QDict *args, *dict;
    QmpCommand *cmd;
    QObject *ret = NULL;


    dict = qmp_dispatch_check_obj(request, errp);
    if (!dict || error_is_set(errp)) {
        return NULL;
    }

    command = qdict_get_str(dict, "execute");
    cmd = qmp_find_command(command);
    if (cmd == NULL) {
        error_set(errp, QERR_COMMAND_NOT_FOUND, command);
        return NULL;
    }
    if (!cmd->enabled) {
        error_set(errp, QERR_COMMAND_DISABLED, command);
        return NULL;
    }

    if (!qdict_haskey(dict, "arguments")) {
        args = qdict_new();
    } else {
        args = qdict_get_qdict(dict, "arguments");
        QINCREF(args);
    }

    switch (cmd->type) {
    case QCT_NORMAL:
        cmd->fn(args, &ret, errp);
        if (!error_is_set(errp) && ret == NULL) {
            ret = QOBJECT(qdict_new());
        }
        break;
    }

    QDECREF(args);

    return ret;
}
Ejemplo n.º 19
0
static void wait_for_migration_complete(QTestState *who)
{
    while (true) {
        QDict *rsp, *rsp_return;
        bool completed;
        const char *status;

        rsp = wait_command(who, "{ 'execute': 'query-migrate' }");
        rsp_return = qdict_get_qdict(rsp, "return");
        status = qdict_get_str(rsp_return, "status");
        completed = strcmp(status, "completed") == 0;
        g_assert_cmpstr(status, !=,  "failed");
        qobject_unref(rsp);
        if (completed) {
            return;
        }
        usleep(1000);
    }
}
Ejemplo n.º 20
0
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 = qdict_get_qdict(dict, "error");
    class = qdict_get_try_str(error, "class");
    desc = qdict_get_try_str(error, "desc");

    s = g_strdup_printf("assertion failed %s: %s %s", expr, class, desc);
    g_assertion_message(domain, file, line, func, s);
    g_free(s);
}
Ejemplo n.º 21
0
static void test_qga_invalid_args(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    QDict *ret, *error;
    const gchar *class, *desc;

    ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', "
                 "'arguments': {'foo': 42 }}");
    g_assert_nonnull(ret);

    error = qdict_get_qdict(ret, "error");
    class = qdict_get_try_str(error, "class");
    desc = qdict_get_try_str(error, "desc");

    g_assert_cmpstr(class, ==, "GenericError");
    g_assert_cmpstr(desc, ==, "Parameter 'foo' is unexpected");

    qobject_unref(ret);
}
Ejemplo n.º 22
0
/* This function is hooked as final emit function, which can verify the
   correctness. */
static void event_test_emit(test_QAPIEvent event, QDict *d, Error **errp)
{
    QDict *t;
    int64_t s, ms;

    /* Verify that we have timestamp, then remove it to compare other fields */
    t = qdict_get_qdict(d, "timestamp");
    g_assert(t);
    s = qdict_get_try_int(t, "seconds", -2);
    ms = qdict_get_try_int(t, "microseconds", -2);
    if (s == -1) {
        g_assert(ms == -1);
    } else {
        g_assert(s >= 0);
        g_assert(ms >= 0 && ms <= 999999);
    }
    g_assert(qdict_size(t) == 2);

    qdict_del(d, "timestamp");

    g_assert(qdict_cmp_simple(d, test_event_data->expect));

}
Ejemplo n.º 23
0
static void qdict_flatten_test(void)
{
    QList *e_1 = qlist_new();
    QList *e = qlist_new();
    QDict *e_1_2 = qdict_new();
    QDict *f = qdict_new();
    QList *y = qlist_new();
    QDict *z = qdict_new();
    QDict *root = qdict_new();

    /*
     * Test the flattening of
     *
     * {
     *     "e": [
     *         42,
     *         [
     *             23,
     *             66,
     *             {
     *                 "a": 0,
     *                 "b": 1
     *             }
     *         ]
     *     ],
     *     "f": {
     *         "c": 2,
     *         "d": 3,
     *     },
     *     "g": 4,
     *     "y": [{}],
     *     "z": {"a": []}
     * }
     *
     * to
     *
     * {
     *     "e.0": 42,
     *     "e.1.0": 23,
     *     "e.1.1": 66,
     *     "e.1.2.a": 0,
     *     "e.1.2.b": 1,
     *     "f.c": 2,
     *     "f.d": 3,
     *     "g": 4,
     *     "y.0": {},
     *     "z.a": []
     * }
     */

    qdict_put_int(e_1_2, "a", 0);
    qdict_put_int(e_1_2, "b", 1);

    qlist_append_int(e_1, 23);
    qlist_append_int(e_1, 66);
    qlist_append(e_1, e_1_2);
    qlist_append_int(e, 42);
    qlist_append(e, e_1);

    qdict_put_int(f, "c", 2);
    qdict_put_int(f, "d", 3);

    qlist_append(y, qdict_new());

    qdict_put(z, "a", qlist_new());

    qdict_put(root, "e", e);
    qdict_put(root, "f", f);
    qdict_put_int(root, "g", 4);
    qdict_put(root, "y", y);
    qdict_put(root, "z", z);

    qdict_flatten(root);

    g_assert(qdict_get_int(root, "e.0") == 42);
    g_assert(qdict_get_int(root, "e.1.0") == 23);
    g_assert(qdict_get_int(root, "e.1.1") == 66);
    g_assert(qdict_get_int(root, "e.1.2.a") == 0);
    g_assert(qdict_get_int(root, "e.1.2.b") == 1);
    g_assert(qdict_get_int(root, "f.c") == 2);
    g_assert(qdict_get_int(root, "f.d") == 3);
    g_assert(qdict_get_int(root, "g") == 4);
    g_assert(!qdict_size(qdict_get_qdict(root, "y.0")));
    g_assert(qlist_empty(qdict_get_qlist(root, "z.a")));

    g_assert(qdict_size(root) == 10);

    qobject_unref(root);
}
Ejemplo n.º 24
0
Archivo: libqos.c Proyecto: stweil/qemu
void migrate(QOSState *from, QOSState *to, const char *uri)
{
    const char *st;
    QDict *rsp, *sub;
    bool running;

    set_context(from);

    /* Is the machine currently running? */
    rsp = qmp_execute(from->qts, "query-status");
    g_assert(qdict_haskey(rsp, "return"));
    sub = qdict_get_qdict(rsp, "return");
    g_assert(qdict_haskey(sub, "running"));
    running = qdict_get_bool(sub, "running");
    qobject_unref(rsp);

    /* Issue the migrate command. */
    rsp = qtest_qmp(from->qts,
                    "{ 'execute': 'migrate', 'arguments': { 'uri': %s }}",
                    uri);
    g_assert(qdict_haskey(rsp, "return"));
    qobject_unref(rsp);

    /* Wait for STOP event, but only if we were running: */
    if (running) {
        qtest_qmp_eventwait(from->qts, "STOP");
    }

    /* If we were running, we can wait for an event. */
    if (running) {
        migrate_allocator(from->alloc, to->alloc);
        set_context(to);
        qtest_qmp_eventwait(to->qts, "RESUME");
        return;
    }

    /* Otherwise, we need to wait: poll until migration is completed. */
    while (1) {
        rsp = qmp_execute(from->qts, "query-migrate");
        g_assert(qdict_haskey(rsp, "return"));
        sub = qdict_get_qdict(rsp, "return");
        g_assert(qdict_haskey(sub, "status"));
        st = qdict_get_str(sub, "status");

        /* "setup", "active", "completed", "failed", "cancelled" */
        if (strcmp(st, "completed") == 0) {
            qobject_unref(rsp);
            break;
        }

        if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0)) {
            qobject_unref(rsp);
            g_usleep(5000);
            continue;
        }

        fprintf(stderr, "Migration did not complete, status: %s\n", st);
        g_assert_not_reached();
    }

    migrate_allocator(from->alloc, to->alloc);
    set_context(to);
}
Ejemplo n.º 25
0
static QObject *do_qmp_dispatch(QmpCommandList *cmds, QObject *request,
                                bool allow_oob, Error **errp)
{
    Error *local_err = NULL;
    bool oob;
    const char *command;
    QDict *args, *dict;
    QmpCommand *cmd;
    QObject *ret = NULL;

    dict = qmp_dispatch_check_obj(request, allow_oob, errp);
    if (!dict) {
        return NULL;
    }

    command = qdict_get_try_str(dict, "execute");
    oob = false;
    if (!command) {
        assert(allow_oob);
        command = qdict_get_str(dict, "exec-oob");
        oob = true;
    }
    cmd = qmp_find_command(cmds, command);
    if (cmd == NULL) {
        error_set(errp, ERROR_CLASS_COMMAND_NOT_FOUND,
                  "The command %s has not been found", command);
        return NULL;
    }
    if (!cmd->enabled) {
        error_setg(errp, "The command %s has been disabled for this instance",
                   command);
        return NULL;
    }
    if (oob && !(cmd->options & QCO_ALLOW_OOB)) {
        error_setg(errp, "The command %s does not support OOB",
                   command);
        return NULL;
    }

    if (runstate_check(RUN_STATE_PRECONFIG) &&
        !(cmd->options & QCO_ALLOW_PRECONFIG)) {
        error_setg(errp, "The command '%s' isn't permitted in '%s' state",
                   cmd->name, RunState_str(RUN_STATE_PRECONFIG));
        return NULL;
    }

    if (!qdict_haskey(dict, "arguments")) {
        args = qdict_new();
    } else {
        args = qdict_get_qdict(dict, "arguments");
        qobject_ref(args);
    }

    cmd->fn(args, &ret, &local_err);
    if (local_err) {
        error_propagate(errp, local_err);
    } else if (cmd->options & QCO_NO_SUCCESS_RESP) {
        g_assert(!ret);
    } else if (!ret) {
        /* TODO turn into assertion */
        ret = QOBJECT(qdict_new());
    }

    qobject_unref(args);

    return ret;
}
Ejemplo n.º 26
0
QDict *error_get_data(Error *err)
{
    QDict *data = qdict_get_qdict(err->obj, "data");
    QINCREF(data);
    return data;
}
Ejemplo n.º 27
0
void error_set_field(Error *err, const char *field, const char *value)
{
    QDict *dict = qdict_get_qdict(err->obj, "data");
    return qdict_put(dict, field, qstring_from_str(value));
}
Ejemplo n.º 28
0
static void qobject_is_equal_dict_test(void)
{
    Error *local_err = NULL;
    QDict *dict_0, *dict_1, *dict_cloned;
    QDict *dict_different_key, *dict_different_value, *dict_different_null_key;
    QDict *dict_longer, *dict_shorter, *dict_nested;
    QDict *dict_crumpled;

    dict_0 = qdict_new();
    dict_1 = qdict_new();
    dict_different_key = qdict_new();
    dict_different_value = qdict_new();
    dict_different_null_key = qdict_new();
    dict_longer = qdict_new();
    dict_shorter = qdict_new();
    dict_nested = qdict_new();

    qdict_put_int(dict_0, "f.o", 1);
    qdict_put_int(dict_0, "bar", 2);
    qdict_put_int(dict_0, "baz", 3);
    qdict_put_null(dict_0, "null");

    qdict_put_int(dict_1, "f.o", 1);
    qdict_put_int(dict_1, "bar", 2);
    qdict_put_int(dict_1, "baz", 3);
    qdict_put_null(dict_1, "null");

    qdict_put_int(dict_different_key, "F.o", 1);
    qdict_put_int(dict_different_key, "bar", 2);
    qdict_put_int(dict_different_key, "baz", 3);
    qdict_put_null(dict_different_key, "null");

    qdict_put_int(dict_different_value, "f.o", 42);
    qdict_put_int(dict_different_value, "bar", 2);
    qdict_put_int(dict_different_value, "baz", 3);
    qdict_put_null(dict_different_value, "null");

    qdict_put_int(dict_different_null_key, "f.o", 1);
    qdict_put_int(dict_different_null_key, "bar", 2);
    qdict_put_int(dict_different_null_key, "baz", 3);
    qdict_put_null(dict_different_null_key, "none");

    qdict_put_int(dict_longer, "f.o", 1);
    qdict_put_int(dict_longer, "bar", 2);
    qdict_put_int(dict_longer, "baz", 3);
    qdict_put_int(dict_longer, "xyz", 4);
    qdict_put_null(dict_longer, "null");

    qdict_put_int(dict_shorter, "f.o", 1);
    qdict_put_int(dict_shorter, "bar", 2);
    qdict_put_int(dict_shorter, "baz", 3);

    qdict_put(dict_nested, "f", qdict_new());
    qdict_put_int(qdict_get_qdict(dict_nested, "f"), "o", 1);
    qdict_put_int(dict_nested, "bar", 2);
    qdict_put_int(dict_nested, "baz", 3);
    qdict_put_null(dict_nested, "null");

    dict_cloned = qdict_clone_shallow(dict_0);

    check_equal(dict_0, dict_1, dict_cloned);
    check_unequal(dict_0, dict_different_key, dict_different_value,
                  dict_different_null_key, dict_longer, dict_shorter,
                  dict_nested);

    dict_crumpled = qobject_to(QDict, qdict_crumple(dict_1, &local_err));
    g_assert(!local_err);
    check_equal(dict_crumpled, dict_nested);

    qdict_flatten(dict_nested);
    check_equal(dict_0, dict_nested);

    /* Containing an NaN value will make this dict compare unequal to
     * itself */
    qdict_put(dict_0, "NaN", qnum_from_double(NAN));
    g_assert(qobject_is_equal(QOBJECT(dict_0), QOBJECT(dict_0)) == false);

    free_all(dict_0, dict_1, dict_cloned, dict_different_key,
             dict_different_value, dict_different_null_key, dict_longer,
             dict_shorter, dict_nested, dict_crumpled);
}
Ejemplo n.º 29
0
static void qdict_crumple_test_recursive(void)
{
    QDict *src, *dst, *rule, *vnc, *acl, *listen;
    QDict *empty, *empty_dict, *empty_list_0;
    QList *rules, *empty_list, *empty_dict_a;

    src = qdict_new();
    qdict_put_str(src, "vnc.listen.addr", "127.0.0.1");
    qdict_put_str(src, "vnc.listen.port", "5901");
    qdict_put_str(src, "vnc.acl.rules.0.match", "fred");
    qdict_put_str(src, "vnc.acl.rules.0.policy", "allow");
    qdict_put_str(src, "vnc.acl.rules.1.match", "bob");
    qdict_put_str(src, "vnc.acl.rules.1.policy", "deny");
    qdict_put_str(src, "vnc.acl.default", "deny");
    qdict_put_str(src, "vnc.acl..name", "acl0");
    qdict_put_str(src, "vnc.acl.rule..name", "acl0");
    qdict_put(src, "empty.dict.a", qlist_new());
    qdict_put(src, "empty.list.0", qdict_new());

    dst = qobject_to(QDict, qdict_crumple(src, &error_abort));
    g_assert(dst);
    g_assert_cmpint(qdict_size(dst), ==, 2);

    vnc = qdict_get_qdict(dst, "vnc");
    g_assert(vnc);
    g_assert_cmpint(qdict_size(vnc), ==, 3);

    listen = qdict_get_qdict(vnc, "listen");
    g_assert(listen);
    g_assert_cmpint(qdict_size(listen), ==, 2);
    g_assert_cmpstr("127.0.0.1", ==, qdict_get_str(listen, "addr"));
    g_assert_cmpstr("5901", ==, qdict_get_str(listen, "port"));

    acl = qdict_get_qdict(vnc, "acl");
    g_assert(acl);
    g_assert_cmpint(qdict_size(acl), ==, 3);

    rules = qdict_get_qlist(acl, "rules");
    g_assert(rules);
    g_assert_cmpint(qlist_size(rules), ==, 2);

    rule = qobject_to(QDict, qlist_pop(rules));
    g_assert(rule);
    g_assert_cmpint(qdict_size(rule), ==, 2);
    g_assert_cmpstr("fred", ==, qdict_get_str(rule, "match"));
    g_assert_cmpstr("allow", ==, qdict_get_str(rule, "policy"));
    qobject_unref(rule);

    rule = qobject_to(QDict, qlist_pop(rules));
    g_assert(rule);
    g_assert_cmpint(qdict_size(rule), ==, 2);
    g_assert_cmpstr("bob", ==, qdict_get_str(rule, "match"));
    g_assert_cmpstr("deny", ==, qdict_get_str(rule, "policy"));
    qobject_unref(rule);

    /* With recursive crumpling, we should see all names unescaped */
    g_assert_cmpstr("acl0", ==, qdict_get_str(vnc, "acl.name"));
    g_assert_cmpstr("acl0", ==, qdict_get_str(acl, "rule.name"));

    empty = qdict_get_qdict(dst, "empty");
    g_assert(empty);
    g_assert_cmpint(qdict_size(empty), ==, 2);
    empty_dict = qdict_get_qdict(empty, "dict");
    g_assert(empty_dict);
    g_assert_cmpint(qdict_size(empty_dict), ==, 1);
    empty_dict_a = qdict_get_qlist(empty_dict, "a");
    g_assert(empty_dict_a && qlist_empty(empty_dict_a));
    empty_list = qdict_get_qlist(empty, "list");
    g_assert(empty_list);
    g_assert_cmpint(qlist_size(empty_list), ==, 1);
    empty_list_0 = qobject_to(QDict, qlist_pop(empty_list));
    g_assert(empty_list_0);
    g_assert_cmpint(qdict_size(empty_list_0), ==, 0);

    qobject_unref(src);
    qobject_unref(dst);
}