Commit c542a9f9 authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/armbru/tags/pull-tests-2018-08-16' into staging



Testing patches for 2018-08-16

# gpg: Signature made Thu 16 Aug 2018 09:34:43 BST
# gpg:                using RSA key 3870B400EB918653
# gpg: Good signature from "Markus Armbruster <armbru@redhat.com>"
# gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>"
# Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653

* remotes/armbru/tags/pull-tests-2018-08-16: (25 commits)
  libqtest: Improve error reporting for bad read from QEMU
  tests/libqtest: Improve kill_qemu()
  libqtest: Rename qtest_FOOv() to qtest_vFOO() for consistency
  libqtest: Replace qtest_startf() by qtest_initf()
  libqtest: Enable compile-time format string checking
  migration-test: Clean up string interpolation into QMP, part 3
  migration-test: Clean up string interpolation into QMP, part 2
  migration-test: Clean up string interpolation into QMP, part 1
  migration-test: Make wait_command() cope with '%'
  tests: New helper qtest_qmp_receive_success()
  migration-test: Make wait_command() return the "return" member
  tests: Clean up string interpolation around qtest_qmp_device_add()
  cpu-plug-test: Don't pass integers as strings to device_add
  tests: Clean up string interpolation into QMP input (simple cases)
  tests: Pass literal format strings directly to qmp_FOO()
  qobject: qobject_from_jsonv() is dangerous, hide it away
  test-qobject-input-visitor: Avoid format string ambiguity
  libqtest: Simplify qmp_fd_vsend() a bit
  qobject: New qobject_from_vjsonf_nofail(), qdict_from_vjsonf_nofail()
  qobject: Replace qobject_from_jsonf() by qobject_from_jsonf_nofail()
  ...

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents d3bd57d9 f9e986d2
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -15,11 +15,15 @@
#define QJSON_H

QObject *qobject_from_json(const char *string, Error **errp);
QObject *qobject_from_jsonf(const char *string, ...) GCC_FMT_ATTR(1, 2);
QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp)
    GCC_FMT_ATTR(1, 0);

QDict *qdict_from_jsonf_nofail(const char *string, ...) GCC_FMT_ATTR(1, 2);
QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap)
    GCC_FMT_ATTR(1, 0);
QObject *qobject_from_jsonf_nofail(const char *string, ...)
    GCC_FMT_ATTR(1, 2);
QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap)
    GCC_FMT_ATTR(1, 0);
QDict *qdict_from_jsonf_nofail(const char *string, ...)
    GCC_FMT_ATTR(1, 2);

QString *qobject_to_json(const QObject *obj);
QString *qobject_to_json_pretty(const QObject *obj);
+55 −8
Original line number Diff line number Diff line
@@ -39,7 +39,18 @@ static void parse_json(JSONMessageParser *parser, GQueue *tokens)
    s->result = json_parser_parse_err(tokens, s->ap, &s->err);
}

QObject *qobject_from_jsonv(const char *string, va_list *ap, Error **errp)
/*
 * Parse @string as JSON value.
 * If @ap is non-null, interpolate %-escapes.
 * Takes ownership of %p arguments.
 * On success, return the JSON value.
 * On failure, store an error through @errp and return NULL.
 * Ownership of %p arguments becomes indeterminate then.  To avoid
 * leaks, callers passing %p must terminate on error, e.g. by passing
 * &error_abort.
 */
static QObject *qobject_from_jsonv(const char *string, va_list *ap,
                                   Error **errp)
{
    JSONParsingState state = {};

@@ -59,18 +70,56 @@ QObject *qobject_from_json(const char *string, Error **errp)
    return qobject_from_jsonv(string, NULL, errp);
}

QObject *qobject_from_jsonf(const char *string, ...)
/*
 * Parse @string as JSON value with %-escapes interpolated.
 * Abort on error.  Do not use with untrusted @string.
 * Return the resulting QObject.  It is never null.
 */
QObject *qobject_from_vjsonf_nofail(const char *string, va_list ap)
{
    va_list ap_copy;
    QObject *obj;

    /* va_copy() is needed when va_list is an array type */
    va_copy(ap_copy, ap);
    obj = qobject_from_jsonv(string, &ap_copy, &error_abort);
    va_end(ap_copy);

    assert(obj);
    return obj;
}

/*
 * Parse @string as JSON value with %-escapes interpolated.
 * Abort on error.  Do not use with untrusted @string.
 * Return the resulting QObject.  It is never null.
 */
