X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=tests%2Flibqtest.c;h=a5c3d2bf4852399bf1f2da36a9686e02cafe5b11;hb=b4053c64833762f1249b2d704d2da30b5b10c8ff;hp=e54354de8aa316bcdfc481310b0b39ae310f65ce;hpb=6b4e463ff35284a3c02c5ceab3351bb07137c77c;p=mirror_qemu.git diff --git a/tests/libqtest.c b/tests/libqtest.c index e54354de8a..a5c3d2bf48 100644 --- a/tests/libqtest.c +++ b/tests/libqtest.c @@ -21,6 +21,7 @@ #include #include +#include "qapi/error.h" #include "qapi/qmp/json-parser.h" #include "qapi/qmp/json-streamer.h" #include "qapi/qmp/qjson.h" @@ -149,7 +150,7 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *data) g_hook_prepend(&abrt_hooks, hook); } -QTestState *qtest_init(const char *extra_args) +QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; int sock, qmpsock, i; @@ -204,10 +205,6 @@ QTestState *qtest_init(const char *extra_args) s->irq_level[i] = false; } - /* Read the QMP greeting and then do the handshake */ - qtest_qmp_discard_response(s, ""); - qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); - if (getenv("QTEST_STOP")) { kill(s->qemu_pid, SIGSTOP); } @@ -219,6 +216,17 @@ QTestState *qtest_init(const char *extra_args) return s; } +QTestState *qtest_init(const char *extra_args) +{ + QTestState *s = qtest_init_without_qmp_handshake(extra_args); + + /* Read the QMP greeting and then do the handshake */ + qtest_qmp_discard_response(s, ""); + qtest_qmp_discard_response(s, "{ 'execute': 'qmp_capabilities' }"); + + return s; +} + void qtest_quit(QTestState *s) { qtest_instances = g_list_remove(qtest_instances, s); @@ -435,21 +443,27 @@ void qmp_fd_sendv(int fd, const char *fmt, va_list ap) * is an array type. */ va_copy(ap_copy, ap); - qobj = qobject_from_jsonv(fmt, &ap_copy); + qobj = qobject_from_jsonv(fmt, &ap_copy, &error_abort); va_end(ap_copy); /* No need to send anything for an empty QObject. */ if (qobj) { int log = getenv("QTEST_LOG") != NULL; QString *qstr = qobject_to_json(qobj); - const char *str = qstring_get_str(qstr); - size_t size = qstring_get_length(qstr); + const char *str; + + /* + * BUG: QMP doesn't react to input until it sees a newline, an + * object, or an array. Work-around: give it a newline. + */ + qstring_append_chr(qstr, '\n'); + str = qstring_get_str(qstr); if (log) { fprintf(stderr, "%s", str); } /* Send QMP request */ - socket_send(fd, str, size); + socket_send(fd, str, qstring_get_length(qstr)); QDECREF(qstr); qobject_decref(qobj); @@ -805,17 +819,7 @@ void qtest_add_data_func_full(const char *str, void *data, GDestroyNotify data_free_func) { gchar *path = g_strdup_printf("/%s/%s", qtest_get_arch(), str); -#if GLIB_CHECK_VERSION(2, 34, 0) g_test_add_data_func_full(path, data, fn, data_free_func); -#elif GLIB_CHECK_VERSION(2, 26, 0) - /* back-compat casts, remove this once we can require new-enough glib */ - g_test_add_vtable(path, 0, data, NULL, - (GTestFixtureFunc)fn, (GTestFixtureFunc) data_free_func); -#else - /* back-compat casts, remove this once we can require new-enough glib */ - g_test_add_vtable(path, 0, data, NULL, - (void (*)(void)) fn, (void (*)(void)) data_free_func); -#endif g_free(path); }