]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qtest/libqos/libqtest.h
linux-user/arm: Implement __kernel_cmpxchg64 with host atomics
[mirror_qemu.git] / tests / qtest / libqos / libqtest.h
1 /*
2 * QTest
3 *
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 * Copyright SUSE LINUX Products GmbH 2013
7 *
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
11 * Andreas Färber <afaerber@suse.de>
12 *
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.
15 *
16 */
17 #ifndef LIBQTEST_H
18 #define LIBQTEST_H
19
20 #include "qapi/qmp/qobject.h"
21 #include "qapi/qmp/qdict.h"
22
23 typedef struct QTestState QTestState;
24
25 /**
26 * qtest_initf:
27 * @fmt: Format for creating other arguments to pass to QEMU, formatted
28 * like sprintf().
29 *
30 * Convenience wrapper around qtest_init().
31 *
32 * Returns: #QTestState instance.
33 */
34 QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
35
36 /**
37 * qtest_vinitf:
38 * @fmt: Format for creating other arguments to pass to QEMU, formatted
39 * like vsprintf().
40 * @ap: Format arguments.
41 *
42 * Convenience wrapper around qtest_init().
43 *
44 * Returns: #QTestState instance.
45 */
46 QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
47
48 /**
49 * qtest_init:
50 * @extra_args: other arguments to pass to QEMU. CAUTION: these
51 * arguments are subject to word splitting and shell evaluation.
52 *
53 * Returns: #QTestState instance.
54 */
55 QTestState *qtest_init(const char *extra_args);
56
57 /**
58 * qtest_init_without_qmp_handshake:
59 * @extra_args: other arguments to pass to QEMU. CAUTION: these
60 * arguments are subject to word splitting and shell evaluation.
61 *
62 * Returns: #QTestState instance.
63 */
64 QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
65
66 /**
67 * qtest_init_with_serial:
68 * @extra_args: other arguments to pass to QEMU. CAUTION: these
69 * arguments are subject to word splitting and shell evaluation.
70 * @sock_fd: pointer to store the socket file descriptor for
71 * connection with serial.
72 *
73 * Returns: #QTestState instance.
74 */
75 QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
76
77 /**
78 * qtest_kill_qemu:
79 * @s: #QTestState instance to operate on.
80 *
81 * Kill the QEMU process and wait for it to terminate. It is safe to call this
82 * function multiple times. Normally qtest_quit() is used instead because it
83 * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
84 * and qtest_quit() will be called later.
85 */
86 void qtest_kill_qemu(QTestState *s);
87
88 /**
89 * qtest_quit:
90 * @s: #QTestState instance to operate on.
91 *
92 * Shut down the QEMU process associated to @s.
93 */
94 void qtest_quit(QTestState *s);
95
96 /**
97 * qtest_qmp_fds:
98 * @s: #QTestState instance to operate on.
99 * @fds: array of file descriptors
100 * @fds_num: number of elements in @fds
101 * @fmt: QMP message to send to qemu, formatted like
102 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
103 * supported after '%'.
104 *
105 * Sends a QMP message to QEMU with fds and returns the response.
106 */
107 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
108 const char *fmt, ...)
109 GCC_FMT_ATTR(4, 5);
110
111 /**
112 * qtest_qmp:
113 * @s: #QTestState instance to operate on.
114 * @fmt: QMP message to send to qemu, formatted like
115 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
116 * supported after '%'.
117 *
118 * Sends a QMP message to QEMU and returns the response.
119 */
120 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
121 GCC_FMT_ATTR(2, 3);
122
123 /**
124 * qtest_qmp_send:
125 * @s: #QTestState instance to operate on.
126 * @fmt: QMP message to send to qemu, formatted like
127 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
128 * supported after '%'.
129 *
130 * Sends a QMP message to QEMU and leaves the response in the stream.
131 */
132 void qtest_qmp_send(QTestState *s, const char *fmt, ...)
133 GCC_FMT_ATTR(2, 3);
134
135 /**
136 * qtest_qmp_send_raw:
137 * @s: #QTestState instance to operate on.
138 * @fmt: text to send, formatted like sprintf()
139 *
140 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
141 * this is useful for negative tests.
142 */
143 void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
144 GCC_FMT_ATTR(2, 3);
145
146 /**
147 * qtest_socket_server:
148 * @socket_path: the UNIX domain socket path
149 *
150 * Create and return a listen socket file descriptor, or abort on failure.
151 */
152 int qtest_socket_server(const char *socket_path);
153
154 /**
155 * qtest_vqmp_fds:
156 * @s: #QTestState instance to operate on.
157 * @fds: array of file descriptors
158 * @fds_num: number of elements in @fds
159 * @fmt: QMP message to send to QEMU, formatted like
160 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
161 * supported after '%'.
162 * @ap: QMP message arguments
163 *
164 * Sends a QMP message to QEMU with fds and returns the response.
165 */
166 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
167 const char *fmt, va_list ap)
168 GCC_FMT_ATTR(4, 0);
169
170 /**
171 * qtest_vqmp:
172 * @s: #QTestState instance to operate on.
173 * @fmt: QMP message to send to QEMU, formatted like
174 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
175 * supported after '%'.
176 * @ap: QMP message arguments
177 *
178 * Sends a QMP message to QEMU and returns the response.
179 */
180 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
181 GCC_FMT_ATTR(2, 0);
182
183 /**
184 * qtest_qmp_vsend_fds:
185 * @s: #QTestState instance to operate on.
186 * @fds: array of file descriptors
187 * @fds_num: number of elements in @fds
188 * @fmt: QMP message to send to QEMU, formatted like
189 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
190 * supported after '%'.
191 * @ap: QMP message arguments
192 *
193 * Sends a QMP message to QEMU and leaves the response in the stream.
194 */
195 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
196 const char *fmt, va_list ap)
197 GCC_FMT_ATTR(4, 0);
198
199 /**
200 * qtest_qmp_vsend:
201 * @s: #QTestState instance to operate on.
202 * @fmt: QMP message to send to QEMU, formatted like
203 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
204 * supported after '%'.
205 * @ap: QMP message arguments
206 *
207 * Sends a QMP message to QEMU and leaves the response in the stream.
208 */
209 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
210 GCC_FMT_ATTR(2, 0);
211
212 /**
213 * qtest_qmp_receive_dict:
214 * @s: #QTestState instance to operate on.
215 *
216 * Reads a QMP message from QEMU and returns the response.
217 */
218 QDict *qtest_qmp_receive_dict(QTestState *s);
219
220 /**
221 * qtest_qmp_receive:
222 * @s: #QTestState instance to operate on.
223 *
224 * Reads a QMP message from QEMU and returns the response.
225 * Buffers all the events received meanwhile, until a
226 * call to qtest_qmp_eventwait
227 */
228 QDict *qtest_qmp_receive(QTestState *s);
229
230 /**
231 * qtest_qmp_eventwait:
232 * @s: #QTestState instance to operate on.
233 * @event: event to wait for.
234 *
235 * Continuously polls for QMP responses until it receives the desired event.
236 */
237 void qtest_qmp_eventwait(QTestState *s, const char *event);
238
239 /**
240 * qtest_qmp_eventwait_ref:
241 * @s: #QTestState instance to operate on.
242 * @event: event to wait for.
243 *
244 * Continuously polls for QMP responses until it receives the desired event.
245 * Returns a copy of the event for further investigation.
246 */
247 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
248
249 /**
250 * qtest_qmp_event_ref:
251 * @s: #QTestState instance to operate on.
252 * @event: event to return.
253 *
254 * Removes non-matching events from the buffer that was set by
255 * qtest_qmp_receive, until an event bearing the given name is found,
256 * and returns it.
257 * If no event matches, clears the buffer and returns NULL.
258 *
259 */
260 QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
261
262 /**
263 * qtest_hmp:
264 * @s: #QTestState instance to operate on.
265 * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
266 *
267 * Send HMP command to QEMU via QMP's human-monitor-command.
268 * QMP events are discarded.
269 *
270 * Returns: the command's output. The caller should g_free() it.
271 */
272 char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
273
274 /**
275 * qtest_hmpv:
276 * @s: #QTestState instance to operate on.
277 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
278 * @ap: HMP command arguments
279 *
280 * Send HMP command to QEMU via QMP's human-monitor-command.
281 * QMP events are discarded.
282 *
283 * Returns: the command's output. The caller should g_free() it.
284 */
285 char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
286 GCC_FMT_ATTR(2, 0);
287
288 void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
289
290 /**
291 * qtest_get_irq:
292 * @s: #QTestState instance to operate on.
293 * @num: Interrupt to observe.
294 *
295 * Returns: The level of the @num interrupt.
296 */
297 bool qtest_get_irq(QTestState *s, int num);
298
299 /**
300 * qtest_irq_intercept_in:
301 * @s: #QTestState instance to operate on.
302 * @string: QOM path of a device.
303 *
304 * Associate qtest irqs with the GPIO-in pins of the device
305 * whose path is specified by @string.
306 */
307 void qtest_irq_intercept_in(QTestState *s, const char *string);
308
309 /**
310 * qtest_irq_intercept_out:
311 * @s: #QTestState instance to operate on.
312 * @string: QOM path of a device.
313 *
314 * Associate qtest irqs with the GPIO-out pins of the device
315 * whose path is specified by @string.
316 */
317 void qtest_irq_intercept_out(QTestState *s, const char *string);
318
319 /**
320 * qtest_set_irq_in:
321 * @s: QTestState instance to operate on.
322 * @string: QOM path of a device
323 * @name: IRQ name
324 * @irq: IRQ number
325 * @level: IRQ level
326 *
327 * Force given device/irq GPIO-in pin to the given level.
328 */
329 void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
330 int irq, int level);
331
332 /**
333 * qtest_outb:
334 * @s: #QTestState instance to operate on.
335 * @addr: I/O port to write to.
336 * @value: Value being written.
337 *
338 * Write an 8-bit value to an I/O port.
339 */
340 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
341
342 /**
343 * qtest_outw:
344 * @s: #QTestState instance to operate on.
345 * @addr: I/O port to write to.
346 * @value: Value being written.
347 *
348 * Write a 16-bit value to an I/O port.
349 */
350 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
351
352 /**
353 * qtest_outl:
354 * @s: #QTestState instance to operate on.
355 * @addr: I/O port to write to.
356 * @value: Value being written.
357 *
358 * Write a 32-bit value to an I/O port.
359 */
360 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
361
362 /**
363 * qtest_inb:
364 * @s: #QTestState instance to operate on.
365 * @addr: I/O port to read from.
366 *
367 * Returns an 8-bit value from an I/O port.
368 */
369 uint8_t qtest_inb(QTestState *s, uint16_t addr);
370
371 /**
372 * qtest_inw:
373 * @s: #QTestState instance to operate on.
374 * @addr: I/O port to read from.
375 *
376 * Returns a 16-bit value from an I/O port.
377 */
378 uint16_t qtest_inw(QTestState *s, uint16_t addr);
379
380 /**
381 * qtest_inl:
382 * @s: #QTestState instance to operate on.
383 * @addr: I/O port to read from.
384 *
385 * Returns a 32-bit value from an I/O port.
386 */
387 uint32_t qtest_inl(QTestState *s, uint16_t addr);
388
389 /**
390 * qtest_writeb:
391 * @s: #QTestState instance to operate on.
392 * @addr: Guest address to write to.
393 * @value: Value being written.
394 *
395 * Writes an 8-bit value to memory.
396 */
397 void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
398
399 /**
400 * qtest_writew:
401 * @s: #QTestState instance to operate on.
402 * @addr: Guest address to write to.
403 * @value: Value being written.
404 *
405 * Writes a 16-bit value to memory.
406 */
407 void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
408
409 /**
410 * qtest_writel:
411 * @s: #QTestState instance to operate on.
412 * @addr: Guest address to write to.
413 * @value: Value being written.
414 *
415 * Writes a 32-bit value to memory.
416 */
417 void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
418
419 /**
420 * qtest_writeq:
421 * @s: #QTestState instance to operate on.
422 * @addr: Guest address to write to.
423 * @value: Value being written.
424 *
425 * Writes a 64-bit value to memory.
426 */
427 void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
428
429 /**
430 * qtest_readb:
431 * @s: #QTestState instance to operate on.
432 * @addr: Guest address to read from.
433 *
434 * Reads an 8-bit value from memory.
435 *
436 * Returns: Value read.
437 */
438 uint8_t qtest_readb(QTestState *s, uint64_t addr);
439
440 /**
441 * qtest_readw:
442 * @s: #QTestState instance to operate on.
443 * @addr: Guest address to read from.
444 *
445 * Reads a 16-bit value from memory.
446 *
447 * Returns: Value read.
448 */
449 uint16_t qtest_readw(QTestState *s, uint64_t addr);
450
451 /**
452 * qtest_readl:
453 * @s: #QTestState instance to operate on.
454 * @addr: Guest address to read from.
455 *
456 * Reads a 32-bit value from memory.
457 *
458 * Returns: Value read.
459 */
460 uint32_t qtest_readl(QTestState *s, uint64_t addr);
461
462 /**
463 * qtest_readq:
464 * @s: #QTestState instance to operate on.
465 * @addr: Guest address to read from.
466 *
467 * Reads a 64-bit value from memory.
468 *
469 * Returns: Value read.
470 */
471 uint64_t qtest_readq(QTestState *s, uint64_t addr);
472
473 /**
474 * qtest_memread:
475 * @s: #QTestState instance to operate on.
476 * @addr: Guest address to read from.
477 * @data: Pointer to where memory contents will be stored.
478 * @size: Number of bytes to read.
479 *
480 * Read guest memory into a buffer.
481 */
482 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
483
484 /**
485 * qtest_rtas_call:
486 * @s: #QTestState instance to operate on.
487 * @name: name of the command to call.
488 * @nargs: Number of args.
489 * @args: Guest address to read args from.
490 * @nret: Number of return value.
491 * @ret: Guest address to write return values to.
492 *
493 * Call an RTAS function
494 */
495 uint64_t qtest_rtas_call(QTestState *s, const char *name,
496 uint32_t nargs, uint64_t args,
497 uint32_t nret, uint64_t ret);
498
499 /**
500 * qtest_bufread:
501 * @s: #QTestState instance to operate on.
502 * @addr: Guest address to read from.
503 * @data: Pointer to where memory contents will be stored.
504 * @size: Number of bytes to read.
505 *
506 * Read guest memory into a buffer and receive using a base64 encoding.
507 */
508 void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
509
510 /**
511 * qtest_memwrite:
512 * @s: #QTestState instance to operate on.
513 * @addr: Guest address to write to.
514 * @data: Pointer to the bytes that will be written to guest memory.
515 * @size: Number of bytes to write.
516 *
517 * Write a buffer to guest memory.
518 */
519 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
520
521 /**
522 * qtest_bufwrite:
523 * @s: #QTestState instance to operate on.
524 * @addr: Guest address to write to.
525 * @data: Pointer to the bytes that will be written to guest memory.
526 * @size: Number of bytes to write.
527 *
528 * Write a buffer to guest memory and transmit using a base64 encoding.
529 */
530 void qtest_bufwrite(QTestState *s, uint64_t addr,
531 const void *data, size_t size);
532
533 /**
534 * qtest_memset:
535 * @s: #QTestState instance to operate on.
536 * @addr: Guest address to write to.
537 * @patt: Byte pattern to fill the guest memory region with.
538 * @size: Number of bytes to write.
539 *
540 * Write a pattern to guest memory.
541 */
542 void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
543
544 /**
545 * qtest_clock_step_next:
546 * @s: #QTestState instance to operate on.
547 *
548 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
549 *
550 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
551 */
552 int64_t qtest_clock_step_next(QTestState *s);
553
554 /**
555 * qtest_clock_step:
556 * @s: QTestState instance to operate on.
557 * @step: Number of nanoseconds to advance the clock by.
558 *
559 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
560 *
561 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
562 */
563 int64_t qtest_clock_step(QTestState *s, int64_t step);
564
565 /**
566 * qtest_clock_set:
567 * @s: QTestState instance to operate on.
568 * @val: Nanoseconds value to advance the clock to.
569 *
570 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
571 *
572 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
573 */
574 int64_t qtest_clock_set(QTestState *s, int64_t val);
575
576 /**
577 * qtest_big_endian:
578 * @s: QTestState instance to operate on.
579 *
580 * Returns: True if the architecture under test has a big endian configuration.
581 */
582 bool qtest_big_endian(QTestState *s);
583
584 /**
585 * qtest_get_arch:
586 *
587 * Returns: The architecture for the QEMU executable under test.
588 */
589 const char *qtest_get_arch(void);
590
591 /**
592 * qtest_has_accel:
593 * @accel_name: Accelerator name to check for.
594 *
595 * Returns: true if the accelerator is built in.
596 */
597 bool qtest_has_accel(const char *accel_name);
598
599 /**
600 * qtest_add_func:
601 * @str: Test case path.
602 * @fn: Test case function
603 *
604 * Add a GTester testcase with the given name and function.
605 * The path is prefixed with the architecture under test, as
606 * returned by qtest_get_arch().
607 */
608 void qtest_add_func(const char *str, void (*fn)(void));
609
610 /**
611 * qtest_add_data_func:
612 * @str: Test case path.
613 * @data: Test case data
614 * @fn: Test case function
615 *
616 * Add a GTester testcase with the given name, data and function.
617 * The path is prefixed with the architecture under test, as
618 * returned by qtest_get_arch().
619 */
620 void qtest_add_data_func(const char *str, const void *data,
621 void (*fn)(const void *));
622
623 /**
624 * qtest_add_data_func_full:
625 * @str: Test case path.
626 * @data: Test case data
627 * @fn: Test case function
628 * @data_free_func: GDestroyNotify for data
629 *
630 * Add a GTester testcase with the given name, data and function.
631 * The path is prefixed with the architecture under test, as
632 * returned by qtest_get_arch().
633 *
634 * @data is passed to @data_free_func() on test completion.
635 */
636 void qtest_add_data_func_full(const char *str, void *data,
637 void (*fn)(const void *),
638 GDestroyNotify data_free_func);
639
640 /**
641 * qtest_add:
642 * @testpath: Test case path
643 * @Fixture: Fixture type
644 * @tdata: Test case data
645 * @fsetup: Test case setup function
646 * @ftest: Test case function
647 * @fteardown: Test case teardown function
648 *
649 * Add a GTester testcase with the given name, data and functions.
650 * The path is prefixed with the architecture under test, as
651 * returned by qtest_get_arch().
652 */
653 #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
654 do { \
655 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
656 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
657 g_free(path); \
658 } while (0)
659
660 /**
661 * qtest_add_abrt_handler:
662 * @fn: Handler function
663 * @data: Argument that is passed to the handler
664 *
665 * Add a handler function that is invoked on SIGABRT. This can be used to
666 * terminate processes and perform other cleanup. The handler can be removed
667 * with qtest_remove_abrt_handler().
668 */
669 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
670
671 /**
672 * qtest_remove_abrt_handler:
673 * @data: Argument previously passed to qtest_add_abrt_handler()
674 *
675 * Remove an abrt handler that was previously added with
676 * qtest_add_abrt_handler().
677 */
678 void qtest_remove_abrt_handler(void *data);
679
680 /**
681 * qtest_qmp_assert_success:
682 * @qts: QTestState instance to operate on
683 * @fmt: QMP message to send to qemu, formatted like
684 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
685 * supported after '%'.
686 *
687 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
688 * the response.
689 */
690 void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
691 GCC_FMT_ATTR(2, 3);
692
693 QDict *qmp_fd_receive(int fd);
694 void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
695 const char *fmt, va_list ap) GCC_FMT_ATTR(4, 0);
696 void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
697 void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
698 void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
699 void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
700 QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
701 QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
702
703 /**
704 * qtest_cb_for_every_machine:
705 * @cb: Pointer to the callback function
706 * @skip_old_versioned: true if versioned old machine types should be skipped
707 *
708 * Call a callback function for every name of all available machines.
709 */
710 void qtest_cb_for_every_machine(void (*cb)(const char *machine),
711 bool skip_old_versioned);
712
713 /**
714 * qtest_has_machine:
715 * @machine: The machine to look for
716 *
717 * Returns: true if the machine is available in the target binary.
718 */
719 bool qtest_has_machine(const char *machine);
720
721 /**
722 * qtest_has_device:
723 * @device: The device to look for
724 *
725 * Returns: true if the device is available in the target binary.
726 */
727 bool qtest_has_device(const char *device);
728
729 /**
730 * qtest_qmp_device_add_qdict:
731 * @qts: QTestState instance to operate on
732 * @drv: Name of the device that should be added
733 * @arguments: QDict with properties for the device to intialize
734 *
735 * Generic hot-plugging test via the device_add QMP command with properties
736 * supplied in form of QDict. Use NULL for empty properties list.
737 */
738 void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
739 const QDict *arguments);
740
741 /**
742 * qtest_qmp_device_add:
743 * @qts: QTestState instance to operate on
744 * @driver: Name of the device that should be added
745 * @id: Identification string
746 * @fmt: QMP message to send to qemu, formatted like
747 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
748 * supported after '%'.
749 *
750 * Generic hot-plugging test via the device_add QMP command.
751 */
752 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
753 const char *fmt, ...) GCC_FMT_ATTR(4, 5);
754
755 /**
756 * qtest_qmp_add_client:
757 * @qts: QTestState instance to operate on
758 * @protocol: the protocol to add to
759 * @fd: the client file-descriptor
760 *
761 * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
762 */
763 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
764
765 /**
766 * qtest_qmp_device_del:
767 * @qts: QTestState instance to operate on
768 * @id: Identification string
769 *
770 * Generic hot-unplugging test via the device_del QMP command.
771 */
772 void qtest_qmp_device_del(QTestState *qts, const char *id);
773
774 /**
775 * qmp_rsp_is_err:
776 * @rsp: QMP response to check for error
777 *
778 * Test @rsp for error and discard @rsp.
779 * Returns 'true' if there is error in @rsp and 'false' otherwise.
780 */
781 bool qmp_rsp_is_err(QDict *rsp);
782
783 /**
784 * qmp_expect_error_and_unref:
785 * @rsp: QMP response to check for error
786 * @class: an error class
787 *
788 * Assert the response has the given error class and discard @rsp.
789 */
790 void qmp_expect_error_and_unref(QDict *rsp, const char *class);
791
792 /**
793 * qtest_probe_child:
794 * @s: QTestState instance to operate on.
795 *
796 * Returns: true if the child is still alive.
797 */
798 bool qtest_probe_child(QTestState *s);
799
800 /**
801 * qtest_set_expected_status:
802 * @s: QTestState instance to operate on.
803 * @status: an expected exit status.
804 *
805 * Set expected exit status of the child.
806 */
807 void qtest_set_expected_status(QTestState *s, int status);
808
809 QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
810 void (*send)(void*, const char*));
811
812 void qtest_client_inproc_recv(void *opaque, const char *str);
813 #endif