xref: /qemu/tests/qtest/libqtest.h (revision de6cd759)
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 #include "libqmp.h"
23 
24 typedef struct QTestState QTestState;
25 
26 /**
27  * qtest_initf:
28  * @fmt: Format for creating other arguments to pass to QEMU, formatted
29  * like sprintf().
30  *
31  * Convenience wrapper around qtest_init().
32  *
33  * Returns: #QTestState instance.
34  */
35 QTestState *qtest_initf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
36 
37 /**
38  * qtest_vinitf:
39  * @fmt: Format for creating other arguments to pass to QEMU, formatted
40  * like vsprintf().
41  * @ap: Format arguments.
42  *
43  * Convenience wrapper around qtest_init().
44  *
45  * Returns: #QTestState instance.
46  */
47 QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
48 
49 /**
50  * qtest_init:
51  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
52  * arguments are subject to word splitting and shell evaluation.
53  *
54  * Returns: #QTestState instance.
55  */
56 QTestState *qtest_init(const char *extra_args);
57 
58 /**
59  * qtest_init_without_qmp_handshake:
60  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
61  * arguments are subject to word splitting and shell evaluation.
62  *
63  * Returns: #QTestState instance.
64  */
65 QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
66 
67 /**
68  * qtest_init_with_serial:
69  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
70  * arguments are subject to word splitting and shell evaluation.
71  * @sock_fd: pointer to store the socket file descriptor for
72  * connection with serial.
73  *
74  * Returns: #QTestState instance.
75  */
76 QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
77 
78 /**
79  * qtest_wait_qemu:
80  * @s: #QTestState instance to operate on.
81  *
82  * Wait for the QEMU process to terminate. It is safe to call this function
83  * multiple times.
84  */
85 void qtest_wait_qemu(QTestState *s);
86 
87 /**
88  * qtest_kill_qemu:
89  * @s: #QTestState instance to operate on.
90  *
91  * Kill the QEMU process and wait for it to terminate. It is safe to call this
92  * function multiple times. Normally qtest_quit() is used instead because it
93  * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
94  * and qtest_quit() will be called later.
95  */
96 void qtest_kill_qemu(QTestState *s);
97 
98 /**
99  * qtest_quit:
100  * @s: #QTestState instance to operate on.
101  *
102  * Shut down the QEMU process associated to @s.
103  */
104 void qtest_quit(QTestState *s);
105 
106 #ifndef _WIN32
107 /**
108  * qtest_qmp_fds:
109  * @s: #QTestState instance to operate on.
110  * @fds: array of file descriptors
111  * @fds_num: number of elements in @fds
112  * @fmt: QMP message to send to qemu, formatted like
113  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
114  * supported after '%'.
115  *
116  * Sends a QMP message to QEMU with fds and returns the response.
117  */
118 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
119                      const char *fmt, ...)
120     G_GNUC_PRINTF(4, 5);
121 #endif /* _WIN32 */
122 
123 /**
124  * qtest_qmp:
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 returns the response.
131  */
132 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
133     G_GNUC_PRINTF(2, 3);
134 
135 /**
136  * qtest_qmp_send:
137  * @s: #QTestState instance to operate on.
138  * @fmt: QMP message to send to qemu, formatted like
139  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
140  * supported after '%'.
141  *
142  * Sends a QMP message to QEMU and leaves the response in the stream.
143  */
144 void qtest_qmp_send(QTestState *s, const char *fmt, ...)
145     G_GNUC_PRINTF(2, 3);
146 
147 /**
148  * qtest_qmp_send_raw:
149  * @s: #QTestState instance to operate on.
150  * @fmt: text to send, formatted like sprintf()
151  *
152  * Sends text to the QMP monitor verbatim.  Need not be valid JSON;
153  * this is useful for negative tests.
154  */
155 void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
156     G_GNUC_PRINTF(2, 3);
157 
158 /**
159  * qtest_socket_server:
160  * @socket_path: the UNIX domain socket path
161  *
162  * Create and return a listen socket file descriptor, or abort on failure.
163  */
164 int qtest_socket_server(const char *socket_path);
165 
166 #ifndef _WIN32
167 /**
168  * qtest_vqmp_fds:
169  * @s: #QTestState instance to operate on.
170  * @fds: array of file descriptors
171  * @fds_num: number of elements in @fds
172  * @fmt: QMP message to send to QEMU, formatted like
173  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
174  * supported after '%'.
175  * @ap: QMP message arguments
176  *
177  * Sends a QMP message to QEMU with fds and returns the response.
178  */
179 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
180                       const char *fmt, va_list ap)
181     G_GNUC_PRINTF(4, 0);
182 #endif /* _WIN32 */
183 
184 /**
185  * qtest_vqmp:
186  * @s: #QTestState instance to operate on.
187  * @fmt: QMP message to send to QEMU, formatted like
188  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
189  * supported after '%'.
190  * @ap: QMP message arguments
191  *
192  * Sends a QMP message to QEMU and returns the response.
193  */
194 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
195     G_GNUC_PRINTF(2, 0);
196 
197 #ifndef _WIN32
198 /**
199  * qtest_qmp_vsend_fds:
200  * @s: #QTestState instance to operate on.
201  * @fds: array of file descriptors
202  * @fds_num: number of elements in @fds
203  * @fmt: QMP message to send to QEMU, formatted like
204  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
205  * supported after '%'.
206  * @ap: QMP message arguments
207  *
208  * Sends a QMP message to QEMU and leaves the response in the stream.
209  */
210 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
211                          const char *fmt, va_list ap)
212     G_GNUC_PRINTF(4, 0);
213 #endif /* _WIN32 */
214 
215 /**
216  * qtest_qmp_vsend:
217  * @s: #QTestState instance to operate on.
218  * @fmt: QMP message to send to QEMU, formatted like
219  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
220  * supported after '%'.
221  * @ap: QMP message arguments
222  *
223  * Sends a QMP message to QEMU and leaves the response in the stream.
224  */
225 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
226     G_GNUC_PRINTF(2, 0);
227 
228 /**
229  * qtest_qmp_receive_dict:
230  * @s: #QTestState instance to operate on.
231  *
232  * Reads a QMP message from QEMU and returns the response.
233  */
234 QDict *qtest_qmp_receive_dict(QTestState *s);
235 
236 /**
237  * qtest_qmp_receive:
238  * @s: #QTestState instance to operate on.
239  *
240  * Reads a QMP message from QEMU and returns the response.
241  *
242  * If a callback is registered with qtest_qmp_set_event_callback,
243  * it will be invoked for every event seen, otherwise events
244  * will be buffered until a call to one of the qtest_qmp_eventwait
245  * family of functions.
246  */
247 QDict *qtest_qmp_receive(QTestState *s);
248 
249 /*
250  * QTestQMPEventCallback:
251  * @s: #QTestState instance event was received on
252  * @name: name of the event type
253  * @event: #QDict for the event details
254  * @opaque: opaque data from time of callback registration
255  *
256  * This callback will be invoked whenever an event is received.
257  * If the callback returns true the event will be consumed,
258  * otherwise it will be put on the list of pending events.
259  * Pending events can be later handled by calling either
260  * qtest_qmp_eventwait or qtest_qmp_eventwait_ref.
261  *
262  * Return: true to consume the event, false to let it be queued
263  */
264 typedef bool (*QTestQMPEventCallback)(QTestState *s, const char *name,
265                                       QDict *event, void *opaque);
266 
267 /**
268  * qtest_qmp_set_event_callback:
269  * @s: #QTestSTate instance to operate on
270  * @cb: callback to invoke for events
271  * @opaque: data to pass to @cb
272  *
273  * Register a callback to be invoked whenever an event arrives
274  */
275 void qtest_qmp_set_event_callback(QTestState *s,
276                                   QTestQMPEventCallback cb, void *opaque);
277 
278 /**
279  * qtest_qmp_eventwait:
280  * @s: #QTestState instance to operate on.
281  * @event: event to wait for.
282  *
283  * Continuously polls for QMP responses until it receives the desired event.
284  *
285  * Any callback registered with qtest_qmp_set_event_callback will
286  * be invoked for every event seen.
287  */
288 void qtest_qmp_eventwait(QTestState *s, const char *event);
289 
290 /**
291  * qtest_qmp_eventwait_ref:
292  * @s: #QTestState instance to operate on.
293  * @event: event to wait for.
294  *
295  * Continuously polls for QMP responses until it receives the desired event.
296  *
297  * Any callback registered with qtest_qmp_set_event_callback will
298  * be invoked for every event seen.
299  *
300  * Returns a copy of the event for further investigation.
301  */
302 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
303 
304 /**
305  * qtest_qmp_event_ref:
306  * @s: #QTestState instance to operate on.
307  * @event: event to return.
308  *
309  * Removes non-matching events from the buffer that was set by
310  * qtest_qmp_receive, until an event bearing the given name is found,
311  * and returns it.
312  * If no event matches, clears the buffer and returns NULL.
313  *
314  */
315 QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
316 
317 /**
318  * qtest_hmp:
319  * @s: #QTestState instance to operate on.
320  * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
321  *
322  * Send HMP command to QEMU via QMP's human-monitor-command.
323  * QMP events are discarded.
324  *
325  * Returns: the command's output.  The caller should g_free() it.
326  */
327 char *qtest_hmp(QTestState *s, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
328 
329 /**
330  * qtest_hmpv:
331  * @s: #QTestState instance to operate on.
332  * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
333  * @ap: HMP command arguments
334  *
335  * Send HMP command to QEMU via QMP's human-monitor-command.
336  * QMP events are discarded.
337  *
338  * Returns: the command's output.  The caller should g_free() it.
339  */
340 char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
341     G_GNUC_PRINTF(2, 0);
342 
343 void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
344 
345 /**
346  * qtest_get_irq:
347  * @s: #QTestState instance to operate on.
348  * @num: Interrupt to observe.
349  *
350  * Returns: The level of the @num interrupt.
351  */
352 bool qtest_get_irq(QTestState *s, int num);
353 
354 /**
355  * qtest_irq_intercept_in:
356  * @s: #QTestState instance to operate on.
357  * @string: QOM path of a device.
358  *
359  * Associate qtest irqs with the GPIO-in pins of the device
360  * whose path is specified by @string.
361  */
362 void qtest_irq_intercept_in(QTestState *s, const char *string);
363 
364 /**
365  * qtest_irq_intercept_out:
366  * @s: #QTestState instance to operate on.
367  * @string: QOM path of a device.
368  *
369  * Associate qtest irqs with the GPIO-out pins of the device
370  * whose path is specified by @string.
371  */
372 void qtest_irq_intercept_out(QTestState *s, const char *string);
373 
374 /**
375  * qtest_set_irq_in:
376  * @s: QTestState instance to operate on.
377  * @string: QOM path of a device
378  * @name: IRQ name
379  * @irq: IRQ number
380  * @level: IRQ level
381  *
382  * Force given device/irq GPIO-in pin to the given level.
383  */
384 void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
385                       int irq, int level);
386 
387 /**
388  * qtest_outb:
389  * @s: #QTestState instance to operate on.
390  * @addr: I/O port to write to.
391  * @value: Value being written.
392  *
393  * Write an 8-bit value to an I/O port.
394  */
395 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
396 
397 /**
398  * qtest_outw:
399  * @s: #QTestState instance to operate on.
400  * @addr: I/O port to write to.
401  * @value: Value being written.
402  *
403  * Write a 16-bit value to an I/O port.
404  */
405 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
406 
407 /**
408  * qtest_outl:
409  * @s: #QTestState instance to operate on.
410  * @addr: I/O port to write to.
411  * @value: Value being written.
412  *
413  * Write a 32-bit value to an I/O port.
414  */
415 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
416 
417 /**
418  * qtest_inb:
419  * @s: #QTestState instance to operate on.
420  * @addr: I/O port to read from.
421  *
422  * Returns an 8-bit value from an I/O port.
423  */
424 uint8_t qtest_inb(QTestState *s, uint16_t addr);
425 
426 /**
427  * qtest_inw:
428  * @s: #QTestState instance to operate on.
429  * @addr: I/O port to read from.
430  *
431  * Returns a 16-bit value from an I/O port.
432  */
433 uint16_t qtest_inw(QTestState *s, uint16_t addr);
434 
435 /**
436  * qtest_inl:
437  * @s: #QTestState instance to operate on.
438  * @addr: I/O port to read from.
439  *
440  * Returns a 32-bit value from an I/O port.
441  */
442 uint32_t qtest_inl(QTestState *s, uint16_t addr);
443 
444 /**
445  * qtest_writeb:
446  * @s: #QTestState instance to operate on.
447  * @addr: Guest address to write to.
448  * @value: Value being written.
449  *
450  * Writes an 8-bit value to memory.
451  */
452 void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
453 
454 /**
455  * qtest_writew:
456  * @s: #QTestState instance to operate on.
457  * @addr: Guest address to write to.
458  * @value: Value being written.
459  *
460  * Writes a 16-bit value to memory.
461  */
462 void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
463 
464 /**
465  * qtest_writel:
466  * @s: #QTestState instance to operate on.
467  * @addr: Guest address to write to.
468  * @value: Value being written.
469  *
470  * Writes a 32-bit value to memory.
471  */
472 void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
473 
474 /**
475  * qtest_writeq:
476  * @s: #QTestState instance to operate on.
477  * @addr: Guest address to write to.
478  * @value: Value being written.
479  *
480  * Writes a 64-bit value to memory.
481  */
482 void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
483 
484 /**
485  * qtest_readb:
486  * @s: #QTestState instance to operate on.
487  * @addr: Guest address to read from.
488  *
489  * Reads an 8-bit value from memory.
490  *
491  * Returns: Value read.
492  */
493 uint8_t qtest_readb(QTestState *s, uint64_t addr);
494 
495 /**
496  * qtest_readw:
497  * @s: #QTestState instance to operate on.
498  * @addr: Guest address to read from.
499  *
500  * Reads a 16-bit value from memory.
501  *
502  * Returns: Value read.
503  */
504 uint16_t qtest_readw(QTestState *s, uint64_t addr);
505 
506 /**
507  * qtest_readl:
508  * @s: #QTestState instance to operate on.
509  * @addr: Guest address to read from.
510  *
511  * Reads a 32-bit value from memory.
512  *
513  * Returns: Value read.
514  */
515 uint32_t qtest_readl(QTestState *s, uint64_t addr);
516 
517 /**
518  * qtest_readq:
519  * @s: #QTestState instance to operate on.
520  * @addr: Guest address to read from.
521  *
522  * Reads a 64-bit value from memory.
523  *
524  * Returns: Value read.
525  */
526 uint64_t qtest_readq(QTestState *s, uint64_t addr);
527 
528 /**
529  * qtest_memread:
530  * @s: #QTestState instance to operate on.
531  * @addr: Guest address to read from.
532  * @data: Pointer to where memory contents will be stored.
533  * @size: Number of bytes to read.
534  *
535  * Read guest memory into a buffer.
536  */
537 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
538 
539 /**
540  * qtest_rtas_call:
541  * @s: #QTestState instance to operate on.
542  * @name: name of the command to call.
543  * @nargs: Number of args.
544  * @args: Guest address to read args from.
545  * @nret: Number of return value.
546  * @ret: Guest address to write return values to.
547  *
548  * Call an RTAS function
549  */
550 uint64_t qtest_rtas_call(QTestState *s, const char *name,
551                          uint32_t nargs, uint64_t args,
552                          uint32_t nret, uint64_t ret);
553 
554 /**
555  * qtest_bufread:
556  * @s: #QTestState instance to operate on.
557  * @addr: Guest address to read from.
558  * @data: Pointer to where memory contents will be stored.
559  * @size: Number of bytes to read.
560  *
561  * Read guest memory into a buffer and receive using a base64 encoding.
562  */
563 void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
564 
565 /**
566  * qtest_memwrite:
567  * @s: #QTestState instance to operate on.
568  * @addr: Guest address to write to.
569  * @data: Pointer to the bytes that will be written to guest memory.
570  * @size: Number of bytes to write.
571  *
572  * Write a buffer to guest memory.
573  */
574 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
575 
576 /**
577  * qtest_bufwrite:
578  * @s: #QTestState instance to operate on.
579  * @addr: Guest address to write to.
580  * @data: Pointer to the bytes that will be written to guest memory.
581  * @size: Number of bytes to write.
582  *
583  * Write a buffer to guest memory and transmit using a base64 encoding.
584  */
585 void qtest_bufwrite(QTestState *s, uint64_t addr,
586                     const void *data, size_t size);
587 
588 /**
589  * qtest_memset:
590  * @s: #QTestState instance to operate on.
591  * @addr: Guest address to write to.
592  * @patt: Byte pattern to fill the guest memory region with.
593  * @size: Number of bytes to write.
594  *
595  * Write a pattern to guest memory.
596  */
597 void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
598 
599 /**
600  * qtest_clock_step_next:
601  * @s: #QTestState instance to operate on.
602  *
603  * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
604  *
605  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
606  */
607 int64_t qtest_clock_step_next(QTestState *s);
608 
609 /**
610  * qtest_clock_step:
611  * @s: QTestState instance to operate on.
612  * @step: Number of nanoseconds to advance the clock by.
613  *
614  * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
615  *
616  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
617  */
618 int64_t qtest_clock_step(QTestState *s, int64_t step);
619 
620 /**
621  * qtest_clock_set:
622  * @s: QTestState instance to operate on.
623  * @val: Nanoseconds value to advance the clock to.
624  *
625  * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
626  *
627  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
628  */
629 int64_t qtest_clock_set(QTestState *s, int64_t val);
630 
631 /**
632  * qtest_big_endian:
633  * @s: QTestState instance to operate on.
634  *
635  * Returns: True if the architecture under test has a big endian configuration.
636  */
637 bool qtest_big_endian(QTestState *s);
638 
639 /**
640  * qtest_get_arch:
641  *
642  * Returns: The architecture for the QEMU executable under test.
643  */
644 const char *qtest_get_arch(void);
645 
646 /**
647  * qtest_has_accel:
648  * @accel_name: Accelerator name to check for.
649  *
650  * Returns: true if the accelerator is built in.
651  */
652 bool qtest_has_accel(const char *accel_name);
653 
654 /**
655  * qtest_add_func:
656  * @str: Test case path.
657  * @fn: Test case function
658  *
659  * Add a GTester testcase with the given name and function.
660  * The path is prefixed with the architecture under test, as
661  * returned by qtest_get_arch().
662  */
663 void qtest_add_func(const char *str, void (*fn)(void));
664 
665 /**
666  * qtest_add_data_func:
667  * @str: Test case path.
668  * @data: Test case data
669  * @fn: Test case function
670  *
671  * Add a GTester testcase with the given name, data and function.
672  * The path is prefixed with the architecture under test, as
673  * returned by qtest_get_arch().
674  */
675 void qtest_add_data_func(const char *str, const void *data,
676                          void (*fn)(const void *));
677 
678 /**
679  * qtest_add_data_func_full:
680  * @str: Test case path.
681  * @data: Test case data
682  * @fn: Test case function
683  * @data_free_func: GDestroyNotify for data
684  *
685  * Add a GTester testcase with the given name, data and function.
686  * The path is prefixed with the architecture under test, as
687  * returned by qtest_get_arch().
688  *
689  * @data is passed to @data_free_func() on test completion.
690  */
691 void qtest_add_data_func_full(const char *str, void *data,
692                               void (*fn)(const void *),
693                               GDestroyNotify data_free_func);
694 
695 /**
696  * qtest_add:
697  * @testpath: Test case path
698  * @Fixture: Fixture type
699  * @tdata: Test case data
700  * @fsetup: Test case setup function
701  * @ftest: Test case function
702  * @fteardown: Test case teardown function
703  *
704  * Add a GTester testcase with the given name, data and functions.
705  * The path is prefixed with the architecture under test, as
706  * returned by qtest_get_arch().
707  */
708 #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
709     do { \
710         char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
711         g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
712         g_free(path); \
713     } while (0)
714 
715 /**
716  * qtest_add_abrt_handler:
717  * @fn: Handler function
718  * @data: Argument that is passed to the handler
719  *
720  * Add a handler function that is invoked on SIGABRT. This can be used to
721  * terminate processes and perform other cleanup. The handler can be removed
722  * with qtest_remove_abrt_handler().
723  */
724 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
725 
726 /**
727  * qtest_remove_abrt_handler:
728  * @data: Argument previously passed to qtest_add_abrt_handler()
729  *
730  * Remove an abrt handler that was previously added with
731  * qtest_add_abrt_handler().
732  */
733 void qtest_remove_abrt_handler(void *data);
734 
735 /**
736  * qtest_vqmp_assert_success_ref:
737  * @qts: QTestState instance to operate on
738  * @fmt: QMP message to send to qemu, formatted like
739  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
740  * supported after '%'.
741  * @args: variable arguments for @fmt
742  *
743  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
744  * the response, and returns the response.
745  */
746 QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
747                                      const char *fmt, va_list args)
748     G_GNUC_PRINTF(2, 0);
749 
750 /**
751  * qtest_vqmp_assert_success:
752  * @qts: QTestState instance to operate on
753  * @fmt: QMP message to send to qemu, formatted like
754  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
755  * supported after '%'.
756  * @args: variable arguments for @fmt
757  *
758  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
759  * the response.
760  */
761 void qtest_vqmp_assert_success(QTestState *qts,
762                                const char *fmt, va_list args)
763     G_GNUC_PRINTF(2, 0);
764 
765 #ifndef _WIN32
766 /**
767  * qtest_vqmp_fds_assert_success_ref:
768  * @qts: QTestState instance to operate on
769  * @fds: the file descriptors to send
770  * @nfds: number of @fds to send
771  * @fmt: QMP message to send to qemu, formatted like
772  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
773  * supported after '%'.
774  * @args: variable arguments for @fmt
775  *
776  * Sends a QMP message with file descriptors to QEMU,
777  * asserts that a 'return' key is present in the response,
778  * and returns the response.
779  */
780 QDict *qtest_vqmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
781                                          const char *fmt, va_list args)
782     G_GNUC_PRINTF(4, 0);
783 
784 /**
785  * qtest_vqmp_fds_assert_success:
786  * @qts: QTestState instance to operate on
787  * @fds: the file descriptors to send
788  * @nfds: number of @fds to send
789  * @fmt: QMP message to send to qemu, formatted like
790  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
791  * supported after '%'.
792  * @args: variable arguments for @fmt
793  *
794  * Sends a QMP message with file descriptors to QEMU and
795  * asserts that a 'return' key is present in the response.
796  */
797 void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
798                                    const char *fmt, va_list args)
799     G_GNUC_PRINTF(4, 0);
800 #endif /* !_WIN32 */
801 
802 /**
803  * qtest_qmp_assert_success_ref:
804  * @qts: QTestState instance to operate on
805  * @fmt: QMP message to send to qemu, formatted like
806  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
807  * supported after '%'.
808  *
809  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
810  * the response, and returns the response.
811  */
812 QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
813     G_GNUC_PRINTF(2, 3);
814 
815 /**
816  * qtest_qmp_assert_success:
817  * @qts: QTestState instance to operate on
818  * @fmt: QMP message to send to qemu, formatted like
819  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
820  * supported after '%'.
821  *
822  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
823  * the response.
824  */
825 void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
826     G_GNUC_PRINTF(2, 3);
827 
828 #ifndef _WIN32
829 /**
830  * qtest_qmp_fd_assert_success_ref:
831  * @qts: QTestState instance to operate on
832  * @fds: the file descriptors to send
833  * @nfds: number of @fds to send
834  * @fmt: QMP message to send to qemu, formatted like
835  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
836  * supported after '%'.
837  *
838  * Sends a QMP message with file descriptors to QEMU,
839  * asserts that a 'return' key is present in the response,
840  * and returns the response.
841  */
842 QDict *qtest_qmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
843                                         const char *fmt, ...)
844     G_GNUC_PRINTF(4, 5);
845 
846 /**
847  * qtest_qmp_fd_assert_success:
848  * @qts: QTestState instance to operate on
849  * @fds: the file descriptors to send
850  * @nfds: number of @fds to send
851  * @fmt: QMP message to send to qemu, formatted like
852  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
853  * supported after '%'.
854  *
855  * Sends a QMP message with file descriptors to QEMU and
856  * asserts that a 'return' key is present in the response.
857  */
858 void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
859                                   const char *fmt, ...)
860     G_GNUC_PRINTF(4, 5);
861 #endif /* !_WIN32 */
862 
863 /**
864  * qtest_cb_for_every_machine:
865  * @cb: Pointer to the callback function
866  * @skip_old_versioned: true if versioned old machine types should be skipped
867  *
868  *  Call a callback function for every name of all available machines.
869  */
870 void qtest_cb_for_every_machine(void (*cb)(const char *machine),
871                                 bool skip_old_versioned);
872 
873 /**
874  * qtest_has_machine:
875  * @machine: The machine to look for
876  *
877  * Returns: true if the machine is available in the target binary.
878  */
879 bool qtest_has_machine(const char *machine);
880 
881 /**
882  * qtest_has_device:
883  * @device: The device to look for
884  *
885  * Returns: true if the device is available in the target binary.
886  */
887 bool qtest_has_device(const char *device);
888 
889 /**
890  * qtest_qmp_device_add_qdict:
891  * @qts: QTestState instance to operate on
892  * @drv: Name of the device that should be added
893  * @arguments: QDict with properties for the device to initialize
894  *
895  * Generic hot-plugging test via the device_add QMP command with properties
896  * supplied in form of QDict. Use NULL for empty properties list.
897  */
898 void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
899                                 const QDict *arguments);
900 
901 /**
902  * qtest_qmp_device_add:
903  * @qts: QTestState instance to operate on
904  * @driver: Name of the device that should be added
905  * @id: Identification string
906  * @fmt: QMP message to send to qemu, formatted like
907  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
908  * supported after '%'.
909  *
910  * Generic hot-plugging test via the device_add QMP command.
911  */
912 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
913                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
914 
915 /**
916  * qtest_qmp_add_client:
917  * @qts: QTestState instance to operate on
918  * @protocol: the protocol to add to
919  * @fd: the client file-descriptor
920  *
921  * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
922  * ``add_client`` with the given @fd.
923  */
924 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
925 
926 /**
927  * qtest_qmp_device_del_send:
928  * @qts: QTestState instance to operate on
929  * @id: Identification string
930  *
931  * Generic hot-unplugging test via the device_del QMP command.
932  */
933 void qtest_qmp_device_del_send(QTestState *qts, const char *id);
934 
935 /**
936  * qtest_qmp_device_del:
937  * @qts: QTestState instance to operate on
938  * @id: Identification string
939  *
940  * Generic hot-unplugging test via the device_del QMP command.
941  * Waiting for command completion event.
942  */
943 void qtest_qmp_device_del(QTestState *qts, const char *id);
944 
945 /**
946  * qtest_probe_child:
947  * @s: QTestState instance to operate on.
948  *
949  * Returns: true if the child is still alive.
950  */
951 bool qtest_probe_child(QTestState *s);
952 
953 /**
954  * qtest_set_expected_status:
955  * @s: QTestState instance to operate on.
956  * @status: an expected exit status.
957  *
958  * Set expected exit status of the child.
959  */
960 void qtest_set_expected_status(QTestState *s, int status);
961 
962 QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
963                     void (*send)(void*, const char*));
964 
965 void qtest_client_inproc_recv(void *opaque, const char *str);
966 
967 /**
968  * qtest_qom_set_bool:
969  * @s: QTestState instance to operate on.
970  * @path: Path to the property being set.
971  * @property: Property being set.
972  * @value: Value to set the property.
973  *
974  * Set the property with passed in value.
975  */
976 void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,
977                          bool value);
978 
979 /**
980  * qtest_qom_get_bool:
981  * @s: QTestState instance to operate on.
982  * @path: Path to the property being retrieved.
983  * @property: Property from where the value is being retrieved.
984  *
985  * Returns: Value retrieved from property.
986  */
987 bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
988 #endif
989