xref: /qemu/tests/qtest/libqtest.h (revision ed097649b55065b3b7da0ca54596e876b29c2561)
149ee3590SAnthony Liguori /*
249ee3590SAnthony Liguori  * QTest
349ee3590SAnthony Liguori  *
449ee3590SAnthony Liguori  * Copyright IBM, Corp. 2012
549ee3590SAnthony Liguori  * Copyright Red Hat, Inc. 2012
6872536bfSAndreas Färber  * Copyright SUSE LINUX Products GmbH 2013
749ee3590SAnthony Liguori  *
849ee3590SAnthony Liguori  * Authors:
949ee3590SAnthony Liguori  *  Anthony Liguori   <aliguori@us.ibm.com>
1049ee3590SAnthony Liguori  *  Paolo Bonzini     <pbonzini@redhat.com>
11872536bfSAndreas Färber  *  Andreas Färber    <afaerber@suse.de>
1249ee3590SAnthony Liguori  *
1349ee3590SAnthony Liguori  * This work is licensed under the terms of the GNU GPL, version 2 or later.
1449ee3590SAnthony Liguori  * See the COPYING file in the top-level directory.
1549ee3590SAnthony Liguori  *
1649ee3590SAnthony Liguori  */
1749ee3590SAnthony Liguori #ifndef LIBQTEST_H
1849ee3590SAnthony Liguori #define LIBQTEST_H
1949ee3590SAnthony Liguori 
205cb8f0dbSPaolo Bonzini #include "qapi/qmp/qobject.h"
215cb8f0dbSPaolo Bonzini #include "qapi/qmp/qdict.h"
22c6d3bcb4SMarc-André Lureau #include "libqmp.h"
235cb8f0dbSPaolo Bonzini 
2449ee3590SAnthony Liguori typedef struct QTestState QTestState;
2549ee3590SAnthony Liguori 
2649ee3590SAnthony Liguori /**
2788b988c8SMarkus Armbruster  * qtest_initf:
2851c778edSEduardo Habkost  * @fmt: Format for creating other arguments to pass to QEMU, formatted
2978b27badSEric Blake  * like sprintf().
3078b27badSEric Blake  *
3100825d96SThomas Huth  * Convenience wrapper around qtest_init().
3278b27badSEric Blake  *
3378b27badSEric Blake  * Returns: #QTestState instance.
3478b27badSEric Blake  */
359edc6313SMarc-André Lureau QTestState *qtest_initf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
3678b27badSEric Blake 
3778b27badSEric Blake /**
3888b988c8SMarkus Armbruster  * qtest_vinitf:
3978b27badSEric Blake  * @fmt: Format for creating other arguments to pass to QEMU, formatted
4078b27badSEric Blake  * like vsprintf().
4178b27badSEric Blake  * @ap: Format arguments.
4278b27badSEric Blake  *
4300825d96SThomas Huth  * Convenience wrapper around qtest_init().
4478b27badSEric Blake  *
4578b27badSEric Blake  * Returns: #QTestState instance.
4678b27badSEric Blake  */
479edc6313SMarc-André Lureau QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
4878b27badSEric Blake 
4978b27badSEric Blake /**
5049ee3590SAnthony Liguori  * qtest_init:
5188b988c8SMarkus Armbruster  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
5288b988c8SMarkus Armbruster  * arguments are subject to word splitting and shell evaluation.
536acf801dSAndreas Färber  *
546acf801dSAndreas Färber  * Returns: #QTestState instance.
5549ee3590SAnthony Liguori  */
5649ee3590SAnthony Liguori QTestState *qtest_init(const char *extra_args);
5749ee3590SAnthony Liguori 
5849ee3590SAnthony Liguori /**
59f66e7ac8SMarkus Armbruster  * qtest_init_without_qmp_handshake:
60ddee57e0SEric Blake  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
61ddee57e0SEric Blake  * arguments are subject to word splitting and shell evaluation.
62f66e7ac8SMarkus Armbruster  *
63f66e7ac8SMarkus Armbruster  * Returns: #QTestState instance.
64f66e7ac8SMarkus Armbruster  */
65192f26a7SPeter Xu QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
66f66e7ac8SMarkus Armbruster 
67f66e7ac8SMarkus Armbruster /**
686c90a82cSJulia Suvorova  * qtest_init_with_serial:
696c90a82cSJulia Suvorova  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
706c90a82cSJulia Suvorova  * arguments are subject to word splitting and shell evaluation.
716c90a82cSJulia Suvorova  * @sock_fd: pointer to store the socket file descriptor for
726c90a82cSJulia Suvorova  * connection with serial.
736c90a82cSJulia Suvorova  *
746c90a82cSJulia Suvorova  * Returns: #QTestState instance.
756c90a82cSJulia Suvorova  */
766c90a82cSJulia Suvorova QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
776c90a82cSJulia Suvorova 
786c90a82cSJulia Suvorova /**
7969c056fbSBin Meng  * qtest_wait_qemu:
8069c056fbSBin Meng  * @s: #QTestState instance to operate on.
8169c056fbSBin Meng  *
8269c056fbSBin Meng  * Wait for the QEMU process to terminate. It is safe to call this function
8369c056fbSBin Meng  * multiple times.
8469c056fbSBin Meng  */
8569c056fbSBin Meng void qtest_wait_qemu(QTestState *s);
8669c056fbSBin Meng 
8769c056fbSBin Meng /**
887a23c523SStefan Hajnoczi  * qtest_kill_qemu:
897a23c523SStefan Hajnoczi  * @s: #QTestState instance to operate on.
907a23c523SStefan Hajnoczi  *
917a23c523SStefan Hajnoczi  * Kill the QEMU process and wait for it to terminate. It is safe to call this
927a23c523SStefan Hajnoczi  * function multiple times. Normally qtest_quit() is used instead because it
937a23c523SStefan Hajnoczi  * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
947a23c523SStefan Hajnoczi  * and qtest_quit() will be called later.
957a23c523SStefan Hajnoczi  */
967a23c523SStefan Hajnoczi void qtest_kill_qemu(QTestState *s);
977a23c523SStefan Hajnoczi 
987a23c523SStefan Hajnoczi /**
9949ee3590SAnthony Liguori  * qtest_quit:
1006acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
10149ee3590SAnthony Liguori  *
10249ee3590SAnthony Liguori  * Shut down the QEMU process associated to @s.
10349ee3590SAnthony Liguori  */
10449ee3590SAnthony Liguori void qtest_quit(QTestState *s);
10549ee3590SAnthony Liguori 
106490081b2SBin Meng #ifndef _WIN32
10749ee3590SAnthony Liguori /**
10824d5588cSYury Kotov  * qtest_qmp_fds:
10924d5588cSYury Kotov  * @s: #QTestState instance to operate on.
11024d5588cSYury Kotov  * @fds: array of file descriptors
11124d5588cSYury Kotov  * @fds_num: number of elements in @fds
11251c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
113ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
11424d5588cSYury Kotov  * supported after '%'.
11524d5588cSYury Kotov  *
11624d5588cSYury Kotov  * Sends a QMP message to QEMU with fds and returns the response.
11724d5588cSYury Kotov  */
11824d5588cSYury Kotov QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
11924d5588cSYury Kotov                      const char *fmt, ...)
1209edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 5);
121490081b2SBin Meng #endif /* _WIN32 */
12224d5588cSYury Kotov 
12324d5588cSYury Kotov /**
1240c460dacSStefan Hajnoczi  * qtest_qmp:
1250c460dacSStefan Hajnoczi  * @s: #QTestState instance to operate on.
12651c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
127ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
1286ce80fd8SMarkus Armbruster  * supported after '%'.
1290c460dacSStefan Hajnoczi  *
1300c460dacSStefan Hajnoczi  * Sends a QMP message to QEMU and returns the response.
1310c460dacSStefan Hajnoczi  */
132e3dc93beSMarkus Armbruster QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
1339edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
1340c460dacSStefan Hajnoczi 
1350c460dacSStefan Hajnoczi /**
1364277f1ebSMarkus Armbruster  * qtest_qmp_send:
137ba4ed393SJohn Snow  * @s: #QTestState instance to operate on.
13851c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
139ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
1406ce80fd8SMarkus Armbruster  * supported after '%'.
141ba4ed393SJohn Snow  *
142ba4ed393SJohn Snow  * Sends a QMP message to QEMU and leaves the response in the stream.
143ba4ed393SJohn Snow  */
144e3dc93beSMarkus Armbruster void qtest_qmp_send(QTestState *s, const char *fmt, ...)
1459edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
146ba4ed393SJohn Snow 
147ba4ed393SJohn Snow /**
148aed877c5SMarkus Armbruster  * qtest_qmp_send_raw:
149aed877c5SMarkus Armbruster  * @s: #QTestState instance to operate on.
15051c778edSEduardo Habkost  * @fmt: text to send, formatted like sprintf()
151aed877c5SMarkus Armbruster  *
152aed877c5SMarkus Armbruster  * Sends text to the QMP monitor verbatim.  Need not be valid JSON;
153aed877c5SMarkus Armbruster  * this is useful for negative tests.
154aed877c5SMarkus Armbruster  */
155aed877c5SMarkus Armbruster void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
1569edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
157aed877c5SMarkus Armbruster 
158aed877c5SMarkus Armbruster /**
1599fb7bb06SStefan Hajnoczi  * qtest_socket_server:
1609fb7bb06SStefan Hajnoczi  * @socket_path: the UNIX domain socket path
1619fb7bb06SStefan Hajnoczi  *
1629fb7bb06SStefan Hajnoczi  * Create and return a listen socket file descriptor, or abort on failure.
1639fb7bb06SStefan Hajnoczi  */
1649fb7bb06SStefan Hajnoczi int qtest_socket_server(const char *socket_path);
1659fb7bb06SStefan Hajnoczi 
166490081b2SBin Meng #ifndef _WIN32
1679fb7bb06SStefan Hajnoczi /**
16824d5588cSYury Kotov  * qtest_vqmp_fds:
16924d5588cSYury Kotov  * @s: #QTestState instance to operate on.
17024d5588cSYury Kotov  * @fds: array of file descriptors
17124d5588cSYury Kotov  * @fds_num: number of elements in @fds
17224d5588cSYury Kotov  * @fmt: QMP message to send to QEMU, formatted like
173ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
17424d5588cSYury Kotov  * supported after '%'.
17524d5588cSYury Kotov  * @ap: QMP message arguments
17624d5588cSYury Kotov  *
17724d5588cSYury Kotov  * Sends a QMP message to QEMU with fds and returns the response.
17824d5588cSYury Kotov  */
17924d5588cSYury Kotov QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
18024d5588cSYury Kotov                       const char *fmt, va_list ap)
1819edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 0);
182490081b2SBin Meng #endif /* _WIN32 */
18324d5588cSYury Kotov 
18424d5588cSYury Kotov /**
18524d5588cSYury Kotov  * qtest_vqmp:
1860c460dacSStefan Hajnoczi  * @s: #QTestState instance to operate on.
187bb340eb2SEric Blake  * @fmt: QMP message to send to QEMU, formatted like
188ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
1896ce80fd8SMarkus Armbruster  * supported after '%'.
1900c460dacSStefan Hajnoczi  * @ap: QMP message arguments
1910c460dacSStefan Hajnoczi  *
1920c460dacSStefan Hajnoczi  * Sends a QMP message to QEMU and returns the response.
1930c460dacSStefan Hajnoczi  */
194248eef02SMarkus Armbruster QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
1959edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
1960c460dacSStefan Hajnoczi 
197490081b2SBin Meng #ifndef _WIN32
1980c460dacSStefan Hajnoczi /**
19924d5588cSYury Kotov  * qtest_qmp_vsend_fds:
20024d5588cSYury Kotov  * @s: #QTestState instance to operate on.
20124d5588cSYury Kotov  * @fds: array of file descriptors
20224d5588cSYury Kotov  * @fds_num: number of elements in @fds
20324d5588cSYury Kotov  * @fmt: QMP message to send to QEMU, formatted like
204ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
20524d5588cSYury Kotov  * supported after '%'.
20624d5588cSYury Kotov  * @ap: QMP message arguments
20724d5588cSYury Kotov  *
20824d5588cSYury Kotov  * Sends a QMP message to QEMU and leaves the response in the stream.
20924d5588cSYury Kotov  */
21024d5588cSYury Kotov void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
21124d5588cSYury Kotov                          const char *fmt, va_list ap)
2129edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 0);
213490081b2SBin Meng #endif /* _WIN32 */
21424d5588cSYury Kotov 
21524d5588cSYury Kotov /**
2164277f1ebSMarkus Armbruster  * qtest_qmp_vsend:
217ba4ed393SJohn Snow  * @s: #QTestState instance to operate on.
218bb340eb2SEric Blake  * @fmt: QMP message to send to QEMU, formatted like
219ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
2206ce80fd8SMarkus Armbruster  * supported after '%'.
221ba4ed393SJohn Snow  * @ap: QMP message arguments
222ba4ed393SJohn Snow  *
223ba4ed393SJohn Snow  * Sends a QMP message to QEMU and leaves the response in the stream.
224ba4ed393SJohn Snow  */
225e3dc93beSMarkus Armbruster void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
2269edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
227ba4ed393SJohn Snow 
228ba4ed393SJohn Snow /**
2291c3e2a38SMaxim Levitsky  * qtest_qmp_receive_dict:
23066e0c7b1SAndreas Färber  * @s: #QTestState instance to operate on.
23166e0c7b1SAndreas Färber  *
23266e0c7b1SAndreas Färber  * Reads a QMP message from QEMU and returns the response.
23366e0c7b1SAndreas Färber  */
2341c3e2a38SMaxim Levitsky QDict *qtest_qmp_receive_dict(QTestState *s);
23566e0c7b1SAndreas Färber 
23666e0c7b1SAndreas Färber /**
237c22045bfSMaxim Levitsky  * qtest_qmp_receive:
238c22045bfSMaxim Levitsky  * @s: #QTestState instance to operate on.
239c22045bfSMaxim Levitsky  *
240c22045bfSMaxim Levitsky  * Reads a QMP message from QEMU and returns the response.
2410150e75dSDaniel P. Berrangé  *
2420150e75dSDaniel P. Berrangé  * If a callback is registered with qtest_qmp_set_event_callback,
2430150e75dSDaniel P. Berrangé  * it will be invoked for every event seen, otherwise events
2440150e75dSDaniel P. Berrangé  * will be buffered until a call to one of the qtest_qmp_eventwait
2450150e75dSDaniel P. Berrangé  * family of functions.
246c22045bfSMaxim Levitsky  */
247c22045bfSMaxim Levitsky QDict *qtest_qmp_receive(QTestState *s);
248c22045bfSMaxim Levitsky 
2490150e75dSDaniel P. Berrangé /*
2500150e75dSDaniel P. Berrangé  * QTestQMPEventCallback:
2510150e75dSDaniel P. Berrangé  * @s: #QTestState instance event was received on
2520150e75dSDaniel P. Berrangé  * @name: name of the event type
2530150e75dSDaniel P. Berrangé  * @event: #QDict for the event details
2540150e75dSDaniel P. Berrangé  * @opaque: opaque data from time of callback registration
2550150e75dSDaniel P. Berrangé  *
2560150e75dSDaniel P. Berrangé  * This callback will be invoked whenever an event is received.
2570150e75dSDaniel P. Berrangé  * If the callback returns true the event will be consumed,
2580150e75dSDaniel P. Berrangé  * otherwise it will be put on the list of pending events.
2590150e75dSDaniel P. Berrangé  * Pending events can be later handled by calling either
2600150e75dSDaniel P. Berrangé  * qtest_qmp_eventwait or qtest_qmp_eventwait_ref.
2610150e75dSDaniel P. Berrangé  *
2620150e75dSDaniel P. Berrangé  * Return: true to consume the event, false to let it be queued
2630150e75dSDaniel P. Berrangé  */
2640150e75dSDaniel P. Berrangé typedef bool (*QTestQMPEventCallback)(QTestState *s, const char *name,
2650150e75dSDaniel P. Berrangé                                       QDict *event, void *opaque);
2660150e75dSDaniel P. Berrangé 
2670150e75dSDaniel P. Berrangé /**
2680150e75dSDaniel P. Berrangé  * qtest_qmp_set_event_callback:
2690150e75dSDaniel P. Berrangé  * @s: #QTestSTate instance to operate on
2700150e75dSDaniel P. Berrangé  * @cb: callback to invoke for events
2710150e75dSDaniel P. Berrangé  * @opaque: data to pass to @cb
2720150e75dSDaniel P. Berrangé  *
2730150e75dSDaniel P. Berrangé  * Register a callback to be invoked whenever an event arrives
2740150e75dSDaniel P. Berrangé  */
2750150e75dSDaniel P. Berrangé void qtest_qmp_set_event_callback(QTestState *s,
2760150e75dSDaniel P. Berrangé                                   QTestQMPEventCallback cb, void *opaque);
2770150e75dSDaniel P. Berrangé 
278c22045bfSMaxim Levitsky /**
2798fe941f7SJohn Snow  * qtest_qmp_eventwait:
2808fe941f7SJohn Snow  * @s: #QTestState instance to operate on.
28151c778edSEduardo Habkost  * @event: event to wait for.
2828fe941f7SJohn Snow  *
283e8ec0117SEric Blake  * Continuously polls for QMP responses until it receives the desired event.
2840150e75dSDaniel P. Berrangé  *
2850150e75dSDaniel P. Berrangé  * Any callback registered with qtest_qmp_set_event_callback will
2860150e75dSDaniel P. Berrangé  * be invoked for every event seen.
2878fe941f7SJohn Snow  */
2888fe941f7SJohn Snow void qtest_qmp_eventwait(QTestState *s, const char *event);
2898fe941f7SJohn Snow 
2908fe941f7SJohn Snow /**
2917ffe3124SJohn Snow  * qtest_qmp_eventwait_ref:
2927ffe3124SJohn Snow  * @s: #QTestState instance to operate on.
29351c778edSEduardo Habkost  * @event: event to wait for.
2947ffe3124SJohn Snow  *
295e8ec0117SEric Blake  * Continuously polls for QMP responses until it receives the desired event.
2960150e75dSDaniel P. Berrangé  *
2970150e75dSDaniel P. Berrangé  * Any callback registered with qtest_qmp_set_event_callback will
2980150e75dSDaniel P. Berrangé  * be invoked for every event seen.
2990150e75dSDaniel P. Berrangé  *
3007ffe3124SJohn Snow  * Returns a copy of the event for further investigation.
3017ffe3124SJohn Snow  */
3027ffe3124SJohn Snow QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
3037ffe3124SJohn Snow 
3047ffe3124SJohn Snow /**
305c22045bfSMaxim Levitsky  * qtest_qmp_event_ref:
306c22045bfSMaxim Levitsky  * @s: #QTestState instance to operate on.
307c22045bfSMaxim Levitsky  * @event: event to return.
308c22045bfSMaxim Levitsky  *
309c22045bfSMaxim Levitsky  * Removes non-matching events from the buffer that was set by
310c22045bfSMaxim Levitsky  * qtest_qmp_receive, until an event bearing the given name is found,
311c22045bfSMaxim Levitsky  * and returns it.
312c22045bfSMaxim Levitsky  * If no event matches, clears the buffer and returns NULL.
313c22045bfSMaxim Levitsky  *
314c22045bfSMaxim Levitsky  */
315c22045bfSMaxim Levitsky QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
316c22045bfSMaxim Levitsky 
317c22045bfSMaxim Levitsky /**
3186bb87be8SThomas Huth  * qtest_hmp:
3195fb48d96SMarkus Armbruster  * @s: #QTestState instance to operate on.
32051c778edSEduardo Habkost  * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
3215fb48d96SMarkus Armbruster  *
3225fb48d96SMarkus Armbruster  * Send HMP command to QEMU via QMP's human-monitor-command.
3236bb87be8SThomas Huth  * QMP events are discarded.
3245fb48d96SMarkus Armbruster  *
3255fb48d96SMarkus Armbruster  * Returns: the command's output.  The caller should g_free() it.
3265fb48d96SMarkus Armbruster  */
3279edc6313SMarc-André Lureau char *qtest_hmp(QTestState *s, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
3285fb48d96SMarkus Armbruster 
3295fb48d96SMarkus Armbruster /**
3305fb48d96SMarkus Armbruster  * qtest_hmpv:
3315fb48d96SMarkus Armbruster  * @s: #QTestState instance to operate on.
332bb340eb2SEric Blake  * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
3335fb48d96SMarkus Armbruster  * @ap: HMP command arguments
3345fb48d96SMarkus Armbruster  *
3355fb48d96SMarkus Armbruster  * Send HMP command to QEMU via QMP's human-monitor-command.
3366bb87be8SThomas Huth  * QMP events are discarded.
3375fb48d96SMarkus Armbruster  *
3385fb48d96SMarkus Armbruster  * Returns: the command's output.  The caller should g_free() it.
3395fb48d96SMarkus Armbruster  */
340248eef02SMarkus Armbruster char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
3419edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
3425fb48d96SMarkus Armbruster 
343eb062cfaSMarc-André Lureau void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
344eb062cfaSMarc-André Lureau 
3455fb48d96SMarkus Armbruster /**
34649ee3590SAnthony Liguori  * qtest_get_irq:
3476acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
34849ee3590SAnthony Liguori  * @num: Interrupt to observe.
34949ee3590SAnthony Liguori  *
3506acf801dSAndreas Färber  * Returns: The level of the @num interrupt.
35149ee3590SAnthony Liguori  */
35249ee3590SAnthony Liguori bool qtest_get_irq(QTestState *s, int num);
35349ee3590SAnthony Liguori 
35449ee3590SAnthony Liguori /**
35549ee3590SAnthony Liguori  * qtest_irq_intercept_in:
3566acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
35749ee3590SAnthony Liguori  * @string: QOM path of a device.
35849ee3590SAnthony Liguori  *
35949ee3590SAnthony Liguori  * Associate qtest irqs with the GPIO-in pins of the device
36049ee3590SAnthony Liguori  * whose path is specified by @string.
36149ee3590SAnthony Liguori  */
36249ee3590SAnthony Liguori void qtest_irq_intercept_in(QTestState *s, const char *string);
36349ee3590SAnthony Liguori 
36449ee3590SAnthony Liguori /**
36549ee3590SAnthony Liguori  * qtest_irq_intercept_out:
3666acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
36749ee3590SAnthony Liguori  * @string: QOM path of a device.
36849ee3590SAnthony Liguori  *
36949ee3590SAnthony Liguori  * Associate qtest irqs with the GPIO-out pins of the device
37049ee3590SAnthony Liguori  * whose path is specified by @string.
37149ee3590SAnthony Liguori  */
37249ee3590SAnthony Liguori void qtest_irq_intercept_out(QTestState *s, const char *string);
37349ee3590SAnthony Liguori 
37449ee3590SAnthony Liguori /**
3759813dc6aSSteffen Görtz  * qtest_set_irq_in:
3769813dc6aSSteffen Görtz  * @s: QTestState instance to operate on.
3779813dc6aSSteffen Görtz  * @string: QOM path of a device
3789813dc6aSSteffen Görtz  * @name: IRQ name
3799813dc6aSSteffen Görtz  * @irq: IRQ number
3809813dc6aSSteffen Görtz  * @level: IRQ level
3819813dc6aSSteffen Görtz  *
3829813dc6aSSteffen Görtz  * Force given device/irq GPIO-in pin to the given level.
3839813dc6aSSteffen Görtz  */
3849813dc6aSSteffen Görtz void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
3859813dc6aSSteffen Görtz                       int irq, int level);
3869813dc6aSSteffen Görtz 
3879813dc6aSSteffen Görtz /**
38849ee3590SAnthony Liguori  * qtest_outb:
3896acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
39049ee3590SAnthony Liguori  * @addr: I/O port to write to.
39149ee3590SAnthony Liguori  * @value: Value being written.
39249ee3590SAnthony Liguori  *
39349ee3590SAnthony Liguori  * Write an 8-bit value to an I/O port.
39449ee3590SAnthony Liguori  */
39549ee3590SAnthony Liguori void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
39649ee3590SAnthony Liguori 
39749ee3590SAnthony Liguori /**
39849ee3590SAnthony Liguori  * qtest_outw:
3996acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
40049ee3590SAnthony Liguori  * @addr: I/O port to write to.
40149ee3590SAnthony Liguori  * @value: Value being written.
40249ee3590SAnthony Liguori  *
40349ee3590SAnthony Liguori  * Write a 16-bit value to an I/O port.
40449ee3590SAnthony Liguori  */
40549ee3590SAnthony Liguori void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
40649ee3590SAnthony Liguori 
40749ee3590SAnthony Liguori /**
40849ee3590SAnthony Liguori  * qtest_outl:
4096acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
41049ee3590SAnthony Liguori  * @addr: I/O port to write to.
41149ee3590SAnthony Liguori  * @value: Value being written.
41249ee3590SAnthony Liguori  *
41349ee3590SAnthony Liguori  * Write a 32-bit value to an I/O port.
41449ee3590SAnthony Liguori  */
41549ee3590SAnthony Liguori void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
41649ee3590SAnthony Liguori 
41749ee3590SAnthony Liguori /**
41849ee3590SAnthony Liguori  * qtest_inb:
4196acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
42049ee3590SAnthony Liguori  * @addr: I/O port to read from.
42149ee3590SAnthony Liguori  *
42249ee3590SAnthony Liguori  * Returns an 8-bit value from an I/O port.
42349ee3590SAnthony Liguori  */
42449ee3590SAnthony Liguori uint8_t qtest_inb(QTestState *s, uint16_t addr);
42549ee3590SAnthony Liguori 
42649ee3590SAnthony Liguori /**
42749ee3590SAnthony Liguori  * qtest_inw:
4286acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
42949ee3590SAnthony Liguori  * @addr: I/O port to read from.
43049ee3590SAnthony Liguori  *
43149ee3590SAnthony Liguori  * Returns a 16-bit value from an I/O port.
43249ee3590SAnthony Liguori  */
43349ee3590SAnthony Liguori uint16_t qtest_inw(QTestState *s, uint16_t addr);
43449ee3590SAnthony Liguori 
43549ee3590SAnthony Liguori /**
43649ee3590SAnthony Liguori  * qtest_inl:
4376acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
43849ee3590SAnthony Liguori  * @addr: I/O port to read from.
43949ee3590SAnthony Liguori  *
44049ee3590SAnthony Liguori  * Returns a 32-bit value from an I/O port.
44149ee3590SAnthony Liguori  */
44249ee3590SAnthony Liguori uint32_t qtest_inl(QTestState *s, uint16_t addr);
44349ee3590SAnthony Liguori 
44449ee3590SAnthony Liguori /**
445872536bfSAndreas Färber  * qtest_writeb:
446872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
447872536bfSAndreas Färber  * @addr: Guest address to write to.
448872536bfSAndreas Färber  * @value: Value being written.
449872536bfSAndreas Färber  *
450872536bfSAndreas Färber  * Writes an 8-bit value to memory.
451872536bfSAndreas Färber  */
452872536bfSAndreas Färber void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
453872536bfSAndreas Färber 
454872536bfSAndreas Färber /**
455872536bfSAndreas Färber  * qtest_writew:
456872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
457872536bfSAndreas Färber  * @addr: Guest address to write to.
458872536bfSAndreas Färber  * @value: Value being written.
459872536bfSAndreas Färber  *
460872536bfSAndreas Färber  * Writes a 16-bit value to memory.
461872536bfSAndreas Färber  */
462872536bfSAndreas Färber void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
463872536bfSAndreas Färber 
464872536bfSAndreas Färber /**
465872536bfSAndreas Färber  * qtest_writel:
466872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
467872536bfSAndreas Färber  * @addr: Guest address to write to.
468872536bfSAndreas Färber  * @value: Value being written.
469872536bfSAndreas Färber  *
470872536bfSAndreas Färber  * Writes a 32-bit value to memory.
471872536bfSAndreas Färber  */
472872536bfSAndreas Färber void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
473872536bfSAndreas Färber 
474872536bfSAndreas Färber /**
475872536bfSAndreas Färber  * qtest_writeq:
476872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
477872536bfSAndreas Färber  * @addr: Guest address to write to.
478872536bfSAndreas Färber  * @value: Value being written.
479872536bfSAndreas Färber  *
480872536bfSAndreas Färber  * Writes a 64-bit value to memory.
481872536bfSAndreas Färber  */
482872536bfSAndreas Färber void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
483872536bfSAndreas Färber 
484872536bfSAndreas Färber /**
485872536bfSAndreas Färber  * qtest_readb:
486872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
487872536bfSAndreas Färber  * @addr: Guest address to read from.
488872536bfSAndreas Färber  *
489872536bfSAndreas Färber  * Reads an 8-bit value from memory.
490872536bfSAndreas Färber  *
491872536bfSAndreas Färber  * Returns: Value read.
492872536bfSAndreas Färber  */
493872536bfSAndreas Färber uint8_t qtest_readb(QTestState *s, uint64_t addr);
494872536bfSAndreas Färber 
495872536bfSAndreas Färber /**
496872536bfSAndreas Färber  * qtest_readw:
497872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
498872536bfSAndreas Färber  * @addr: Guest address to read from.
499872536bfSAndreas Färber  *
500872536bfSAndreas Färber  * Reads a 16-bit value from memory.
501872536bfSAndreas Färber  *
502872536bfSAndreas Färber  * Returns: Value read.
503872536bfSAndreas Färber  */
504872536bfSAndreas Färber uint16_t qtest_readw(QTestState *s, uint64_t addr);
505872536bfSAndreas Färber 
506872536bfSAndreas Färber /**
507872536bfSAndreas Färber  * qtest_readl:
508872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
509872536bfSAndreas Färber  * @addr: Guest address to read from.
510872536bfSAndreas Färber  *
511872536bfSAndreas Färber  * Reads a 32-bit value from memory.
512872536bfSAndreas Färber  *
513872536bfSAndreas Färber  * Returns: Value read.
514872536bfSAndreas Färber  */
515872536bfSAndreas Färber uint32_t qtest_readl(QTestState *s, uint64_t addr);
516872536bfSAndreas Färber 
517872536bfSAndreas Färber /**
518872536bfSAndreas Färber  * qtest_readq:
519872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
520872536bfSAndreas Färber  * @addr: Guest address to read from.
521872536bfSAndreas Färber  *
522872536bfSAndreas Färber  * Reads a 64-bit value from memory.
523872536bfSAndreas Färber  *
524872536bfSAndreas Färber  * Returns: Value read.
525872536bfSAndreas Färber  */
526872536bfSAndreas Färber uint64_t qtest_readq(QTestState *s, uint64_t addr);
527872536bfSAndreas Färber 
528872536bfSAndreas Färber /**
52949ee3590SAnthony Liguori  * qtest_memread:
5306acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
53149ee3590SAnthony Liguori  * @addr: Guest address to read from.
53249ee3590SAnthony Liguori  * @data: Pointer to where memory contents will be stored.
53349ee3590SAnthony Liguori  * @size: Number of bytes to read.
53449ee3590SAnthony Liguori  *
53549ee3590SAnthony Liguori  * Read guest memory into a buffer.
53649ee3590SAnthony Liguori  */
53749ee3590SAnthony Liguori void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
53849ee3590SAnthony Liguori 
53949ee3590SAnthony Liguori /**
540eeddd59fSLaurent Vivier  * qtest_rtas_call:
541eeddd59fSLaurent Vivier  * @s: #QTestState instance to operate on.
542eeddd59fSLaurent Vivier  * @name: name of the command to call.
543eeddd59fSLaurent Vivier  * @nargs: Number of args.
544eeddd59fSLaurent Vivier  * @args: Guest address to read args from.
545eeddd59fSLaurent Vivier  * @nret: Number of return value.
546eeddd59fSLaurent Vivier  * @ret: Guest address to write return values to.
547eeddd59fSLaurent Vivier  *
548eeddd59fSLaurent Vivier  * Call an RTAS function
549eeddd59fSLaurent Vivier  */
550eeddd59fSLaurent Vivier uint64_t qtest_rtas_call(QTestState *s, const char *name,
551eeddd59fSLaurent Vivier                          uint32_t nargs, uint64_t args,
552eeddd59fSLaurent Vivier                          uint32_t nret, uint64_t ret);
553eeddd59fSLaurent Vivier 
554eeddd59fSLaurent Vivier /**
5557a6a740dSJohn Snow  * qtest_bufread:
5567a6a740dSJohn Snow  * @s: #QTestState instance to operate on.
5577a6a740dSJohn Snow  * @addr: Guest address to read from.
5587a6a740dSJohn Snow  * @data: Pointer to where memory contents will be stored.
5597a6a740dSJohn Snow  * @size: Number of bytes to read.
5607a6a740dSJohn Snow  *
5617a6a740dSJohn Snow  * Read guest memory into a buffer and receive using a base64 encoding.
5627a6a740dSJohn Snow  */
5637a6a740dSJohn Snow void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
5647a6a740dSJohn Snow 
5657a6a740dSJohn Snow /**
56649ee3590SAnthony Liguori  * qtest_memwrite:
5676acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
56849ee3590SAnthony Liguori  * @addr: Guest address to write to.
56949ee3590SAnthony Liguori  * @data: Pointer to the bytes that will be written to guest memory.
57049ee3590SAnthony Liguori  * @size: Number of bytes to write.
57149ee3590SAnthony Liguori  *
57249ee3590SAnthony Liguori  * Write a buffer to guest memory.
57349ee3590SAnthony Liguori  */
57449ee3590SAnthony Liguori void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
57549ee3590SAnthony Liguori 
57649ee3590SAnthony Liguori /**
5777a6a740dSJohn Snow  * qtest_bufwrite:
5787a6a740dSJohn Snow  * @s: #QTestState instance to operate on.
5797a6a740dSJohn Snow  * @addr: Guest address to write to.
5807a6a740dSJohn Snow  * @data: Pointer to the bytes that will be written to guest memory.
5817a6a740dSJohn Snow  * @size: Number of bytes to write.
5827a6a740dSJohn Snow  *
5837a6a740dSJohn Snow  * Write a buffer to guest memory and transmit using a base64 encoding.
5847a6a740dSJohn Snow  */
5857a6a740dSJohn Snow void qtest_bufwrite(QTestState *s, uint64_t addr,
5867a6a740dSJohn Snow                     const void *data, size_t size);
5877a6a740dSJohn Snow 
5887a6a740dSJohn Snow /**
58986298845SJohn Snow  * qtest_memset:
59086298845SJohn Snow  * @s: #QTestState instance to operate on.
59186298845SJohn Snow  * @addr: Guest address to write to.
59286298845SJohn Snow  * @patt: Byte pattern to fill the guest memory region with.
59386298845SJohn Snow  * @size: Number of bytes to write.
59486298845SJohn Snow  *
59586298845SJohn Snow  * Write a pattern to guest memory.
59686298845SJohn Snow  */
59786298845SJohn Snow void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
59886298845SJohn Snow 
59986298845SJohn Snow /**
60049ee3590SAnthony Liguori  * qtest_clock_step_next:
6016acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
60249ee3590SAnthony Liguori  *
603bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
6046acf801dSAndreas Färber  *
605bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
60649ee3590SAnthony Liguori  */
60749ee3590SAnthony Liguori int64_t qtest_clock_step_next(QTestState *s);
60849ee3590SAnthony Liguori 
60949ee3590SAnthony Liguori /**
61049ee3590SAnthony Liguori  * qtest_clock_step:
61149ee3590SAnthony Liguori  * @s: QTestState instance to operate on.
61249ee3590SAnthony Liguori  * @step: Number of nanoseconds to advance the clock by.
61349ee3590SAnthony Liguori  *
614bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
6156acf801dSAndreas Färber  *
616bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
61749ee3590SAnthony Liguori  */
61849ee3590SAnthony Liguori int64_t qtest_clock_step(QTestState *s, int64_t step);
61949ee3590SAnthony Liguori 
62049ee3590SAnthony Liguori /**
62149ee3590SAnthony Liguori  * qtest_clock_set:
62249ee3590SAnthony Liguori  * @s: QTestState instance to operate on.
62349ee3590SAnthony Liguori  * @val: Nanoseconds value to advance the clock to.
62449ee3590SAnthony Liguori  *
625bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
6266acf801dSAndreas Färber  *
627bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
62849ee3590SAnthony Liguori  */
62949ee3590SAnthony Liguori int64_t qtest_clock_set(QTestState *s, int64_t val);
63049ee3590SAnthony Liguori 
63149ee3590SAnthony Liguori /**
63254ce6f22SLaurent Vivier  * qtest_big_endian:
63354ce6f22SLaurent Vivier  * @s: QTestState instance to operate on.
63454ce6f22SLaurent Vivier  *
63554ce6f22SLaurent Vivier  * Returns: True if the architecture under test has a big endian configuration.
63654ce6f22SLaurent Vivier  */
63754ce6f22SLaurent Vivier bool qtest_big_endian(QTestState *s);
63854ce6f22SLaurent Vivier 
63954ce6f22SLaurent Vivier /**
64049ee3590SAnthony Liguori  * qtest_get_arch:
64149ee3590SAnthony Liguori  *
6426acf801dSAndreas Färber  * Returns: The architecture for the QEMU executable under test.
64349ee3590SAnthony Liguori  */
64449ee3590SAnthony Liguori const char *qtest_get_arch(void);
64549ee3590SAnthony Liguori 
64649ee3590SAnthony Liguori /**
647e741aff0SIgor Mammedov  * qtest_has_accel:
648e741aff0SIgor Mammedov  * @accel_name: Accelerator name to check for.
649e741aff0SIgor Mammedov  *
650e741aff0SIgor Mammedov  * Returns: true if the accelerator is built in.
651e741aff0SIgor Mammedov  */
652e741aff0SIgor Mammedov bool qtest_has_accel(const char *accel_name);
653e741aff0SIgor Mammedov 
654e741aff0SIgor Mammedov /**
65549ee3590SAnthony Liguori  * qtest_add_func:
65649ee3590SAnthony Liguori  * @str: Test case path.
65749ee3590SAnthony Liguori  * @fn: Test case function
65849ee3590SAnthony Liguori  *
65949ee3590SAnthony Liguori  * Add a GTester testcase with the given name and function.
66049ee3590SAnthony Liguori  * The path is prefixed with the architecture under test, as
6616acf801dSAndreas Färber  * returned by qtest_get_arch().
66249ee3590SAnthony Liguori  */
663041088c7SMarkus Armbruster void qtest_add_func(const char *str, void (*fn)(void));
66449ee3590SAnthony Liguori 
66549ee3590SAnthony Liguori /**
6667949c0e3SAndreas Färber  * qtest_add_data_func:
6677949c0e3SAndreas Färber  * @str: Test case path.
6687949c0e3SAndreas Färber  * @data: Test case data
6697949c0e3SAndreas Färber  * @fn: Test case function
6707949c0e3SAndreas Färber  *
6717949c0e3SAndreas Färber  * Add a GTester testcase with the given name, data and function.
6727949c0e3SAndreas Färber  * The path is prefixed with the architecture under test, as
6737949c0e3SAndreas Färber  * returned by qtest_get_arch().
6747949c0e3SAndreas Färber  */
675041088c7SMarkus Armbruster void qtest_add_data_func(const char *str, const void *data,
676041088c7SMarkus Armbruster                          void (*fn)(const void *));
6777949c0e3SAndreas Färber 
6787949c0e3SAndreas Färber /**
679822e36caSMarc-André Lureau  * qtest_add_data_func_full:
680822e36caSMarc-André Lureau  * @str: Test case path.
681822e36caSMarc-André Lureau  * @data: Test case data
682822e36caSMarc-André Lureau  * @fn: Test case function
683822e36caSMarc-André Lureau  * @data_free_func: GDestroyNotify for data
684822e36caSMarc-André Lureau  *
685822e36caSMarc-André Lureau  * Add a GTester testcase with the given name, data and function.
686822e36caSMarc-André Lureau  * The path is prefixed with the architecture under test, as
687822e36caSMarc-André Lureau  * returned by qtest_get_arch().
688822e36caSMarc-André Lureau  *
689822e36caSMarc-André Lureau  * @data is passed to @data_free_func() on test completion.
690822e36caSMarc-André Lureau  */
691822e36caSMarc-André Lureau void qtest_add_data_func_full(const char *str, void *data,
692822e36caSMarc-André Lureau                               void (*fn)(const void *),
693822e36caSMarc-André Lureau                               GDestroyNotify data_free_func);
694822e36caSMarc-André Lureau 
695822e36caSMarc-André Lureau /**
69645b0f830SAndreas Färber  * qtest_add:
69745b0f830SAndreas Färber  * @testpath: Test case path
69845b0f830SAndreas Färber  * @Fixture: Fixture type
69945b0f830SAndreas Färber  * @tdata: Test case data
70045b0f830SAndreas Färber  * @fsetup: Test case setup function
70145b0f830SAndreas Färber  * @ftest: Test case function
70245b0f830SAndreas Färber  * @fteardown: Test case teardown function
70345b0f830SAndreas Färber  *
70445b0f830SAndreas Färber  * Add a GTester testcase with the given name, data and functions.
70545b0f830SAndreas Färber  * The path is prefixed with the architecture under test, as
70645b0f830SAndreas Färber  * returned by qtest_get_arch().
70745b0f830SAndreas Färber  */
70845b0f830SAndreas Färber #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
70945b0f830SAndreas Färber     do { \
71045b0f830SAndreas Färber         char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
71145b0f830SAndreas Färber         g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
71245b0f830SAndreas Färber         g_free(path); \
71345b0f830SAndreas Färber     } while (0)
71445b0f830SAndreas Färber 
715e1fa7f55SStefan Hajnoczi /**
716e1fa7f55SStefan Hajnoczi  * qtest_add_abrt_handler:
717e1fa7f55SStefan Hajnoczi  * @fn: Handler function
718e1fa7f55SStefan Hajnoczi  * @data: Argument that is passed to the handler
719e1fa7f55SStefan Hajnoczi  *
720e1fa7f55SStefan Hajnoczi  * Add a handler function that is invoked on SIGABRT. This can be used to
721e1fa7f55SStefan Hajnoczi  * terminate processes and perform other cleanup. The handler can be removed
722e1fa7f55SStefan Hajnoczi  * with qtest_remove_abrt_handler().
723e1fa7f55SStefan Hajnoczi  */
724041088c7SMarkus Armbruster void qtest_add_abrt_handler(GHookFunc fn, const void *data);
725063c23d9SMarc-André Lureau 
72645b0f830SAndreas Färber /**
727e1fa7f55SStefan Hajnoczi  * qtest_remove_abrt_handler:
728e1fa7f55SStefan Hajnoczi  * @data: Argument previously passed to qtest_add_abrt_handler()
729e1fa7f55SStefan Hajnoczi  *
730e1fa7f55SStefan Hajnoczi  * Remove an abrt handler that was previously added with
731e1fa7f55SStefan Hajnoczi  * qtest_add_abrt_handler().
732e1fa7f55SStefan Hajnoczi  */
733e1fa7f55SStefan Hajnoczi void qtest_remove_abrt_handler(void *data);
734e1fa7f55SStefan Hajnoczi 
735e1fa7f55SStefan Hajnoczi /**
73628760edcSDaniel P. Berrangé  * qtest_vqmp_assert_success_ref:
73728760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
73828760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
73928760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
74028760edcSDaniel P. Berrangé  * supported after '%'.
74128760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
74228760edcSDaniel P. Berrangé  *
74328760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
74428760edcSDaniel P. Berrangé  * the response, and returns the response.
74528760edcSDaniel P. Berrangé  */
74628760edcSDaniel P. Berrangé QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
74728760edcSDaniel P. Berrangé                                      const char *fmt, va_list args)
74828760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 0);
74928760edcSDaniel P. Berrangé 
75028760edcSDaniel P. Berrangé /**
75128760edcSDaniel P. Berrangé  * qtest_vqmp_assert_success:
75228760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
75328760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
75428760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
75528760edcSDaniel P. Berrangé  * supported after '%'.
75628760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
75728760edcSDaniel P. Berrangé  *
75828760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
75928760edcSDaniel P. Berrangé  * the response.
76028760edcSDaniel P. Berrangé  */
76128760edcSDaniel P. Berrangé void qtest_vqmp_assert_success(QTestState *qts,
76228760edcSDaniel P. Berrangé                                const char *fmt, va_list args)
76328760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 0);
76428760edcSDaniel P. Berrangé 
76528760edcSDaniel P. Berrangé #ifndef _WIN32
76628760edcSDaniel P. Berrangé /**
76728760edcSDaniel P. Berrangé  * qtest_vqmp_fds_assert_success_ref:
76828760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
76928760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
77028760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
77128760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
77228760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
77328760edcSDaniel P. Berrangé  * supported after '%'.
77428760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
77528760edcSDaniel P. Berrangé  *
77628760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU,
77728760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response,
77828760edcSDaniel P. Berrangé  * and returns the response.
77928760edcSDaniel P. Berrangé  */
78028760edcSDaniel P. Berrangé QDict *qtest_vqmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
78128760edcSDaniel P. Berrangé                                          const char *fmt, va_list args)
78228760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 0);
78328760edcSDaniel P. Berrangé 
78428760edcSDaniel P. Berrangé /**
78528760edcSDaniel P. Berrangé  * qtest_vqmp_fds_assert_success:
78628760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
78728760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
78828760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
78928760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
79028760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
79128760edcSDaniel P. Berrangé  * supported after '%'.
79228760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
79328760edcSDaniel P. Berrangé  *
79428760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU and
79528760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response.
79628760edcSDaniel P. Berrangé  */
79728760edcSDaniel P. Berrangé void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
79828760edcSDaniel P. Berrangé                                    const char *fmt, va_list args)
79928760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 0);
80028760edcSDaniel P. Berrangé #endif /* !_WIN32 */
80128760edcSDaniel P. Berrangé 
80228760edcSDaniel P. Berrangé /**
80328760edcSDaniel P. Berrangé  * qtest_qmp_assert_success_ref:
80428760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
80528760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
80628760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
80728760edcSDaniel P. Berrangé  * supported after '%'.
80828760edcSDaniel P. Berrangé  *
80928760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
81028760edcSDaniel P. Berrangé  * the response, and returns the response.
81128760edcSDaniel P. Berrangé  */
81228760edcSDaniel P. Berrangé QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
81328760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 3);
81428760edcSDaniel P. Berrangé 
81528760edcSDaniel P. Berrangé /**
8166fc9f3d3SThomas Huth  * qtest_qmp_assert_success:
8176fc9f3d3SThomas Huth  * @qts: QTestState instance to operate on
81851c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
819ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
820edbe36adSKevin Wolf  * supported after '%'.
821edbe36adSKevin Wolf  *
822edbe36adSKevin Wolf  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
823edbe36adSKevin Wolf  * the response.
824edbe36adSKevin Wolf  */
8256fc9f3d3SThomas Huth void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
8269edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
827edbe36adSKevin Wolf 
82828760edcSDaniel P. Berrangé #ifndef _WIN32
82928760edcSDaniel P. Berrangé /**
83028760edcSDaniel P. Berrangé  * qtest_qmp_fd_assert_success_ref:
83128760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
83228760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
83328760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
83428760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
83528760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
83628760edcSDaniel P. Berrangé  * supported after '%'.
83728760edcSDaniel P. Berrangé  *
83828760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU,
83928760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response,
84028760edcSDaniel P. Berrangé  * and returns the response.
84128760edcSDaniel P. Berrangé  */
84228760edcSDaniel P. Berrangé QDict *qtest_qmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
84328760edcSDaniel P. Berrangé                                         const char *fmt, ...)
84428760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 5);
84528760edcSDaniel P. Berrangé 
84628760edcSDaniel P. Berrangé /**
84728760edcSDaniel P. Berrangé  * qtest_qmp_fd_assert_success:
84828760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
84928760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
85028760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
85128760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
85228760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
85328760edcSDaniel P. Berrangé  * supported after '%'.
85428760edcSDaniel P. Berrangé  *
85528760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU and
85628760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response.
85728760edcSDaniel P. Berrangé  */
85828760edcSDaniel P. Berrangé void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
85928760edcSDaniel P. Berrangé                                   const char *fmt, ...)
86028760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 5);
86128760edcSDaniel P. Berrangé #endif /* !_WIN32 */
86228760edcSDaniel P. Berrangé 
86302ef6e87SThomas Huth /**
86402ef6e87SThomas Huth  * qtest_cb_for_every_machine:
86502ef6e87SThomas Huth  * @cb: Pointer to the callback function
8661f4a0d81SThomas Huth  * @skip_old_versioned: true if versioned old machine types should be skipped
86702ef6e87SThomas Huth  *
86802ef6e87SThomas Huth  *  Call a callback function for every name of all available machines.
86902ef6e87SThomas Huth  */
8701f4a0d81SThomas Huth void qtest_cb_for_every_machine(void (*cb)(const char *machine),
8711f4a0d81SThomas Huth                                 bool skip_old_versioned);
87202ef6e87SThomas Huth 
873acd80015SThomas Huth /**
874719051caSThomas Huth  * qtest_has_machine:
875719051caSThomas Huth  * @machine: The machine to look for
876719051caSThomas Huth  *
877719051caSThomas Huth  * Returns: true if the machine is available in the target binary.
878719051caSThomas Huth  */
879719051caSThomas Huth bool qtest_has_machine(const char *machine);
880719051caSThomas Huth 
881719051caSThomas Huth /**
882ad9e129bSThomas Huth  * qtest_has_device:
883ad9e129bSThomas Huth  * @device: The device to look for
884ad9e129bSThomas Huth  *
885ad9e129bSThomas Huth  * Returns: true if the device is available in the target binary.
886ad9e129bSThomas Huth  */
887ad9e129bSThomas Huth bool qtest_has_device(const char *device);
888ad9e129bSThomas Huth 
889ad9e129bSThomas Huth /**
890b4510bb4SIgor Mammedov  * qtest_qmp_device_add_qdict:
891b4510bb4SIgor Mammedov  * @qts: QTestState instance to operate on
892b4510bb4SIgor Mammedov  * @drv: Name of the device that should be added
8931e458f11SStefan Weil  * @arguments: QDict with properties for the device to initialize
894b4510bb4SIgor Mammedov  *
895b4510bb4SIgor Mammedov  * Generic hot-plugging test via the device_add QMP command with properties
896b4510bb4SIgor Mammedov  * supplied in form of QDict. Use NULL for empty properties list.
897b4510bb4SIgor Mammedov  */
898b4510bb4SIgor Mammedov void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
899b4510bb4SIgor Mammedov                                 const QDict *arguments);
900b4510bb4SIgor Mammedov 
901b4510bb4SIgor Mammedov /**
902acd80015SThomas Huth  * qtest_qmp_device_add:
903e5758de4SThomas Huth  * @qts: QTestState instance to operate on
904acd80015SThomas Huth  * @driver: Name of the device that should be added
905acd80015SThomas Huth  * @id: Identification string
90651c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
907ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
90882cab70bSMarkus Armbruster  * supported after '%'.
909acd80015SThomas Huth  *
910acd80015SThomas Huth  * Generic hot-plugging test via the device_add QMP command.
911acd80015SThomas Huth  */
912e5758de4SThomas Huth void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
9139edc6313SMarc-André Lureau                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
914acd80015SThomas Huth 
915acd80015SThomas Huth /**
9162c7294d7SMarc-André Lureau  * qtest_qmp_add_client:
9172c7294d7SMarc-André Lureau  * @qts: QTestState instance to operate on
9182c7294d7SMarc-André Lureau  * @protocol: the protocol to add to
9192c7294d7SMarc-André Lureau  * @fd: the client file-descriptor
9202c7294d7SMarc-André Lureau  *
92161683d27SMarc-André Lureau  * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
92261683d27SMarc-André Lureau  * ``add_client`` with the given @fd.
9232c7294d7SMarc-André Lureau  */
9242c7294d7SMarc-André Lureau void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
9252c7294d7SMarc-André Lureau 
9262c7294d7SMarc-André Lureau /**
927ea42a6c4SMichael Labiuk  * qtest_qmp_device_del_send:
928ea42a6c4SMichael Labiuk  * @qts: QTestState instance to operate on
929ea42a6c4SMichael Labiuk  * @id: Identification string
930ea42a6c4SMichael Labiuk  *
931ea42a6c4SMichael Labiuk  * Generic hot-unplugging test via the device_del QMP command.
932ea42a6c4SMichael Labiuk  */
933ea42a6c4SMichael Labiuk void qtest_qmp_device_del_send(QTestState *qts, const char *id);
934ea42a6c4SMichael Labiuk 
935ea42a6c4SMichael Labiuk /**
936acd80015SThomas Huth  * qtest_qmp_device_del:
937e5758de4SThomas Huth  * @qts: QTestState instance to operate on
938acd80015SThomas Huth  * @id: Identification string
939acd80015SThomas Huth  *
940acd80015SThomas Huth  * Generic hot-unplugging test via the device_del QMP command.
941ea42a6c4SMichael Labiuk  * Waiting for command completion event.
942acd80015SThomas Huth  */
943e5758de4SThomas Huth void qtest_qmp_device_del(QTestState *qts, const char *id);
944acd80015SThomas Huth 
945c35665e1SIgor Mammedov /**
94621f80286SRichard Henderson  * qtest_probe_child:
94721f80286SRichard Henderson  * @s: QTestState instance to operate on.
94821f80286SRichard Henderson  *
94921f80286SRichard Henderson  * Returns: true if the child is still alive.
95021f80286SRichard Henderson  */
95121f80286SRichard Henderson bool qtest_probe_child(QTestState *s);
95221f80286SRichard Henderson 
953d43e59e7SYury Kotov /**
954d43e59e7SYury Kotov  * qtest_set_expected_status:
955d43e59e7SYury Kotov  * @s: QTestState instance to operate on.
956d43e59e7SYury Kotov  * @status: an expected exit status.
957d43e59e7SYury Kotov  *
958d43e59e7SYury Kotov  * Set expected exit status of the child.
959d43e59e7SYury Kotov  */
960d43e59e7SYury Kotov void qtest_set_expected_status(QTestState *s, int status);
961d43e59e7SYury Kotov 
962ca5d4641SAlexander Bulekov QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
963ca5d4641SAlexander Bulekov                     void (*send)(void*, const char*));
964ca5d4641SAlexander Bulekov 
965ca5d4641SAlexander Bulekov void qtest_client_inproc_recv(void *opaque, const char *str);
966188052a1SIris Chen 
967188052a1SIris Chen /**
968188052a1SIris Chen  * qtest_qom_set_bool:
969188052a1SIris Chen  * @s: QTestState instance to operate on.
970188052a1SIris Chen  * @path: Path to the property being set.
971188052a1SIris Chen  * @property: Property being set.
972188052a1SIris Chen  * @value: Value to set the property.
973188052a1SIris Chen  *
974188052a1SIris Chen  * Set the property with passed in value.
975188052a1SIris Chen  */
976188052a1SIris Chen void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,
977188052a1SIris Chen                          bool value);
978188052a1SIris Chen 
979188052a1SIris Chen /**
980188052a1SIris Chen  * qtest_qom_get_bool:
981188052a1SIris Chen  * @s: QTestState instance to operate on.
982188052a1SIris Chen  * @path: Path to the property being retrieved.
983188052a1SIris Chen  * @property: Property from where the value is being retrieved.
984188052a1SIris Chen  *
985188052a1SIris Chen  * Returns: Value retrieved from property.
986188052a1SIris Chen  */
987188052a1SIris Chen bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
988*ed097649SMarc-André Lureau 
989*ed097649SMarc-André Lureau /**
990*ed097649SMarc-André Lureau  * qtest_pid:
991*ed097649SMarc-André Lureau  * @s: QTestState instance to operate on.
992*ed097649SMarc-André Lureau  *
993*ed097649SMarc-André Lureau  * Returns: the PID of the QEMU process, or <= 0
994*ed097649SMarc-André Lureau  */
995*ed097649SMarc-André Lureau pid_t qtest_pid(QTestState *s);
996*ed097649SMarc-André Lureau 
99749ee3590SAnthony Liguori #endif
998