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.
20 #include "qapi/qmp/qobject.h"
21 #include "qapi/qmp/qdict.h"
24 typedef struct QTestState QTestState
;
28 * @fmt: Format for creating other arguments to pass to QEMU, formatted
31 * Convenience wrapper around qtest_init().
33 * Returns: #QTestState instance.
35 QTestState
*qtest_initf(const char *fmt
, ...) G_GNUC_PRINTF(1, 2);
39 * @fmt: Format for creating other arguments to pass to QEMU, formatted
41 * @ap: Format arguments.
43 * Convenience wrapper around qtest_init().
45 * Returns: #QTestState instance.
47 QTestState
*qtest_vinitf(const char *fmt
, va_list ap
) G_GNUC_PRINTF(1, 0);
51 * @extra_args: other arguments to pass to QEMU. CAUTION: these
52 * arguments are subject to word splitting and shell evaluation.
54 * Returns: #QTestState instance.
56 QTestState
*qtest_init(const char *extra_args
);
59 * qtest_init_with_env:
60 * @var: Environment variable from where to take the QEMU binary
61 * @extra_args: Other arguments to pass to QEMU. CAUTION: these
62 * arguments are subject to word splitting and shell evaluation.
64 * Like qtest_init(), but use a different environment variable for the
67 * Returns: #QTestState instance.
69 QTestState
*qtest_init_with_env(const char *var
, const char *extra_args
);
72 * qtest_init_without_qmp_handshake:
73 * @extra_args: other arguments to pass to QEMU. CAUTION: these
74 * arguments are subject to word splitting and shell evaluation.
76 * Returns: #QTestState instance.
78 QTestState
*qtest_init_without_qmp_handshake(const char *extra_args
);
81 * qtest_init_with_serial:
82 * @extra_args: other arguments to pass to QEMU. CAUTION: these
83 * arguments are subject to word splitting and shell evaluation.
84 * @sock_fd: pointer to store the socket file descriptor for
85 * connection with serial.
87 * Returns: #QTestState instance.
89 QTestState
*qtest_init_with_serial(const char *extra_args
, int *sock_fd
);
93 * @s: #QTestState instance to operate on.
95 * Wait for the QEMU process to terminate. It is safe to call this function
98 void qtest_wait_qemu(QTestState
*s
);
102 * @s: #QTestState instance to operate on.
104 * Kill the QEMU process and wait for it to terminate. It is safe to call this
105 * function multiple times. Normally qtest_quit() is used instead because it
106 * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
107 * and qtest_quit() will be called later.
109 void qtest_kill_qemu(QTestState
*s
);
113 * @s: #QTestState instance to operate on.
115 * Shut down the QEMU process associated to @s.
117 void qtest_quit(QTestState
*s
);
122 * @s: #QTestState instance to operate on.
123 * @fds: array of file descriptors
124 * @fds_num: number of elements in @fds
125 * @fmt: QMP message to send to qemu, formatted like
126 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
127 * supported after '%'.
129 * Sends a QMP message to QEMU with fds and returns the response.
131 QDict
*qtest_qmp_fds(QTestState
*s
, int *fds
, size_t fds_num
,
132 const char *fmt
, ...)
138 * @s: #QTestState instance to operate on.
139 * @fmt: QMP message to send to qemu, formatted like
140 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
141 * supported after '%'.
143 * Sends a QMP message to QEMU and returns the response.
145 QDict
*qtest_qmp(QTestState
*s
, const char *fmt
, ...)
150 * @s: #QTestState instance to operate on.
151 * @fmt: QMP message to send to qemu, formatted like
152 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
153 * supported after '%'.
155 * Sends a QMP message to QEMU and leaves the response in the stream.
157 void qtest_qmp_send(QTestState
*s
, const char *fmt
, ...)
161 * qtest_qmp_send_raw:
162 * @s: #QTestState instance to operate on.
163 * @fmt: text to send, formatted like sprintf()
165 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
166 * this is useful for negative tests.
168 void qtest_qmp_send_raw(QTestState
*s
, const char *fmt
, ...)
172 * qtest_socket_server:
173 * @socket_path: the UNIX domain socket path
175 * Create and return a listen socket file descriptor, or abort on failure.
177 int qtest_socket_server(const char *socket_path
);
182 * @s: #QTestState instance to operate on.
183 * @fds: array of file descriptors
184 * @fds_num: number of elements in @fds
185 * @fmt: QMP message to send to QEMU, formatted like
186 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
187 * supported after '%'.
188 * @ap: QMP message arguments
190 * Sends a QMP message to QEMU with fds and returns the response.
192 QDict
*qtest_vqmp_fds(QTestState
*s
, int *fds
, size_t fds_num
,
193 const char *fmt
, va_list ap
)
199 * @s: #QTestState instance to operate on.
200 * @fmt: QMP message to send to QEMU, formatted like
201 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
202 * supported after '%'.
203 * @ap: QMP message arguments
205 * Sends a QMP message to QEMU and returns the response.
207 QDict
*qtest_vqmp(QTestState
*s
, const char *fmt
, va_list ap
)
212 * qtest_qmp_vsend_fds:
213 * @s: #QTestState instance to operate on.
214 * @fds: array of file descriptors
215 * @fds_num: number of elements in @fds
216 * @fmt: QMP message to send to QEMU, formatted like
217 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
218 * supported after '%'.
219 * @ap: QMP message arguments
221 * Sends a QMP message to QEMU and leaves the response in the stream.
223 void qtest_qmp_vsend_fds(QTestState
*s
, int *fds
, size_t fds_num
,
224 const char *fmt
, va_list ap
)
230 * @s: #QTestState instance to operate on.
231 * @fmt: QMP message to send to QEMU, formatted like
232 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
233 * supported after '%'.
234 * @ap: QMP message arguments
236 * Sends a QMP message to QEMU and leaves the response in the stream.
238 void qtest_qmp_vsend(QTestState
*s
, const char *fmt
, va_list ap
)
242 * qtest_qmp_receive_dict:
243 * @s: #QTestState instance to operate on.
245 * Reads a QMP message from QEMU and returns the response.
247 QDict
*qtest_qmp_receive_dict(QTestState
*s
);
251 * @s: #QTestState instance to operate on.
253 * Reads a QMP message from QEMU and returns the response.
255 * If a callback is registered with qtest_qmp_set_event_callback,
256 * it will be invoked for every event seen, otherwise events
257 * will be buffered until a call to one of the qtest_qmp_eventwait
258 * family of functions.
260 QDict
*qtest_qmp_receive(QTestState
*s
);
263 * QTestQMPEventCallback:
264 * @s: #QTestState instance event was received on
265 * @name: name of the event type
266 * @event: #QDict for the event details
267 * @opaque: opaque data from time of callback registration
269 * This callback will be invoked whenever an event is received.
270 * If the callback returns true the event will be consumed,
271 * otherwise it will be put on the list of pending events.
272 * Pending events can be later handled by calling either
273 * qtest_qmp_eventwait or qtest_qmp_eventwait_ref.
275 * Return: true to consume the event, false to let it be queued
277 typedef bool (*QTestQMPEventCallback
)(QTestState
*s
, const char *name
,
278 QDict
*event
, void *opaque
);
281 * qtest_qmp_set_event_callback:
282 * @s: #QTestSTate instance to operate on
283 * @cb: callback to invoke for events
284 * @opaque: data to pass to @cb
286 * Register a callback to be invoked whenever an event arrives
288 void qtest_qmp_set_event_callback(QTestState
*s
,
289 QTestQMPEventCallback cb
, void *opaque
);
292 * qtest_qmp_eventwait:
293 * @s: #QTestState instance to operate on.
294 * @event: event to wait for.
296 * Continuously polls for QMP responses until it receives the desired event.
298 * Any callback registered with qtest_qmp_set_event_callback will
299 * be invoked for every event seen.
301 void qtest_qmp_eventwait(QTestState
*s
, const char *event
);
304 * qtest_qmp_eventwait_ref:
305 * @s: #QTestState instance to operate on.
306 * @event: event to wait for.
308 * Continuously polls for QMP responses until it receives the desired event.
310 * Any callback registered with qtest_qmp_set_event_callback will
311 * be invoked for every event seen.
313 * Returns a copy of the event for further investigation.
315 QDict
*qtest_qmp_eventwait_ref(QTestState
*s
, const char *event
);
318 * qtest_qmp_event_ref:
319 * @s: #QTestState instance to operate on.
320 * @event: event to return.
322 * Removes non-matching events from the buffer that was set by
323 * qtest_qmp_receive, until an event bearing the given name is found,
325 * If no event matches, clears the buffer and returns NULL.
328 QDict
*qtest_qmp_event_ref(QTestState
*s
, const char *event
);
332 * @s: #QTestState instance to operate on.
333 * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
335 * Send HMP command to QEMU via QMP's human-monitor-command.
336 * QMP events are discarded.
338 * Returns: the command's output. The caller should g_free() it.
340 char *qtest_hmp(QTestState
*s
, const char *fmt
, ...) G_GNUC_PRINTF(2, 3);
344 * @s: #QTestState instance to operate on.
345 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
346 * @ap: HMP command arguments
348 * Send HMP command to QEMU via QMP's human-monitor-command.
349 * QMP events are discarded.
351 * Returns: the command's output. The caller should g_free() it.
353 char *qtest_vhmp(QTestState
*s
, const char *fmt
, va_list ap
)
356 void qtest_module_load(QTestState
*s
, const char *prefix
, const char *libname
);
360 * @s: #QTestState instance to operate on.
361 * @num: Interrupt to observe.
363 * Returns: The level of the @num interrupt.
365 bool qtest_get_irq(QTestState
*s
, int num
);
368 * qtest_irq_intercept_in:
369 * @s: #QTestState instance to operate on.
370 * @string: QOM path of a device.
372 * Associate qtest irqs with the GPIO-in pins of the device
373 * whose path is specified by @string.
375 void qtest_irq_intercept_in(QTestState
*s
, const char *string
);
378 * qtest_irq_intercept_out:
379 * @s: #QTestState instance to operate on.
380 * @string: QOM path of a device.
382 * Associate qtest irqs with the GPIO-out pins of the device
383 * whose path is specified by @string.
385 void qtest_irq_intercept_out(QTestState
*s
, const char *string
);
388 * qtest_irq_intercept_out_named:
389 * @s: #QTestState instance to operate on.
390 * @qom_path: QOM path of a device.
391 * @name: Name of the GPIO out pin
393 * Associate a qtest irq with the named GPIO-out pin of the device
394 * whose path is specified by @string and whose name is @name.
396 void qtest_irq_intercept_out_named(QTestState
*s
, const char *qom_path
, const char *name
);
400 * @s: QTestState instance to operate on.
401 * @string: QOM path of a device
406 * Force given device/irq GPIO-in pin to the given level.
408 void qtest_set_irq_in(QTestState
*s
, const char *string
, const char *name
,
413 * @s: #QTestState instance to operate on.
414 * @addr: I/O port to write to.
415 * @value: Value being written.
417 * Write an 8-bit value to an I/O port.
419 void qtest_outb(QTestState
*s
, uint16_t addr
, uint8_t value
);
423 * @s: #QTestState instance to operate on.
424 * @addr: I/O port to write to.
425 * @value: Value being written.
427 * Write a 16-bit value to an I/O port.
429 void qtest_outw(QTestState
*s
, uint16_t addr
, uint16_t value
);
433 * @s: #QTestState instance to operate on.
434 * @addr: I/O port to write to.
435 * @value: Value being written.
437 * Write a 32-bit value to an I/O port.
439 void qtest_outl(QTestState
*s
, uint16_t addr
, uint32_t value
);
443 * @s: #QTestState instance to operate on.
444 * @addr: I/O port to read from.
446 * Returns an 8-bit value from an I/O port.
448 uint8_t qtest_inb(QTestState
*s
, uint16_t addr
);
452 * @s: #QTestState instance to operate on.
453 * @addr: I/O port to read from.
455 * Returns a 16-bit value from an I/O port.
457 uint16_t qtest_inw(QTestState
*s
, uint16_t addr
);
461 * @s: #QTestState instance to operate on.
462 * @addr: I/O port to read from.
464 * Returns a 32-bit value from an I/O port.
466 uint32_t qtest_inl(QTestState
*s
, uint16_t addr
);
470 * @s: #QTestState instance to operate on.
471 * @addr: Guest address to write to.
472 * @value: Value being written.
474 * Writes an 8-bit value to memory.
476 void qtest_writeb(QTestState
*s
, uint64_t addr
, uint8_t value
);
480 * @s: #QTestState instance to operate on.
481 * @addr: Guest address to write to.
482 * @value: Value being written.
484 * Writes a 16-bit value to memory.
486 void qtest_writew(QTestState
*s
, uint64_t addr
, uint16_t value
);
490 * @s: #QTestState instance to operate on.
491 * @addr: Guest address to write to.
492 * @value: Value being written.
494 * Writes a 32-bit value to memory.
496 void qtest_writel(QTestState
*s
, uint64_t addr
, uint32_t value
);
500 * @s: #QTestState instance to operate on.
501 * @addr: Guest address to write to.
502 * @value: Value being written.
504 * Writes a 64-bit value to memory.
506 void qtest_writeq(QTestState
*s
, uint64_t addr
, uint64_t value
);
510 * @s: #QTestState instance to operate on.
511 * @addr: Guest address to read from.
513 * Reads an 8-bit value from memory.
515 * Returns: Value read.
517 uint8_t qtest_readb(QTestState
*s
, uint64_t addr
);
521 * @s: #QTestState instance to operate on.
522 * @addr: Guest address to read from.
524 * Reads a 16-bit value from memory.
526 * Returns: Value read.
528 uint16_t qtest_readw(QTestState
*s
, uint64_t addr
);
532 * @s: #QTestState instance to operate on.
533 * @addr: Guest address to read from.
535 * Reads a 32-bit value from memory.
537 * Returns: Value read.
539 uint32_t qtest_readl(QTestState
*s
, uint64_t addr
);
543 * @s: #QTestState instance to operate on.
544 * @addr: Guest address to read from.
546 * Reads a 64-bit value from memory.
548 * Returns: Value read.
550 uint64_t qtest_readq(QTestState
*s
, uint64_t addr
);
554 * @s: #QTestState instance to operate on.
555 * @addr: Guest address to read from.
556 * @data: Pointer to where memory contents will be stored.
557 * @size: Number of bytes to read.
559 * Read guest memory into a buffer.
561 void qtest_memread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
);
565 * @s: #QTestState instance to operate on.
566 * @name: name of the command to call.
567 * @nargs: Number of args.
568 * @args: Guest address to read args from.
569 * @nret: Number of return value.
570 * @ret: Guest address to write return values to.
572 * Call an RTAS function
574 uint64_t qtest_rtas_call(QTestState
*s
, const char *name
,
575 uint32_t nargs
, uint64_t args
,
576 uint32_t nret
, uint64_t ret
);
580 * @s: #QTestState instance to operate on.
581 * @addr: Guest address to read from.
582 * @data: Pointer to where memory contents will be stored.
583 * @size: Number of bytes to read.
585 * Read guest memory into a buffer and receive using a base64 encoding.
587 void qtest_bufread(QTestState
*s
, uint64_t addr
, void *data
, size_t size
);
591 * @s: #QTestState instance to operate on.
592 * @addr: Guest address to write to.
593 * @data: Pointer to the bytes that will be written to guest memory.
594 * @size: Number of bytes to write.
596 * Write a buffer to guest memory.
598 void qtest_memwrite(QTestState
*s
, uint64_t addr
, const void *data
, size_t size
);
602 * @s: #QTestState instance to operate on.
603 * @addr: Guest address to write to.
604 * @data: Pointer to the bytes that will be written to guest memory.
605 * @size: Number of bytes to write.
607 * Write a buffer to guest memory and transmit using a base64 encoding.
609 void qtest_bufwrite(QTestState
*s
, uint64_t addr
,
610 const void *data
, size_t size
);
614 * @s: #QTestState instance to operate on.
615 * @addr: Guest address to write to.
616 * @patt: Byte pattern to fill the guest memory region with.
617 * @size: Number of bytes to write.
619 * Write a pattern to guest memory.
621 void qtest_memset(QTestState
*s
, uint64_t addr
, uint8_t patt
, size_t size
);
624 * qtest_clock_step_next:
625 * @s: #QTestState instance to operate on.
627 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
629 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
631 int64_t qtest_clock_step_next(QTestState
*s
);
635 * @s: QTestState instance to operate on.
636 * @step: Number of nanoseconds to advance the clock by.
638 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
640 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
642 int64_t qtest_clock_step(QTestState
*s
, int64_t step
);
646 * @s: QTestState instance to operate on.
647 * @val: Nanoseconds value to advance the clock to.
649 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
651 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
653 int64_t qtest_clock_set(QTestState
*s
, int64_t val
);
657 * @s: QTestState instance to operate on.
659 * Returns: True if the architecture under test has a big endian configuration.
661 bool qtest_big_endian(QTestState
*s
);
666 * Returns: The architecture for the QEMU executable under test.
668 const char *qtest_get_arch(void);
672 * @accel_name: Accelerator name to check for.
674 * Returns: true if the accelerator is built in.
676 bool qtest_has_accel(const char *accel_name
);
680 * @str: Test case path.
681 * @fn: Test case function
683 * Add a GTester testcase with the given name and function.
684 * The path is prefixed with the architecture under test, as
685 * returned by qtest_get_arch().
687 void qtest_add_func(const char *str
, void (*fn
)(void));
690 * qtest_add_data_func:
691 * @str: Test case path.
692 * @data: Test case data
693 * @fn: Test case function
695 * Add a GTester testcase with the given name, data and function.
696 * The path is prefixed with the architecture under test, as
697 * returned by qtest_get_arch().
699 void qtest_add_data_func(const char *str
, const void *data
,
700 void (*fn
)(const void *));
703 * qtest_add_data_func_full:
704 * @str: Test case path.
705 * @data: Test case data
706 * @fn: Test case function
707 * @data_free_func: GDestroyNotify for data
709 * Add a GTester testcase with the given name, data and function.
710 * The path is prefixed with the architecture under test, as
711 * returned by qtest_get_arch().
713 * @data is passed to @data_free_func() on test completion.
715 void qtest_add_data_func_full(const char *str
, void *data
,
716 void (*fn
)(const void *),
717 GDestroyNotify data_free_func
);
721 * @testpath: Test case path
722 * @Fixture: Fixture type
723 * @tdata: Test case data
724 * @fsetup: Test case setup function
725 * @ftest: Test case function
726 * @fteardown: Test case teardown function
728 * Add a GTester testcase with the given name, data and functions.
729 * The path is prefixed with the architecture under test, as
730 * returned by qtest_get_arch().
732 #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
734 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
735 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
740 * qtest_add_abrt_handler:
741 * @fn: Handler function
742 * @data: Argument that is passed to the handler
744 * Add a handler function that is invoked on SIGABRT. This can be used to
745 * terminate processes and perform other cleanup. The handler can be removed
746 * with qtest_remove_abrt_handler().
748 void qtest_add_abrt_handler(GHookFunc fn
, const void *data
);
751 * qtest_remove_abrt_handler:
752 * @data: Argument previously passed to qtest_add_abrt_handler()
754 * Remove an abrt handler that was previously added with
755 * qtest_add_abrt_handler().
757 void qtest_remove_abrt_handler(void *data
);
760 * qtest_vqmp_assert_success_ref:
761 * @qts: QTestState instance to operate on
762 * @fmt: QMP message to send to qemu, formatted like
763 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
764 * supported after '%'.
765 * @args: variable arguments for @fmt
767 * Sends a QMP message to QEMU, asserts that a 'return' key is present in
768 * the response, and returns the response.
770 QDict
*qtest_vqmp_assert_success_ref(QTestState
*qts
,
771 const char *fmt
, va_list args
)
775 * qtest_vqmp_assert_success:
776 * @qts: QTestState instance to operate on
777 * @fmt: QMP message to send to qemu, formatted like
778 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
779 * supported after '%'.
780 * @args: variable arguments for @fmt
782 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
785 void qtest_vqmp_assert_success(QTestState
*qts
,
786 const char *fmt
, va_list args
)
791 * qtest_vqmp_fds_assert_success_ref:
792 * @qts: QTestState instance to operate on
793 * @fds: the file descriptors to send
794 * @nfds: number of @fds to send
795 * @fmt: QMP message to send to qemu, formatted like
796 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
797 * supported after '%'.
798 * @args: variable arguments for @fmt
800 * Sends a QMP message with file descriptors to QEMU,
801 * asserts that a 'return' key is present in the response,
802 * and returns the response.
804 QDict
*qtest_vqmp_fds_assert_success_ref(QTestState
*qts
, int *fds
, size_t nfds
,
805 const char *fmt
, va_list args
)
809 * qtest_vqmp_fds_assert_success:
810 * @qts: QTestState instance to operate on
811 * @fds: the file descriptors to send
812 * @nfds: number of @fds to send
813 * @fmt: QMP message to send to qemu, formatted like
814 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
815 * supported after '%'.
816 * @args: variable arguments for @fmt
818 * Sends a QMP message with file descriptors to QEMU and
819 * asserts that a 'return' key is present in the response.
821 void qtest_vqmp_fds_assert_success(QTestState
*qts
, int *fds
, size_t nfds
,
822 const char *fmt
, va_list args
)
827 * qtest_qmp_assert_failure_ref:
828 * @qts: QTestState instance to operate on
829 * @fmt: QMP message to send to qemu, formatted like
830 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
831 * supported after '%'.
833 * Sends a QMP message to QEMU, asserts that an 'error' key is present in
834 * the response, and returns the response.
836 QDict
*qtest_qmp_assert_failure_ref(QTestState
*qts
, const char *fmt
, ...)
840 * qtest_vqmp_assert_failure_ref:
841 * @qts: QTestState instance to operate on
842 * @fmt: QMP message to send to qemu, formatted like
843 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
844 * supported after '%'.
845 * @args: variable arguments for @fmt
847 * Sends a QMP message to QEMU, asserts that an 'error' key is present in
848 * the response, and returns the response.
850 QDict
*qtest_vqmp_assert_failure_ref(QTestState
*qts
,
851 const char *fmt
, va_list args
)
855 * qtest_qmp_assert_success_ref:
856 * @qts: QTestState instance to operate on
857 * @fmt: QMP message to send to qemu, formatted like
858 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
859 * supported after '%'.
861 * Sends a QMP message to QEMU, asserts that a 'return' key is present in
862 * the response, and returns the response.
864 QDict
*qtest_qmp_assert_success_ref(QTestState
*qts
, const char *fmt
, ...)
868 * qtest_qmp_assert_success:
869 * @qts: QTestState instance to operate on
870 * @fmt: QMP message to send to qemu, formatted like
871 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
872 * supported after '%'.
874 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
877 void qtest_qmp_assert_success(QTestState
*qts
, const char *fmt
, ...)
882 * qtest_qmp_fd_assert_success_ref:
883 * @qts: QTestState instance to operate on
884 * @fds: the file descriptors to send
885 * @nfds: number of @fds to send
886 * @fmt: QMP message to send to qemu, formatted like
887 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
888 * supported after '%'.
890 * Sends a QMP message with file descriptors to QEMU,
891 * asserts that a 'return' key is present in the response,
892 * and returns the response.
894 QDict
*qtest_qmp_fds_assert_success_ref(QTestState
*qts
, int *fds
, size_t nfds
,
895 const char *fmt
, ...)
899 * qtest_qmp_fd_assert_success:
900 * @qts: QTestState instance to operate on
901 * @fds: the file descriptors to send
902 * @nfds: number of @fds to send
903 * @fmt: QMP message to send to qemu, formatted like
904 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
905 * supported after '%'.
907 * Sends a QMP message with file descriptors to QEMU and
908 * asserts that a 'return' key is present in the response.
910 void qtest_qmp_fds_assert_success(QTestState
*qts
, int *fds
, size_t nfds
,
911 const char *fmt
, ...)
916 * qtest_cb_for_every_machine:
917 * @cb: Pointer to the callback function
918 * @skip_old_versioned: true if versioned old machine types should be skipped
920 * Call a callback function for every name of all available machines.
922 void qtest_cb_for_every_machine(void (*cb
)(const char *machine
),
923 bool skip_old_versioned
);
926 * qtest_resolve_machine_alias:
927 * @var: Environment variable from where to take the QEMU binary
928 * @alias: The alias to resolve
930 * Returns: the machine type corresponding to the alias if any,
933 char *qtest_resolve_machine_alias(const char *var
, const char *alias
);
937 * @machine: The machine to look for
939 * Returns: true if the machine is available in the target binary.
941 bool qtest_has_machine(const char *machine
);
944 * qtest_has_machine_with_env:
945 * @var: Environment variable from where to take the QEMU binary
946 * @machine: The machine to look for
948 * Returns: true if the machine is available in the specified binary.
950 bool qtest_has_machine_with_env(const char *var
, const char *machine
);
953 * qtest_has_cpu_model:
954 * @cpu: The cpu to look for
956 * Returns: true if the cpu is available in the target binary.
958 bool qtest_has_cpu_model(const char *cpu
);
962 * @device: The device to look for
964 * Returns: true if the device is available in the target binary.
966 bool qtest_has_device(const char *device
);
969 * qtest_qmp_device_add_qdict:
970 * @qts: QTestState instance to operate on
971 * @drv: Name of the device that should be added
972 * @arguments: QDict with properties for the device to initialize
974 * Generic hot-plugging test via the device_add QMP command with properties
975 * supplied in form of QDict. Use NULL for empty properties list.
977 void qtest_qmp_device_add_qdict(QTestState
*qts
, const char *drv
,
978 const QDict
*arguments
);
981 * qtest_qmp_device_add:
982 * @qts: QTestState instance to operate on
983 * @driver: Name of the device that should be added
984 * @id: Identification string
985 * @fmt: QMP message to send to qemu, formatted like
986 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
987 * supported after '%'.
989 * Generic hot-plugging test via the device_add QMP command.
991 void qtest_qmp_device_add(QTestState
*qts
, const char *driver
, const char *id
,
992 const char *fmt
, ...) G_GNUC_PRINTF(4, 5);
995 * qtest_qmp_add_client:
996 * @qts: QTestState instance to operate on
997 * @protocol: the protocol to add to
998 * @fd: the client file-descriptor
1000 * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
1001 * ``add_client`` with the given @fd.
1003 void qtest_qmp_add_client(QTestState
*qts
, const char *protocol
, int fd
);
1006 * qtest_qmp_device_del_send:
1007 * @qts: QTestState instance to operate on
1008 * @id: Identification string
1010 * Generic hot-unplugging test via the device_del QMP command.
1012 void qtest_qmp_device_del_send(QTestState
*qts
, const char *id
);
1015 * qtest_qmp_device_del:
1016 * @qts: QTestState instance to operate on
1017 * @id: Identification string
1019 * Generic hot-unplugging test via the device_del QMP command.
1020 * Waiting for command completion event.
1022 void qtest_qmp_device_del(QTestState
*qts
, const char *id
);
1025 * qtest_probe_child:
1026 * @s: QTestState instance to operate on.
1028 * Returns: true if the child is still alive.
1030 bool qtest_probe_child(QTestState
*s
);
1033 * qtest_set_expected_status:
1034 * @s: QTestState instance to operate on.
1035 * @status: an expected exit status.
1037 * Set expected exit status of the child.
1039 void qtest_set_expected_status(QTestState
*s
, int status
);
1041 QTestState
*qtest_inproc_init(QTestState
**s
, bool log
, const char* arch
,
1042 void (*send
)(void*, const char*));
1044 void qtest_client_inproc_recv(void *opaque
, const char *str
);
1047 * qtest_qom_set_bool:
1048 * @s: QTestState instance to operate on.
1049 * @path: Path to the property being set.
1050 * @property: Property being set.
1051 * @value: Value to set the property.
1053 * Set the property with passed in value.
1055 void qtest_qom_set_bool(QTestState
*s
, const char *path
, const char *property
,
1059 * qtest_qom_get_bool:
1060 * @s: QTestState instance to operate on.
1061 * @path: Path to the property being retrieved.
1062 * @property: Property from where the value is being retrieved.
1064 * Returns: Value retrieved from property.
1066 bool qtest_qom_get_bool(QTestState
*s
, const char *path
, const char *property
);
1070 * @s: QTestState instance to operate on.
1072 * Returns: the PID of the QEMU process, or <= 0
1074 pid_t
qtest_pid(QTestState
*s
);
1079 * Returns: true if "qemu-img" is available.
1081 bool have_qemu_img(void);
1085 * @file: File name of the image that should be created
1086 * @fmt: Format, e.g. "qcow2" or "raw"
1087 * @size_mb: Size of the image in megabytes
1089 * Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG
1090 * environment variable must point to the qemu-img file.
1092 * Returns: true if the image has been created successfully.
1094 bool mkimg(const char *file
, const char *fmt
, unsigned size_mb
);