QObject *qobject_from_jsonf_nofail(const char *string, ...)
{
    QObject *obj;
    va_list ap;

    va_start(ap, string);
    obj = qobject_from_jsonv(string, &ap, &error_abort);
    obj = qobject_from_vjsonf_nofail(string, ap);
    va_end(ap);

    return obj;
}

/*
 * Parse @string as JSON object with %-escapes interpolated.
 * Abort on error.  Do not use with untrusted @string.
 * Return the resulting QDict.  It is never null.
 */
QDict *qdict_from_vjsonf_nofail(const char *string, va_list ap)
{
    QDict *qdict;

    qdict = qobject_to(QDict, qobject_from_vjsonf_nofail(string, ap));
    assert(qdict);
    return qdict;
}

/*
 * Parse @string as JSON object with %-escapes interpolated.
 * Abort on error.  Do not use with untrusted @string.
@@ -78,15 +127,13 @@ QObject *qobject_from_jsonf(const char *string, ...)
 */
QDict *qdict_from_jsonf_nofail(const char *string, ...)
{
    QDict *obj;
    QDict *qdict;
    va_list ap;

    va_start(ap, string);
    obj = qobject_to(QDict, qobject_from_jsonv(string, &ap, &error_abort));
    qdict = qdict_from_vjsonf_nofail(string, ap);
    va_end(ap);

    assert(obj);
    return obj;
    return qdict;
}

typedef struct ToJsonIterState
+8 −7
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@
#include "hw/pci/pci_ids.h"
#include "hw/pci/pci_regs.h"

/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))

/* Test images sizes in MB */
#define TEST_IMAGE_SIZE_MB_LARGE (200 * 1024)
#define TEST_IMAGE_SIZE_MB_SMALL 64
@@ -1352,7 +1355,6 @@ static void test_flush_migrate(void)
    AHCIQState *src, *dst;
    AHCICommand *cmd;
    uint8_t px;
    const char *s;
    char *uri = g_strdup_printf("unix:%s", mig_socket);

    prepare_blkdebug_script(debug_path, "flush_to_disk");
@@ -1388,8 +1390,7 @@ static void test_flush_migrate(void)
    ahci_migrate(src, dst, uri);

    /* Complete the command */
    s = "{'execute':'cont' }";
    qmp_async(s);
    qmp_send("{'execute':'cont' }");
    qmp_eventwait("RESUME");
    ahci_command_wait(dst, cmd);
    ahci_command_verify(dst, cmd);
@@ -1592,7 +1593,7 @@ static void test_atapi_tray(void)
    atapi_wait_tray(false);

    /* Remove media */
    qmp_async("{'execute': 'blockdev-open-tray', "
    qmp_send("{'execute': 'blockdev-open-tray',"
             " 'arguments': {'id': 'cd0'}}");
    atapi_wait_tray(true);
    rsp = qmp_receive();
@@ -1619,7 +1620,7 @@ static void test_atapi_tray(void)
                                         "'node-name': 'node0' }}");

    /* Again, the event shows up first */
    qmp_async("{'execute': 'blockdev-close-tray', "
    qmp_send("{'execute': 'blockdev-close-tray',"
             " 'arguments': {'id': 'cd0'}}");
    atapi_wait_tray(false);
    rsp = qmp_receive();
+8 −5
Original line number Diff line number Diff line
@@ -13,9 +13,12 @@
#include "qemu/osdep.h"
#include "libqos/fw_cfg.h"
#include "libqtest.h"

#include "qapi/qmp/qdict.h"
#include "hw/nvram/fw_cfg_keys.h"

/* TODO actually test the results and get rid of this */
#define qmp_discard_response(...) qobject_unref(qmp(__VA_ARGS__))

typedef struct {
    const char *args;
    uint64_t expected_boot;
@@ -30,7 +33,7 @@ static void test_a_boot_order(const char *machine,
{
    uint64_t actual;

    global_qtest = qtest_startf("-nodefaults%s%s %s",
    global_qtest = qtest_initf("-nodefaults%s%s %s",
                               machine ? " -M " : "",
                               machine ?: "",
                               test_args);
+5 −5
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ static void test_machine(const void *data)
     * Make sure that this test uses tcg if available: It is used as a
     * fast-enough smoketest for that.
     */
    global_qtest = qtest_startf("%s %s -M %s,accel=tcg:kvm "
    global_qtest = qtest_initf("%s %s -M %s,accel=tcg:kvm "
                               "-chardev file,id=serial0,path=%s "
                               "-no-shutdown -serial chardev:serial0 %s",
                               codeparam, code ? codetmp : "",
Loading