4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 * Copyright SUSE LINUX Products GmbH 2013
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
11 * Andreas Färber <afaerber@suse.de>
13 * This work is licensed under the terms of the GNU GPL, version 2 or later.
14 * See the COPYING file in the top-level directory.
17 #include "qemu/osdep.h"
20 #include <sys/socket.h>
24 #include "qapi/error.h"
25 #include "qapi/qmp/json-parser.h"
26 #include "qapi/qmp/json-streamer.h"
27 #include "qapi/qmp/qjson.h"
30 #define SOCKET_TIMEOUT 50
32 QTestState
*global_qtest
;
38 bool irq_level
[MAX_IRQ
];
40 pid_t qemu_pid
; /* our child QEMU process */
44 static GHookList abrt_hooks
;
45 static struct sigaction sigact_old
;
47 #define g_assert_no_errno(ret) do { \
48 g_assert_cmpint(ret, !=, -1); \
51 static int qtest_query_target_endianness(QTestState
*s
);
53 static int init_socket(const char *socket_path
)
55 struct sockaddr_un addr
;
59 sock
= socket(PF_UNIX
, SOCK_STREAM
, 0);
60 g_assert_no_errno(sock
);
62 addr
.sun_family
= AF_UNIX
;
63 snprintf(addr
.sun_path
, sizeof(addr
.sun_path
), "%s", socket_path
);
64 qemu_set_cloexec(sock
);
67 ret
= bind(sock
, (struct sockaddr
*)&addr
, sizeof(addr
));
68 } while (ret
== -1 && errno
== EINTR
);
69 g_assert_no_errno(ret
);
70 ret
= listen(sock
, 1);
71 g_assert_no_errno(ret
);
76 static int socket_accept(int sock
)
78 struct sockaddr_un addr
;
81 struct timeval timeout
= { .tv_sec
= SOCKET_TIMEOUT
,
84 setsockopt(sock
, SOL_SOCKET
, SO_RCVTIMEO
, (void *)&timeout
,
88 addrlen
= sizeof(addr
);
89 ret
= accept(sock
, (struct sockaddr
*)&addr
, &addrlen
);
90 } while (ret
== -1 && errno
== EINTR
);
92 fprintf(stderr
, "%s failed: %s\n", __func__
, strerror(errno
));
99 static void kill_qemu(QTestState
*s
)
101 if (s
->qemu_pid
!= -1) {
102 kill(s
->qemu_pid
, SIGTERM
);
103 waitpid(s
->qemu_pid
, NULL
, 0);
107 static void kill_qemu_hook_func(void *s
)
112 static void sigabrt_handler(int signo
)
114 g_hook_list_invoke(&abrt_hooks
, FALSE
);
117 static void setup_sigabrt_handler(void)
119 struct sigaction sigact
;
121 /* Catch SIGABRT to clean up on g_assert() failure */
122 sigact
= (struct sigaction
){
123 .sa_handler
= sigabrt_handler
,
124 .sa_flags
= SA_RESETHAND
,
126 sigemptyset(&sigact
.sa_mask
);
127 sigaction(SIGABRT
, &sigact
, &sigact_old
);
130 static void cleanup_sigabrt_handler(void)
132 sigaction(SIGABRT
, &sigact_old
, NULL
);
135 void qtest_add_abrt_handler(GHookFunc fn
, const void *data
)
139 /* Only install SIGABRT handler once */
140 if (!abrt_hooks
.is_setup
) {
141 g_hook_list_init(&abrt_hooks
, sizeof(GHook
));
143 setup_sigabrt_handler();
145 hook
= g_hook_alloc(&abrt_hooks
);
147 hook
->data
= (void *)data
;
149 g_hook_prepend(&abrt_hooks
, hook
);
152 static const char *qtest_qemu_binary(void)
154 const char *qemu_bin
;
156 qemu_bin
= getenv("QTEST_QEMU_BINARY");
158 fprintf(stderr
, "Environment variable QTEST_QEMU_BINARY required\n");
165 QTestState
*qtest_init_without_qmp_handshake(const char *extra_args
)
168 int sock
, qmpsock
, i
;
170 gchar
*qmp_socket_path
;
172 const char *qemu_binary
= qtest_qemu_binary();
174 s
= g_malloc(sizeof(*s
));
176 socket_path
= g_strdup_printf("/tmp/qtest-%d.sock", getpid());
177 qmp_socket_path
= g_strdup_printf("/tmp/qtest-%d.qmp", getpid());
179 /* It's possible that if an earlier test run crashed it might
180 * have left a stale unix socket lying around. Delete any
181 * stale old socket to avoid spurious test failures with
182 * tests/libqtest.c:70:init_socket: assertion failed (ret != -1): (-1 != -1)
185 unlink(qmp_socket_path
);
187 sock
= init_socket(socket_path
);
188 qmpsock
= init_socket(qmp_socket_path
);
190 qtest_add_abrt_handler(kill_qemu_hook_func
, s
);
192 s
->qemu_pid
= fork();
193 if (s
->qemu_pid
== 0) {
194 setenv("QEMU_AUDIO_DRV", "none", true);
195 command
= g_strdup_printf("exec %s "
196 "-qtest unix:%s,nowait "
198 "-qmp unix:%s,nowait "
199 "-machine accel=qtest "
201 "%s", qemu_binary
, socket_path
,
202 getenv("QTEST_LOG") ? "/dev/fd/2" : "/dev/null",
205 execlp("/bin/sh", "sh", "-c", command
, NULL
);
209 s
->fd
= socket_accept(sock
);
211 s
->qmp_fd
= socket_accept(qmpsock
);
214 unlink(qmp_socket_path
);
216 g_free(qmp_socket_path
);
218 g_assert(s
->fd
>= 0 && s
->qmp_fd
>= 0);
220 s
->rx
= g_string_new("");
221 for (i
= 0; i
< MAX_IRQ
; i
++) {
222 s
->irq_level
[i
] = false;
225 if (getenv("QTEST_STOP")) {
226 kill(s
->qemu_pid
, SIGSTOP
);
229 /* ask endianness of the target */
231 s
->big_endian
= qtest_query_target_endianness(s
);
236 QTestState
*qtest_init(const char *extra_args
)
238 QTestState
*s
= qtest_init_without_qmp_handshake(extra_args
);
240 /* Read the QMP greeting and then do the handshake */
241 qtest_qmp_discard_response(s
, "");
242 qtest_qmp_discard_response(s
, "{ 'execute': 'qmp_capabilities' }");
247 void qtest_quit(QTestState
*s
)
249 g_hook_destroy_link(&abrt_hooks
, g_hook_find_data(&abrt_hooks
, TRUE
, s
));
251 /* Uninstall SIGABRT handler on last instance */
252 cleanup_sigabrt_handler();
257 g_string_free(s
->rx
, true);
261 static void socket_send(int fd
, const char *buf
, size_t size
)
266 while (offset
< size
) {
269 len
= write(fd
, buf
+ offset
, size
- offset
);
270 if (len
== -1 && errno
== EINTR
) {
274 g_assert_no_errno(len
);
275 g_assert_cmpint(len
, >, 0);
281 static void socket_sendf(int fd
, const char *fmt
, va_list ap
)
283 gchar
*str
= g_strdup_vprintf(fmt
, ap
);
284 size_t size
= strlen(str
);
286 socket_send(fd
, str
, size
);
290 static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState
*s
, const char *fmt
, ...)
295 socket_sendf(s
->fd
, fmt
, ap
);
299 static GString
*qtest_recv_line(QTestState
*s
)
305 while ((eol
= strchr(s
->rx
->str
, '\n')) == NULL
) {
309 len
= read(s
->fd
, buffer
, sizeof(buffer
));
310 if (len
== -1 && errno
== EINTR
) {
314 if (len
== -1 || len
== 0) {
315 fprintf(stderr
, "Broken pipe\n");
319 g_string_append_len(s
->rx
, buffer
, len
);
322 offset
= eol
- s
->rx
->str
;
323 line
= g_string_new_len(s
->rx
->str
, offset
);
324 g_string_erase(s
->rx
, 0, offset
+ 1);
329 static gchar
**qtest_rsp(QTestState
*s
, int expected_args
)
336 line
= qtest_recv_line(s
);
337 words
= g_strsplit(line
->str
, " ", 0);
338 g_string_free(line
, TRUE
);
340 if (strcmp(words
[0], "IRQ") == 0) {
343 g_assert(words
[1] != NULL
);
344 g_assert(words
[2] != NULL
);
346 irq
= strtoul(words
[2], NULL
, 0);
347 g_assert_cmpint(irq
, >=, 0);
348 g_assert_cmpint(irq
, <, MAX_IRQ
);
350 if (strcmp(words
[1], "raise") == 0) {
351 s
->irq_level
[irq
] = true;
353 s
->irq_level
[irq
] = false;
360 g_assert(words
[0] != NULL
);
361 g_assert_cmpstr(words
[0], ==, "OK");
364 for (i
= 0; i
< expected_args
; i
++) {
365 g_assert(words
[i
] != NULL
);
374 static int qtest_query_target_endianness(QTestState
*s
)
379 qtest_sendf(s
, "endianness\n");
380 args
= qtest_rsp(s
, 1);
381 g_assert(strcmp(args
[1], "big") == 0 || strcmp(args
[1], "little") == 0);
382 big_endian
= strcmp(args
[1], "big") == 0;
389 JSONMessageParser parser
;
393 static void qmp_response(JSONMessageParser
*parser
, GQueue
*tokens
)
395 QMPResponseParser
*qmp
= container_of(parser
, QMPResponseParser
, parser
);
398 obj
= json_parser_parse(tokens
, NULL
);
400 fprintf(stderr
, "QMP JSON response parsing failed\n");
404 g_assert(!qmp
->response
);
405 qmp
->response
= qobject_to_qdict(obj
);
406 g_assert(qmp
->response
);
409 QDict
*qmp_fd_receive(int fd
)
411 QMPResponseParser qmp
;
412 bool log
= getenv("QTEST_LOG") != NULL
;
415 json_message_parser_init(&qmp
.parser
, qmp_response
);
416 while (!qmp
.response
) {
420 len
= read(fd
, &c
, 1);
421 if (len
== -1 && errno
== EINTR
) {
425 if (len
== -1 || len
== 0) {
426 fprintf(stderr
, "Broken pipe\n");
431 len
= write(2, &c
, 1);
433 json_message_parser_feed(&qmp
.parser
, &c
, 1);
435 json_message_parser_destroy(&qmp
.parser
);
440 QDict
*qtest_qmp_receive(QTestState
*s
)
442 return qmp_fd_receive(s
->qmp_fd
);
446 * Allow users to send a message without waiting for the reply,
447 * in the case that they choose to discard all replies up until
448 * a particular EVENT is received.
450 void qmp_fd_sendv(int fd
, const char *fmt
, va_list ap
)
455 /* qobject_from_jsonv() silently eats leading 0xff as invalid
456 * JSON, but we want to test sending them over the wire to force
458 if (*fmt
== '\377') {
459 socket_send(fd
, fmt
, 1);
463 /* Going through qobject ensures we escape strings properly.
464 * This seemingly unnecessary copy is required in case va_list
467 va_copy(ap_copy
, ap
);
468 qobj
= qobject_from_jsonv(fmt
, &ap_copy
, &error_abort
);
471 /* No need to send anything for an empty QObject. */
473 int log
= getenv("QTEST_LOG") != NULL
;
474 QString
*qstr
= qobject_to_json(qobj
);
478 * BUG: QMP doesn't react to input until it sees a newline, an
479 * object, or an array. Work-around: give it a newline.
481 qstring_append_chr(qstr
, '\n');
482 str
= qstring_get_str(qstr
);
485 fprintf(stderr
, "%s", str
);
487 /* Send QMP request */
488 socket_send(fd
, str
, qstring_get_length(qstr
));
491 qobject_decref(qobj
);
495 void qtest_async_qmpv(QTestState
*s
, const char *fmt
, va_list ap
)
497 qmp_fd_sendv(s
->qmp_fd
, fmt
, ap
);
500 QDict
*qmp_fdv(int fd
, const char *fmt
, va_list ap
)
502 qmp_fd_sendv(fd
, fmt
, ap
);
504 return qmp_fd_receive(fd
);
507 QDict
*qtest_qmpv(QTestState
*s
, const char *fmt
, va_list ap
)
509 qtest_async_qmpv(s
, fmt
, ap
);
512 return qtest_qmp_receive(s
);
515 QDict
*qmp_fd(int fd
, const char *fmt
, ...)
521 response
= qmp_fdv(fd
, fmt
, ap
);
526 void qmp_fd_send(int fd
, const char *fmt
, ...)
531 qmp_fd_sendv(fd
, fmt
, ap
);
535 QDict
*qtest_qmp(QTestState
*s
, const char *fmt
, ...)
541 response
= qtest_qmpv(s
, fmt
, ap
);
546 void qtest_async_qmp(QTestState
*s
, const char *fmt
, ...)
551 qtest_async_qmpv(s
, fmt
, ap
);
555 void qtest_qmpv_discard_response(QTestState
*s
, const char *fmt
, va_list ap
)
557 QDict
*response
= qtest_qmpv(s
, fmt
, ap
);
561 void qtest_qmp_discard_response(QTestState
*s
, const char *fmt
, ...)
567 response
= qtest_qmpv(s
, fmt
, ap
);
572 QDict
*qtest_qmp_eventwait_ref(QTestState
*s
, const char *event
)
577 response
= qtest_qmp_receive(s
);
578 if ((qdict_haskey(response
, "event")) &&
579 (strcmp(qdict_get_str(response
, "event"), event
) == 0)) {
586 void qtest_qmp_eventwait(QTestState
*s
, const char *event
)
590 response
= qtest_qmp_eventwait_ref(s
, event
);
594 char *qtest_hmpv(QTestState
*s
, const char *fmt
, va_list ap
)
600 cmd
= g_strdup_vprintf(fmt
, ap
);
601 resp
= qtest_qmp(s
, "{'execute': 'human-monitor-command',"
602 " 'arguments': {'command-line': %s}}",
604 ret
= g_strdup(qdict_get_try_str(resp
, "return"));
605 while (ret
== NULL
&& qdict_get_try_str(resp
, "event")) {
606 /* Ignore asynchronous QMP events */
608 resp
= qtest_qmp_receive(s
);
609 ret
= g_strdup(qdict_get_try_str(resp
, "return"));
617 char *qtest_hmp(QTestState
*s
, const char *fmt
, ...)
623 ret
= qtest_hmpv(s
, fmt
, ap
);
628 const char *qtest_get_arch(void)
630 const char *qemu
= qtest_qemu_binary();
631 const char *end
= strrchr(qemu
, '/');
633 return end
+ strlen("/qemu-system-");
636 bool qtest_get_irq(QTestState
*s
, int num
)
638 /* dummy operation in order to make sure irq is up to date */
641 return s
->irq_level
[num
];
644 static int64_t qtest_clock_rsp(QTestState
*s
)
648 words
= qtest_rsp(s
, 2);
649 clock
= g_ascii_strtoll(words
[1], NULL
, 0);
654 int64_t qtest_clock_step_next(QTestState
*s
)
656 qtest_sendf(s
, "clock_step\n");
657 return qtest_clock_rsp(s
);
660 int64_t qtest_clock_step(QTestState
*s
, int64_t step
)
662 qtest_sendf(s
, "clock_step %"PRIi64
"\n", step
);
663 return qtest_clock_rsp(s
);
666 int64_t qtest_clock_set(QTestState
*s
, int64_t val
)
668 qtest_sendf(s
, "clock_set %"PRIi64
"\n", val
);
669 return qtest_clock_rsp(s
);
672 void qtest_irq_intercept_out(QTestState
*s
, const char *qom_path
)
674 qtest_sendf(s
, "irq_intercept_out %s\n", qom_path
);
678 void qtest_irq_intercept_in(QTestState
*s
, const char *qom_path
)
680 qtest_sendf(s
, "irq_intercept_in %s\n", qom_path
);
684 static void qtest_out(QTestState
*s
, const char *cmd
, uint16_t addr
, uint32_t value
)
686 qtest_sendf(s
, "%s 0x%x 0x%x\n", cmd
, addr
, value
);
690 void qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
)
692 qtest_out(s
, "outb", addr
, value
);
695 void qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
)
697 qtest_out(s
, "outw", addr
, value
);
700 void qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
)
702 qtest_out(s
, "outl", addr
, value
);
705 static uint32_t qtest_in(QTestState
*s
, const char *cmd
, uint16_t addr
)
710 qtest_sendf(s
, "%s 0x%x\n", cmd
, addr
);
711 args
= qtest_rsp(s
, 2);
712 value
= strtoul(args
[1], NULL
, 0);
718 uint8_t qtest_inb(QTestState
*s
, uint16_t addr
)
720 return qtest_in(s
, "inb", addr
);
723 uint16_t qtest_inw(QTestState
*s
, uint16_t addr
)
725 return qtest_in(s
, "inw", addr
);
728 uint32_t qtest_inl(QTestState
*s
, uint16_t addr
)
730 return qtest_in(s
, "inl", addr
);
733 static void qtest_write(QTestState
*s
, const char *cmd
, uint64_t addr
,
736 qtest_sendf(s
, "%s 0x%" PRIx64
" 0x%" PRIx64
"\n", cmd
, addr
, value
);
740 void qtest_writeb(QTestState
*s
, uint64_t addr
, uint8_t value
)
742 qtest_write(s
, "writeb", addr
, value
);
745 void qtest_writew(QTestState
*s
, uint64_t addr
, uint16_t value
)
747 qtest_write(s
, "writew", addr
, value
);
750 void qtest_writel(QTestState
*s
, uint64_t addr
, uint32_t value
)
752 qtest_write(s
, "writel", addr
, value
);
755 void qtest_writeq(QTestState
*s
, uint64_t addr
, uint64_t value
)
757 qtest_write(s
, "writeq", addr
, value
);
760 static uint64_t qtest_read(QTestState
*s
, const char *cmd
, uint64_t addr
)
765 qtest_sendf(s
, "%s 0x%" PRIx64
"\n", cmd
, addr
);
766 args
= qtest_rsp(s
, 2);
767 value
= strtoull(args
[1], NULL
, 0);
773 uint8_t qtest_readb(QTestState
*s
, uint64_t addr
)
775 return qtest_read(s
, "readb", addr
);
778 uint16_t qtest_readw(QTestState
*s
, uint64_t addr
)
780 return qtest_read(s
, "readw", addr
);
783 uint32_t qtest_readl(QTestState
*s
, uint64_t addr
)
785 return qtest_read(s
, "readl", addr
);
788 uint64_t qtest_readq(QTestState
*s
, uint64_t addr
)
790 return qtest_read(s
, "readq", addr
);
793 static int hex2nib(char ch
)
795 if (ch
>= '0' && ch
<= '9') {
797 } else if (ch
>= 'a' && ch
<= 'f') {
798 return 10 + (ch
- 'a');
799 } else if (ch
>= 'A' && ch
<= 'F') {
800 return 10 + (ch
- 'a');
806 void qtest_memread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
)
816 qtest_sendf(s
, "read 0x%" PRIx64
" 0x%zx\n", addr
, size
);
817 args
= qtest_rsp(s
, 2);
819 for (i
= 0; i
< size
; i
++) {
820 ptr
[i
] = hex2nib(args
[1][2 + (i
* 2)]) << 4;
821 ptr
[i
] |= hex2nib(args
[1][2 + (i
* 2) + 1]);
827 uint64_t qtest_rtas_call(QTestState
*s
, const char *name
,
828 uint32_t nargs
, uint64_t args
,
829 uint32_t nret
, uint64_t ret
)
831 qtest_sendf(s
, "rtas %s %u 0x%"PRIx64
" %u 0x%"PRIx64
"\n",
832 name
, nargs
, args
, nret
, ret
);
837 void qtest_add_func(const char *str
, void (*fn
)(void))
839 gchar
*path
= g_strdup_printf("/%s/%s", qtest_get_arch(), str
);
840 g_test_add_func(path
, fn
);
844 void qtest_add_data_func_full(const char *str
, void *data
,
845 void (*fn
)(const void *),
846 GDestroyNotify data_free_func
)
848 gchar
*path
= g_strdup_printf("/%s/%s", qtest_get_arch(), str
);
849 g_test_add_data_func_full(path
, data
, fn
, data_free_func
);
853 void qtest_add_data_func(const char *str
, const void *data
,
854 void (*fn
)(const void *))
856 gchar
*path
= g_strdup_printf("/%s/%s", qtest_get_arch(), str
);
857 g_test_add_data_func(path
, data
, fn
);
861 void qtest_bufwrite(QTestState
*s
, uint64_t addr
, const void *data
, size_t size
)
865 bdata
= g_base64_encode(data
, size
);
866 qtest_sendf(s
, "b64write 0x%" PRIx64
" 0x%zx ", addr
, size
);
867 socket_send(s
->fd
, bdata
, strlen(bdata
));
868 socket_send(s
->fd
, "\n", 1);
873 void qtest_bufread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
)
878 qtest_sendf(s
, "b64read 0x%" PRIx64
" 0x%zx\n", addr
, size
);
879 args
= qtest_rsp(s
, 2);
881 g_base64_decode_inplace(args
[1], &len
);
883 fprintf(stderr
, "bufread: asked for %zu bytes but decoded %zu\n",
885 len
= MIN(len
, size
);
888 memcpy(data
, args
[1], len
);
892 void qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
, size_t size
)
894 const uint8_t *ptr
= data
;
902 enc
= g_malloc(2 * size
+ 1);
904 for (i
= 0; i
< size
; i
++) {
905 sprintf(&enc
[i
* 2], "%02x", ptr
[i
]);
908 qtest_sendf(s
, "write 0x%" PRIx64
" 0x%zx 0x%s\n", addr
, size
, enc
);
913 void qtest_memset(QTestState
*s
, uint64_t addr
, uint8_t pattern
, size_t size
)
915 qtest_sendf(s
, "memset 0x%" PRIx64
" 0x%zx 0x%02x\n", addr
, size
, pattern
);
919 QDict
*qmp(const char *fmt
, ...)
925 response
= qtest_qmpv(global_qtest
, fmt
, ap
);
930 void qmp_async(const char *fmt
, ...)
935 qtest_async_qmpv(global_qtest
, fmt
, ap
);
939 void qmp_discard_response(const char *fmt
, ...)
944 qtest_qmpv_discard_response(global_qtest
, fmt
, ap
);
947 char *hmp(const char *fmt
, ...)
953 ret
= qtest_hmpv(global_qtest
, fmt
, ap
);
958 bool qtest_big_endian(QTestState
*s
)
960 return s
->big_endian
;
963 void qtest_cb_for_every_machine(void (*cb
)(const char *machine
))
965 QDict
*response
, *minfo
;
972 qtest_start("-machine none");
973 response
= qmp("{ 'execute': 'query-machines' }");
975 list
= qdict_get_qlist(response
, "return");
978 for (p
= qlist_first(list
); p
; p
= qlist_next(p
)) {
979 minfo
= qobject_to_qdict(qlist_entry_obj(p
));
981 qobj
= qdict_get(minfo
, "name");
983 qstr
= qobject_to_qstring(qobj
);
985 mname
= qstring_get_str(qstr
);
994 * Generic hot-plugging test via the device_add QMP command.
996 void qtest_qmp_device_add(const char *driver
, const char *id
, const char *fmt
,
1000 char *cmd
, *opts
= NULL
;
1005 opts
= g_strdup_vprintf(fmt
, va
);
1009 cmd
= g_strdup_printf("{'execute': 'device_add',"
1010 " 'arguments': { 'driver': '%s', 'id': '%s'%s%s }}",
1011 driver
, id
, opts
? ", " : "", opts
? opts
: "");
1014 response
= qmp(cmd
);
1017 g_assert(!qdict_haskey(response
, "event")); /* We don't expect any events */
1018 g_assert(!qdict_haskey(response
, "error"));
1023 * Generic hot-unplugging test via the device_del QMP command.
1024 * Device deletion will get one response and one event. For example:
1026 * {'execute': 'device_del','arguments': { 'id': 'scsi-hd'}}
1028 * will get this one:
1030 * {"timestamp": {"seconds": 1505289667, "microseconds": 569862},
1031 * "event": "DEVICE_DELETED", "data": {"device": "scsi-hd",
1032 * "path": "/machine/peripheral/scsi-hd"}}
1038 * But the order of arrival may vary - so we've got to detect both.
1040 void qtest_qmp_device_del(const char *id
)
1042 QDict
*response1
, *response2
, *event
= NULL
;
1045 cmd
= g_strdup_printf("{'execute': 'device_del',"
1046 " 'arguments': { 'id': '%s' }}", id
);
1047 response1
= qmp(cmd
);
1049 g_assert(response1
);
1050 g_assert(!qdict_haskey(response1
, "error"));
1052 response2
= qmp("");
1053 g_assert(response2
);
1054 g_assert(!qdict_haskey(response2
, "error"));
1056 if (qdict_haskey(response1
, "event")) {
1058 } else if (qdict_haskey(response2
, "event")) {
1062 g_assert_cmpstr(qdict_get_str(event
, "event"), ==, "DEVICE_DELETED");