xref: /qemu/tests/qtest/libqtest.h (revision 1027fc0ae4fcd24c11a43d1f217a1d11579a574b)
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 /**
599931215bSFabiano Rosas  * qtest_init_with_env:
609931215bSFabiano Rosas  * @var: Environment variable from where to take the QEMU binary
619931215bSFabiano Rosas  * @extra_args: Other arguments to pass to QEMU.  CAUTION: these
629931215bSFabiano Rosas  * arguments are subject to word splitting and shell evaluation.
639931215bSFabiano Rosas  *
649931215bSFabiano Rosas  * Like qtest_init(), but use a different environment variable for the
659931215bSFabiano Rosas  * QEMU binary.
669931215bSFabiano Rosas  *
679931215bSFabiano Rosas  * Returns: #QTestState instance.
689931215bSFabiano Rosas  */
699931215bSFabiano Rosas QTestState *qtest_init_with_env(const char *var, const char *extra_args);
709931215bSFabiano Rosas 
719931215bSFabiano Rosas /**
72f66e7ac8SMarkus Armbruster  * qtest_init_without_qmp_handshake:
73ddee57e0SEric Blake  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
74ddee57e0SEric Blake  * arguments are subject to word splitting and shell evaluation.
75f66e7ac8SMarkus Armbruster  *
76f66e7ac8SMarkus Armbruster  * Returns: #QTestState instance.
77f66e7ac8SMarkus Armbruster  */
78192f26a7SPeter Xu QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
79f66e7ac8SMarkus Armbruster 
80f66e7ac8SMarkus Armbruster /**
816c90a82cSJulia Suvorova  * qtest_init_with_serial:
826c90a82cSJulia Suvorova  * @extra_args: other arguments to pass to QEMU.  CAUTION: these
836c90a82cSJulia Suvorova  * arguments are subject to word splitting and shell evaluation.
846c90a82cSJulia Suvorova  * @sock_fd: pointer to store the socket file descriptor for
856c90a82cSJulia Suvorova  * connection with serial.
866c90a82cSJulia Suvorova  *
876c90a82cSJulia Suvorova  * Returns: #QTestState instance.
886c90a82cSJulia Suvorova  */
896c90a82cSJulia Suvorova QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
906c90a82cSJulia Suvorova 
916c90a82cSJulia Suvorova /**
9269c056fbSBin Meng  * qtest_wait_qemu:
9369c056fbSBin Meng  * @s: #QTestState instance to operate on.
9469c056fbSBin Meng  *
9569c056fbSBin Meng  * Wait for the QEMU process to terminate. It is safe to call this function
9669c056fbSBin Meng  * multiple times.
9769c056fbSBin Meng  */
9869c056fbSBin Meng void qtest_wait_qemu(QTestState *s);
9969c056fbSBin Meng 
10069c056fbSBin Meng /**
1017a23c523SStefan Hajnoczi  * qtest_kill_qemu:
1027a23c523SStefan Hajnoczi  * @s: #QTestState instance to operate on.
1037a23c523SStefan Hajnoczi  *
1047a23c523SStefan Hajnoczi  * Kill the QEMU process and wait for it to terminate. It is safe to call this
1057a23c523SStefan Hajnoczi  * function multiple times. Normally qtest_quit() is used instead because it
1067a23c523SStefan Hajnoczi  * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
1077a23c523SStefan Hajnoczi  * and qtest_quit() will be called later.
1087a23c523SStefan Hajnoczi  */
1097a23c523SStefan Hajnoczi void qtest_kill_qemu(QTestState *s);
1107a23c523SStefan Hajnoczi 
1117a23c523SStefan Hajnoczi /**
11249ee3590SAnthony Liguori  * qtest_quit:
1136acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
11449ee3590SAnthony Liguori  *
11549ee3590SAnthony Liguori  * Shut down the QEMU process associated to @s.
11649ee3590SAnthony Liguori  */
11749ee3590SAnthony Liguori void qtest_quit(QTestState *s);
11849ee3590SAnthony Liguori 
119490081b2SBin Meng #ifndef _WIN32
12049ee3590SAnthony Liguori /**
12124d5588cSYury Kotov  * qtest_qmp_fds:
12224d5588cSYury Kotov  * @s: #QTestState instance to operate on.
12324d5588cSYury Kotov  * @fds: array of file descriptors
12424d5588cSYury Kotov  * @fds_num: number of elements in @fds
12551c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
126ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
12724d5588cSYury Kotov  * supported after '%'.
12824d5588cSYury Kotov  *
12924d5588cSYury Kotov  * Sends a QMP message to QEMU with fds and returns the response.
13024d5588cSYury Kotov  */
13124d5588cSYury Kotov QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
13224d5588cSYury Kotov                      const char *fmt, ...)
1339edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 5);
134490081b2SBin Meng #endif /* _WIN32 */
13524d5588cSYury Kotov 
13624d5588cSYury Kotov /**
1370c460dacSStefan Hajnoczi  * qtest_qmp:
1380c460dacSStefan Hajnoczi  * @s: #QTestState instance to operate on.
13951c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
140ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
1416ce80fd8SMarkus Armbruster  * supported after '%'.
1420c460dacSStefan Hajnoczi  *
1430c460dacSStefan Hajnoczi  * Sends a QMP message to QEMU and returns the response.
1440c460dacSStefan Hajnoczi  */
145e3dc93beSMarkus Armbruster QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
1469edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
1470c460dacSStefan Hajnoczi 
1480c460dacSStefan Hajnoczi /**
1494277f1ebSMarkus Armbruster  * qtest_qmp_send:
150ba4ed393SJohn Snow  * @s: #QTestState instance to operate on.
15151c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
152ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
1536ce80fd8SMarkus Armbruster  * supported after '%'.
154ba4ed393SJohn Snow  *
155ba4ed393SJohn Snow  * Sends a QMP message to QEMU and leaves the response in the stream.
156ba4ed393SJohn Snow  */
157e3dc93beSMarkus Armbruster void qtest_qmp_send(QTestState *s, const char *fmt, ...)
1589edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
159ba4ed393SJohn Snow 
160ba4ed393SJohn Snow /**
161aed877c5SMarkus Armbruster  * qtest_qmp_send_raw:
162aed877c5SMarkus Armbruster  * @s: #QTestState instance to operate on.
16351c778edSEduardo Habkost  * @fmt: text to send, formatted like sprintf()
164aed877c5SMarkus Armbruster  *
165aed877c5SMarkus Armbruster  * Sends text to the QMP monitor verbatim.  Need not be valid JSON;
166aed877c5SMarkus Armbruster  * this is useful for negative tests.
167aed877c5SMarkus Armbruster  */
168aed877c5SMarkus Armbruster void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
1699edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
170aed877c5SMarkus Armbruster 
171aed877c5SMarkus Armbruster /**
1729fb7bb06SStefan Hajnoczi  * qtest_socket_server:
1739fb7bb06SStefan Hajnoczi  * @socket_path: the UNIX domain socket path
1749fb7bb06SStefan Hajnoczi  *
1759fb7bb06SStefan Hajnoczi  * Create and return a listen socket file descriptor, or abort on failure.
1769fb7bb06SStefan Hajnoczi  */
1779fb7bb06SStefan Hajnoczi int qtest_socket_server(const char *socket_path);
1789fb7bb06SStefan Hajnoczi 
179490081b2SBin Meng #ifndef _WIN32
1809fb7bb06SStefan Hajnoczi /**
18124d5588cSYury Kotov  * qtest_vqmp_fds:
18224d5588cSYury Kotov  * @s: #QTestState instance to operate on.
18324d5588cSYury Kotov  * @fds: array of file descriptors
18424d5588cSYury Kotov  * @fds_num: number of elements in @fds
18524d5588cSYury Kotov  * @fmt: QMP message to send to QEMU, formatted like
186ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
18724d5588cSYury Kotov  * supported after '%'.
18824d5588cSYury Kotov  * @ap: QMP message arguments
18924d5588cSYury Kotov  *
19024d5588cSYury Kotov  * Sends a QMP message to QEMU with fds and returns the response.
19124d5588cSYury Kotov  */
19224d5588cSYury Kotov QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
19324d5588cSYury Kotov                       const char *fmt, va_list ap)
1949edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 0);
195490081b2SBin Meng #endif /* _WIN32 */
19624d5588cSYury Kotov 
19724d5588cSYury Kotov /**
19824d5588cSYury Kotov  * qtest_vqmp:
1990c460dacSStefan Hajnoczi  * @s: #QTestState instance to operate on.
200bb340eb2SEric Blake  * @fmt: QMP message to send to QEMU, formatted like
201ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
2026ce80fd8SMarkus Armbruster  * supported after '%'.
2030c460dacSStefan Hajnoczi  * @ap: QMP message arguments
2040c460dacSStefan Hajnoczi  *
2050c460dacSStefan Hajnoczi  * Sends a QMP message to QEMU and returns the response.
2060c460dacSStefan Hajnoczi  */
207248eef02SMarkus Armbruster QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
2089edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
2090c460dacSStefan Hajnoczi 
210490081b2SBin Meng #ifndef _WIN32
2110c460dacSStefan Hajnoczi /**
21224d5588cSYury Kotov  * qtest_qmp_vsend_fds:
21324d5588cSYury Kotov  * @s: #QTestState instance to operate on.
21424d5588cSYury Kotov  * @fds: array of file descriptors
21524d5588cSYury Kotov  * @fds_num: number of elements in @fds
21624d5588cSYury Kotov  * @fmt: QMP message to send to QEMU, formatted like
217ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
21824d5588cSYury Kotov  * supported after '%'.
21924d5588cSYury Kotov  * @ap: QMP message arguments
22024d5588cSYury Kotov  *
22124d5588cSYury Kotov  * Sends a QMP message to QEMU and leaves the response in the stream.
22224d5588cSYury Kotov  */
22324d5588cSYury Kotov void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
22424d5588cSYury Kotov                          const char *fmt, va_list ap)
2259edc6313SMarc-André Lureau     G_GNUC_PRINTF(4, 0);
226490081b2SBin Meng #endif /* _WIN32 */
22724d5588cSYury Kotov 
22824d5588cSYury Kotov /**
2294277f1ebSMarkus Armbruster  * qtest_qmp_vsend:
230ba4ed393SJohn Snow  * @s: #QTestState instance to operate on.
231bb340eb2SEric Blake  * @fmt: QMP message to send to QEMU, formatted like
232ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
2336ce80fd8SMarkus Armbruster  * supported after '%'.
234ba4ed393SJohn Snow  * @ap: QMP message arguments
235ba4ed393SJohn Snow  *
236ba4ed393SJohn Snow  * Sends a QMP message to QEMU and leaves the response in the stream.
237ba4ed393SJohn Snow  */
238e3dc93beSMarkus Armbruster void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
2399edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
240ba4ed393SJohn Snow 
241ba4ed393SJohn Snow /**
2421c3e2a38SMaxim Levitsky  * qtest_qmp_receive_dict:
24366e0c7b1SAndreas Färber  * @s: #QTestState instance to operate on.
24466e0c7b1SAndreas Färber  *
24566e0c7b1SAndreas Färber  * Reads a QMP message from QEMU and returns the response.
24666e0c7b1SAndreas Färber  */
2471c3e2a38SMaxim Levitsky QDict *qtest_qmp_receive_dict(QTestState *s);
24866e0c7b1SAndreas Färber 
24966e0c7b1SAndreas Färber /**
250c22045bfSMaxim Levitsky  * qtest_qmp_receive:
251c22045bfSMaxim Levitsky  * @s: #QTestState instance to operate on.
252c22045bfSMaxim Levitsky  *
253c22045bfSMaxim Levitsky  * Reads a QMP message from QEMU and returns the response.
2540150e75dSDaniel P. Berrangé  *
2550150e75dSDaniel P. Berrangé  * If a callback is registered with qtest_qmp_set_event_callback,
2560150e75dSDaniel P. Berrangé  * it will be invoked for every event seen, otherwise events
2570150e75dSDaniel P. Berrangé  * will be buffered until a call to one of the qtest_qmp_eventwait
2580150e75dSDaniel P. Berrangé  * family of functions.
259c22045bfSMaxim Levitsky  */
260c22045bfSMaxim Levitsky QDict *qtest_qmp_receive(QTestState *s);
261c22045bfSMaxim Levitsky 
2620150e75dSDaniel P. Berrangé /*
2630150e75dSDaniel P. Berrangé  * QTestQMPEventCallback:
2640150e75dSDaniel P. Berrangé  * @s: #QTestState instance event was received on
2650150e75dSDaniel P. Berrangé  * @name: name of the event type
2660150e75dSDaniel P. Berrangé  * @event: #QDict for the event details
2670150e75dSDaniel P. Berrangé  * @opaque: opaque data from time of callback registration
2680150e75dSDaniel P. Berrangé  *
2690150e75dSDaniel P. Berrangé  * This callback will be invoked whenever an event is received.
2700150e75dSDaniel P. Berrangé  * If the callback returns true the event will be consumed,
2710150e75dSDaniel P. Berrangé  * otherwise it will be put on the list of pending events.
2720150e75dSDaniel P. Berrangé  * Pending events can be later handled by calling either
2730150e75dSDaniel P. Berrangé  * qtest_qmp_eventwait or qtest_qmp_eventwait_ref.
2740150e75dSDaniel P. Berrangé  *
2750150e75dSDaniel P. Berrangé  * Return: true to consume the event, false to let it be queued
2760150e75dSDaniel P. Berrangé  */
2770150e75dSDaniel P. Berrangé typedef bool (*QTestQMPEventCallback)(QTestState *s, const char *name,
2780150e75dSDaniel P. Berrangé                                       QDict *event, void *opaque);
2790150e75dSDaniel P. Berrangé 
2800150e75dSDaniel P. Berrangé /**
2810150e75dSDaniel P. Berrangé  * qtest_qmp_set_event_callback:
2820150e75dSDaniel P. Berrangé  * @s: #QTestSTate instance to operate on
2830150e75dSDaniel P. Berrangé  * @cb: callback to invoke for events
2840150e75dSDaniel P. Berrangé  * @opaque: data to pass to @cb
2850150e75dSDaniel P. Berrangé  *
2860150e75dSDaniel P. Berrangé  * Register a callback to be invoked whenever an event arrives
2870150e75dSDaniel P. Berrangé  */
2880150e75dSDaniel P. Berrangé void qtest_qmp_set_event_callback(QTestState *s,
2890150e75dSDaniel P. Berrangé                                   QTestQMPEventCallback cb, void *opaque);
2900150e75dSDaniel P. Berrangé 
291c22045bfSMaxim Levitsky /**
2928fe941f7SJohn Snow  * qtest_qmp_eventwait:
2938fe941f7SJohn Snow  * @s: #QTestState instance to operate on.
29451c778edSEduardo Habkost  * @event: event to wait for.
2958fe941f7SJohn Snow  *
296e8ec0117SEric Blake  * Continuously polls for QMP responses until it receives the desired event.
2970150e75dSDaniel P. Berrangé  *
2980150e75dSDaniel P. Berrangé  * Any callback registered with qtest_qmp_set_event_callback will
2990150e75dSDaniel P. Berrangé  * be invoked for every event seen.
3008fe941f7SJohn Snow  */
3018fe941f7SJohn Snow void qtest_qmp_eventwait(QTestState *s, const char *event);
3028fe941f7SJohn Snow 
3038fe941f7SJohn Snow /**
3047ffe3124SJohn Snow  * qtest_qmp_eventwait_ref:
3057ffe3124SJohn Snow  * @s: #QTestState instance to operate on.
30651c778edSEduardo Habkost  * @event: event to wait for.
3077ffe3124SJohn Snow  *
308e8ec0117SEric Blake  * Continuously polls for QMP responses until it receives the desired event.
3090150e75dSDaniel P. Berrangé  *
3100150e75dSDaniel P. Berrangé  * Any callback registered with qtest_qmp_set_event_callback will
3110150e75dSDaniel P. Berrangé  * be invoked for every event seen.
3120150e75dSDaniel P. Berrangé  *
3137ffe3124SJohn Snow  * Returns a copy of the event for further investigation.
3147ffe3124SJohn Snow  */
3157ffe3124SJohn Snow QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
3167ffe3124SJohn Snow 
3177ffe3124SJohn Snow /**
318c22045bfSMaxim Levitsky  * qtest_qmp_event_ref:
319c22045bfSMaxim Levitsky  * @s: #QTestState instance to operate on.
320c22045bfSMaxim Levitsky  * @event: event to return.
321c22045bfSMaxim Levitsky  *
322c22045bfSMaxim Levitsky  * Removes non-matching events from the buffer that was set by
323c22045bfSMaxim Levitsky  * qtest_qmp_receive, until an event bearing the given name is found,
324c22045bfSMaxim Levitsky  * and returns it.
325c22045bfSMaxim Levitsky  * If no event matches, clears the buffer and returns NULL.
326c22045bfSMaxim Levitsky  *
327c22045bfSMaxim Levitsky  */
328c22045bfSMaxim Levitsky QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
329c22045bfSMaxim Levitsky 
330c22045bfSMaxim Levitsky /**
3316bb87be8SThomas Huth  * qtest_hmp:
3325fb48d96SMarkus Armbruster  * @s: #QTestState instance to operate on.
33351c778edSEduardo Habkost  * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
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  */
3409edc6313SMarc-André Lureau char *qtest_hmp(QTestState *s, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
3415fb48d96SMarkus Armbruster 
3425fb48d96SMarkus Armbruster /**
3435fb48d96SMarkus Armbruster  * qtest_hmpv:
3445fb48d96SMarkus Armbruster  * @s: #QTestState instance to operate on.
345bb340eb2SEric Blake  * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
3465fb48d96SMarkus Armbruster  * @ap: HMP command arguments
3475fb48d96SMarkus Armbruster  *
3485fb48d96SMarkus Armbruster  * Send HMP command to QEMU via QMP's human-monitor-command.
3496bb87be8SThomas Huth  * QMP events are discarded.
3505fb48d96SMarkus Armbruster  *
3515fb48d96SMarkus Armbruster  * Returns: the command's output.  The caller should g_free() it.
3525fb48d96SMarkus Armbruster  */
353248eef02SMarkus Armbruster char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
3549edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 0);
3555fb48d96SMarkus Armbruster 
356eb062cfaSMarc-André Lureau void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
357eb062cfaSMarc-André Lureau 
3585fb48d96SMarkus Armbruster /**
35949ee3590SAnthony Liguori  * qtest_get_irq:
3606acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
36149ee3590SAnthony Liguori  * @num: Interrupt to observe.
36249ee3590SAnthony Liguori  *
3636acf801dSAndreas Färber  * Returns: The level of the @num interrupt.
36449ee3590SAnthony Liguori  */
36549ee3590SAnthony Liguori bool qtest_get_irq(QTestState *s, int num);
36649ee3590SAnthony Liguori 
36749ee3590SAnthony Liguori /**
36849ee3590SAnthony Liguori  * qtest_irq_intercept_in:
3696acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
37049ee3590SAnthony Liguori  * @string: QOM path of a device.
37149ee3590SAnthony Liguori  *
37249ee3590SAnthony Liguori  * Associate qtest irqs with the GPIO-in pins of the device
37349ee3590SAnthony Liguori  * whose path is specified by @string.
37449ee3590SAnthony Liguori  */
37549ee3590SAnthony Liguori void qtest_irq_intercept_in(QTestState *s, const char *string);
37649ee3590SAnthony Liguori 
37749ee3590SAnthony Liguori /**
37849ee3590SAnthony Liguori  * qtest_irq_intercept_out:
3796acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
38049ee3590SAnthony Liguori  * @string: QOM path of a device.
38149ee3590SAnthony Liguori  *
38249ee3590SAnthony Liguori  * Associate qtest irqs with the GPIO-out pins of the device
38349ee3590SAnthony Liguori  * whose path is specified by @string.
38449ee3590SAnthony Liguori  */
38549ee3590SAnthony Liguori void qtest_irq_intercept_out(QTestState *s, const char *string);
38649ee3590SAnthony Liguori 
38749ee3590SAnthony Liguori /**
388a8610f8bSChris Laplante  * qtest_irq_intercept_out_named:
389a8610f8bSChris Laplante  * @s: #QTestState instance to operate on.
390a8610f8bSChris Laplante  * @qom_path: QOM path of a device.
391a8610f8bSChris Laplante  * @name: Name of the GPIO out pin
392a8610f8bSChris Laplante  *
393a8610f8bSChris Laplante  * Associate a qtest irq with the named GPIO-out pin of the device
394a8610f8bSChris Laplante  * whose path is specified by @string and whose name is @name.
395a8610f8bSChris Laplante  */
396a8610f8bSChris Laplante void qtest_irq_intercept_out_named(QTestState *s, const char *qom_path, const char *name);
397a8610f8bSChris Laplante 
398a8610f8bSChris Laplante /**
3999813dc6aSSteffen Görtz  * qtest_set_irq_in:
4009813dc6aSSteffen Görtz  * @s: QTestState instance to operate on.
4019813dc6aSSteffen Görtz  * @string: QOM path of a device
4029813dc6aSSteffen Görtz  * @name: IRQ name
4039813dc6aSSteffen Görtz  * @irq: IRQ number
4049813dc6aSSteffen Görtz  * @level: IRQ level
4059813dc6aSSteffen Görtz  *
4069813dc6aSSteffen Görtz  * Force given device/irq GPIO-in pin to the given level.
4079813dc6aSSteffen Görtz  */
4089813dc6aSSteffen Görtz void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
4099813dc6aSSteffen Görtz                       int irq, int level);
4109813dc6aSSteffen Görtz 
4119813dc6aSSteffen Görtz /**
41249ee3590SAnthony Liguori  * qtest_outb:
4136acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
41449ee3590SAnthony Liguori  * @addr: I/O port to write to.
41549ee3590SAnthony Liguori  * @value: Value being written.
41649ee3590SAnthony Liguori  *
41749ee3590SAnthony Liguori  * Write an 8-bit value to an I/O port.
41849ee3590SAnthony Liguori  */
41949ee3590SAnthony Liguori void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
42049ee3590SAnthony Liguori 
42149ee3590SAnthony Liguori /**
42249ee3590SAnthony Liguori  * qtest_outw:
4236acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
42449ee3590SAnthony Liguori  * @addr: I/O port to write to.
42549ee3590SAnthony Liguori  * @value: Value being written.
42649ee3590SAnthony Liguori  *
42749ee3590SAnthony Liguori  * Write a 16-bit value to an I/O port.
42849ee3590SAnthony Liguori  */
42949ee3590SAnthony Liguori void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
43049ee3590SAnthony Liguori 
43149ee3590SAnthony Liguori /**
43249ee3590SAnthony Liguori  * qtest_outl:
4336acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
43449ee3590SAnthony Liguori  * @addr: I/O port to write to.
43549ee3590SAnthony Liguori  * @value: Value being written.
43649ee3590SAnthony Liguori  *
43749ee3590SAnthony Liguori  * Write a 32-bit value to an I/O port.
43849ee3590SAnthony Liguori  */
43949ee3590SAnthony Liguori void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
44049ee3590SAnthony Liguori 
44149ee3590SAnthony Liguori /**
44249ee3590SAnthony Liguori  * qtest_inb:
4436acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
44449ee3590SAnthony Liguori  * @addr: I/O port to read from.
44549ee3590SAnthony Liguori  *
44649ee3590SAnthony Liguori  * Returns an 8-bit value from an I/O port.
44749ee3590SAnthony Liguori  */
44849ee3590SAnthony Liguori uint8_t qtest_inb(QTestState *s, uint16_t addr);
44949ee3590SAnthony Liguori 
45049ee3590SAnthony Liguori /**
45149ee3590SAnthony Liguori  * qtest_inw:
4526acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
45349ee3590SAnthony Liguori  * @addr: I/O port to read from.
45449ee3590SAnthony Liguori  *
45549ee3590SAnthony Liguori  * Returns a 16-bit value from an I/O port.
45649ee3590SAnthony Liguori  */
45749ee3590SAnthony Liguori uint16_t qtest_inw(QTestState *s, uint16_t addr);
45849ee3590SAnthony Liguori 
45949ee3590SAnthony Liguori /**
46049ee3590SAnthony Liguori  * qtest_inl:
4616acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
46249ee3590SAnthony Liguori  * @addr: I/O port to read from.
46349ee3590SAnthony Liguori  *
46449ee3590SAnthony Liguori  * Returns a 32-bit value from an I/O port.
46549ee3590SAnthony Liguori  */
46649ee3590SAnthony Liguori uint32_t qtest_inl(QTestState *s, uint16_t addr);
46749ee3590SAnthony Liguori 
46849ee3590SAnthony Liguori /**
469872536bfSAndreas Färber  * qtest_writeb:
470872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
471872536bfSAndreas Färber  * @addr: Guest address to write to.
472872536bfSAndreas Färber  * @value: Value being written.
473872536bfSAndreas Färber  *
474872536bfSAndreas Färber  * Writes an 8-bit value to memory.
475872536bfSAndreas Färber  */
476872536bfSAndreas Färber void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
477872536bfSAndreas Färber 
478872536bfSAndreas Färber /**
479872536bfSAndreas Färber  * qtest_writew:
480872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
481872536bfSAndreas Färber  * @addr: Guest address to write to.
482872536bfSAndreas Färber  * @value: Value being written.
483872536bfSAndreas Färber  *
484872536bfSAndreas Färber  * Writes a 16-bit value to memory.
485872536bfSAndreas Färber  */
486872536bfSAndreas Färber void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
487872536bfSAndreas Färber 
488872536bfSAndreas Färber /**
489872536bfSAndreas Färber  * qtest_writel:
490872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
491872536bfSAndreas Färber  * @addr: Guest address to write to.
492872536bfSAndreas Färber  * @value: Value being written.
493872536bfSAndreas Färber  *
494872536bfSAndreas Färber  * Writes a 32-bit value to memory.
495872536bfSAndreas Färber  */
496872536bfSAndreas Färber void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
497872536bfSAndreas Färber 
498872536bfSAndreas Färber /**
499872536bfSAndreas Färber  * qtest_writeq:
500872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
501872536bfSAndreas Färber  * @addr: Guest address to write to.
502872536bfSAndreas Färber  * @value: Value being written.
503872536bfSAndreas Färber  *
504872536bfSAndreas Färber  * Writes a 64-bit value to memory.
505872536bfSAndreas Färber  */
506872536bfSAndreas Färber void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
507872536bfSAndreas Färber 
508872536bfSAndreas Färber /**
509872536bfSAndreas Färber  * qtest_readb:
510872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
511872536bfSAndreas Färber  * @addr: Guest address to read from.
512872536bfSAndreas Färber  *
513872536bfSAndreas Färber  * Reads an 8-bit value from memory.
514872536bfSAndreas Färber  *
515872536bfSAndreas Färber  * Returns: Value read.
516872536bfSAndreas Färber  */
517872536bfSAndreas Färber uint8_t qtest_readb(QTestState *s, uint64_t addr);
518872536bfSAndreas Färber 
519872536bfSAndreas Färber /**
520872536bfSAndreas Färber  * qtest_readw:
521872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
522872536bfSAndreas Färber  * @addr: Guest address to read from.
523872536bfSAndreas Färber  *
524872536bfSAndreas Färber  * Reads a 16-bit value from memory.
525872536bfSAndreas Färber  *
526872536bfSAndreas Färber  * Returns: Value read.
527872536bfSAndreas Färber  */
528872536bfSAndreas Färber uint16_t qtest_readw(QTestState *s, uint64_t addr);
529872536bfSAndreas Färber 
530872536bfSAndreas Färber /**
531872536bfSAndreas Färber  * qtest_readl:
532872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
533872536bfSAndreas Färber  * @addr: Guest address to read from.
534872536bfSAndreas Färber  *
535872536bfSAndreas Färber  * Reads a 32-bit value from memory.
536872536bfSAndreas Färber  *
537872536bfSAndreas Färber  * Returns: Value read.
538872536bfSAndreas Färber  */
539872536bfSAndreas Färber uint32_t qtest_readl(QTestState *s, uint64_t addr);
540872536bfSAndreas Färber 
541872536bfSAndreas Färber /**
542872536bfSAndreas Färber  * qtest_readq:
543872536bfSAndreas Färber  * @s: #QTestState instance to operate on.
544872536bfSAndreas Färber  * @addr: Guest address to read from.
545872536bfSAndreas Färber  *
546872536bfSAndreas Färber  * Reads a 64-bit value from memory.
547872536bfSAndreas Färber  *
548872536bfSAndreas Färber  * Returns: Value read.
549872536bfSAndreas Färber  */
550872536bfSAndreas Färber uint64_t qtest_readq(QTestState *s, uint64_t addr);
551872536bfSAndreas Färber 
552872536bfSAndreas Färber /**
55349ee3590SAnthony Liguori  * qtest_memread:
5546acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
55549ee3590SAnthony Liguori  * @addr: Guest address to read from.
55649ee3590SAnthony Liguori  * @data: Pointer to where memory contents will be stored.
55749ee3590SAnthony Liguori  * @size: Number of bytes to read.
55849ee3590SAnthony Liguori  *
55949ee3590SAnthony Liguori  * Read guest memory into a buffer.
56049ee3590SAnthony Liguori  */
56149ee3590SAnthony Liguori void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
56249ee3590SAnthony Liguori 
56349ee3590SAnthony Liguori /**
564eeddd59fSLaurent Vivier  * qtest_rtas_call:
565eeddd59fSLaurent Vivier  * @s: #QTestState instance to operate on.
566eeddd59fSLaurent Vivier  * @name: name of the command to call.
567eeddd59fSLaurent Vivier  * @nargs: Number of args.
568eeddd59fSLaurent Vivier  * @args: Guest address to read args from.
569eeddd59fSLaurent Vivier  * @nret: Number of return value.
570eeddd59fSLaurent Vivier  * @ret: Guest address to write return values to.
571eeddd59fSLaurent Vivier  *
572eeddd59fSLaurent Vivier  * Call an RTAS function
573eeddd59fSLaurent Vivier  */
574eeddd59fSLaurent Vivier uint64_t qtest_rtas_call(QTestState *s, const char *name,
575eeddd59fSLaurent Vivier                          uint32_t nargs, uint64_t args,
576eeddd59fSLaurent Vivier                          uint32_t nret, uint64_t ret);
577eeddd59fSLaurent Vivier 
578eeddd59fSLaurent Vivier /**
5797a6a740dSJohn Snow  * qtest_bufread:
5807a6a740dSJohn Snow  * @s: #QTestState instance to operate on.
5817a6a740dSJohn Snow  * @addr: Guest address to read from.
5827a6a740dSJohn Snow  * @data: Pointer to where memory contents will be stored.
5837a6a740dSJohn Snow  * @size: Number of bytes to read.
5847a6a740dSJohn Snow  *
5857a6a740dSJohn Snow  * Read guest memory into a buffer and receive using a base64 encoding.
5867a6a740dSJohn Snow  */
5877a6a740dSJohn Snow void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
5887a6a740dSJohn Snow 
5897a6a740dSJohn Snow /**
59049ee3590SAnthony Liguori  * qtest_memwrite:
5916acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
59249ee3590SAnthony Liguori  * @addr: Guest address to write to.
59349ee3590SAnthony Liguori  * @data: Pointer to the bytes that will be written to guest memory.
59449ee3590SAnthony Liguori  * @size: Number of bytes to write.
59549ee3590SAnthony Liguori  *
59649ee3590SAnthony Liguori  * Write a buffer to guest memory.
59749ee3590SAnthony Liguori  */
59849ee3590SAnthony Liguori void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
59949ee3590SAnthony Liguori 
60049ee3590SAnthony Liguori /**
6017a6a740dSJohn Snow  * qtest_bufwrite:
6027a6a740dSJohn Snow  * @s: #QTestState instance to operate on.
6037a6a740dSJohn Snow  * @addr: Guest address to write to.
6047a6a740dSJohn Snow  * @data: Pointer to the bytes that will be written to guest memory.
6057a6a740dSJohn Snow  * @size: Number of bytes to write.
6067a6a740dSJohn Snow  *
6077a6a740dSJohn Snow  * Write a buffer to guest memory and transmit using a base64 encoding.
6087a6a740dSJohn Snow  */
6097a6a740dSJohn Snow void qtest_bufwrite(QTestState *s, uint64_t addr,
6107a6a740dSJohn Snow                     const void *data, size_t size);
6117a6a740dSJohn Snow 
6127a6a740dSJohn Snow /**
61386298845SJohn Snow  * qtest_memset:
61486298845SJohn Snow  * @s: #QTestState instance to operate on.
61586298845SJohn Snow  * @addr: Guest address to write to.
61686298845SJohn Snow  * @patt: Byte pattern to fill the guest memory region with.
61786298845SJohn Snow  * @size: Number of bytes to write.
61886298845SJohn Snow  *
61986298845SJohn Snow  * Write a pattern to guest memory.
62086298845SJohn Snow  */
62186298845SJohn Snow void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
62286298845SJohn Snow 
62386298845SJohn Snow /**
62449ee3590SAnthony Liguori  * qtest_clock_step_next:
6256acf801dSAndreas Färber  * @s: #QTestState instance to operate on.
62649ee3590SAnthony Liguori  *
627bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
6286acf801dSAndreas Färber  *
629bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
63049ee3590SAnthony Liguori  */
63149ee3590SAnthony Liguori int64_t qtest_clock_step_next(QTestState *s);
63249ee3590SAnthony Liguori 
63349ee3590SAnthony Liguori /**
63449ee3590SAnthony Liguori  * qtest_clock_step:
63549ee3590SAnthony Liguori  * @s: QTestState instance to operate on.
63649ee3590SAnthony Liguori  * @step: Number of nanoseconds to advance the clock by.
63749ee3590SAnthony Liguori  *
638bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
6396acf801dSAndreas Färber  *
640bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
64149ee3590SAnthony Liguori  */
64249ee3590SAnthony Liguori int64_t qtest_clock_step(QTestState *s, int64_t step);
64349ee3590SAnthony Liguori 
64449ee3590SAnthony Liguori /**
64549ee3590SAnthony Liguori  * qtest_clock_set:
64649ee3590SAnthony Liguori  * @s: QTestState instance to operate on.
64749ee3590SAnthony Liguori  * @val: Nanoseconds value to advance the clock to.
64849ee3590SAnthony Liguori  *
649bc72ad67SAlex Bligh  * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
6506acf801dSAndreas Färber  *
651bc72ad67SAlex Bligh  * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
65249ee3590SAnthony Liguori  */
65349ee3590SAnthony Liguori int64_t qtest_clock_set(QTestState *s, int64_t val);
65449ee3590SAnthony Liguori 
65549ee3590SAnthony Liguori /**
65654ce6f22SLaurent Vivier  * qtest_big_endian:
65754ce6f22SLaurent Vivier  * @s: QTestState instance to operate on.
65854ce6f22SLaurent Vivier  *
65954ce6f22SLaurent Vivier  * Returns: True if the architecture under test has a big endian configuration.
66054ce6f22SLaurent Vivier  */
66154ce6f22SLaurent Vivier bool qtest_big_endian(QTestState *s);
66254ce6f22SLaurent Vivier 
66354ce6f22SLaurent Vivier /**
66449ee3590SAnthony Liguori  * qtest_get_arch:
66549ee3590SAnthony Liguori  *
6666acf801dSAndreas Färber  * Returns: The architecture for the QEMU executable under test.
66749ee3590SAnthony Liguori  */
66849ee3590SAnthony Liguori const char *qtest_get_arch(void);
66949ee3590SAnthony Liguori 
67049ee3590SAnthony Liguori /**
671e741aff0SIgor Mammedov  * qtest_has_accel:
672e741aff0SIgor Mammedov  * @accel_name: Accelerator name to check for.
673e741aff0SIgor Mammedov  *
674e741aff0SIgor Mammedov  * Returns: true if the accelerator is built in.
675e741aff0SIgor Mammedov  */
676e741aff0SIgor Mammedov bool qtest_has_accel(const char *accel_name);
677e741aff0SIgor Mammedov 
678e741aff0SIgor Mammedov /**
67949ee3590SAnthony Liguori  * qtest_add_func:
68049ee3590SAnthony Liguori  * @str: Test case path.
68149ee3590SAnthony Liguori  * @fn: Test case function
68249ee3590SAnthony Liguori  *
68349ee3590SAnthony Liguori  * Add a GTester testcase with the given name and function.
68449ee3590SAnthony Liguori  * The path is prefixed with the architecture under test, as
6856acf801dSAndreas Färber  * returned by qtest_get_arch().
68649ee3590SAnthony Liguori  */
687041088c7SMarkus Armbruster void qtest_add_func(const char *str, void (*fn)(void));
68849ee3590SAnthony Liguori 
68949ee3590SAnthony Liguori /**
6907949c0e3SAndreas Färber  * qtest_add_data_func:
6917949c0e3SAndreas Färber  * @str: Test case path.
6927949c0e3SAndreas Färber  * @data: Test case data
6937949c0e3SAndreas Färber  * @fn: Test case function
6947949c0e3SAndreas Färber  *
6957949c0e3SAndreas Färber  * Add a GTester testcase with the given name, data and function.
6967949c0e3SAndreas Färber  * The path is prefixed with the architecture under test, as
6977949c0e3SAndreas Färber  * returned by qtest_get_arch().
6987949c0e3SAndreas Färber  */
699041088c7SMarkus Armbruster void qtest_add_data_func(const char *str, const void *data,
700041088c7SMarkus Armbruster                          void (*fn)(const void *));
7017949c0e3SAndreas Färber 
7027949c0e3SAndreas Färber /**
703822e36caSMarc-André Lureau  * qtest_add_data_func_full:
704822e36caSMarc-André Lureau  * @str: Test case path.
705822e36caSMarc-André Lureau  * @data: Test case data
706822e36caSMarc-André Lureau  * @fn: Test case function
707822e36caSMarc-André Lureau  * @data_free_func: GDestroyNotify for data
708822e36caSMarc-André Lureau  *
709822e36caSMarc-André Lureau  * Add a GTester testcase with the given name, data and function.
710822e36caSMarc-André Lureau  * The path is prefixed with the architecture under test, as
711822e36caSMarc-André Lureau  * returned by qtest_get_arch().
712822e36caSMarc-André Lureau  *
713822e36caSMarc-André Lureau  * @data is passed to @data_free_func() on test completion.
714822e36caSMarc-André Lureau  */
715822e36caSMarc-André Lureau void qtest_add_data_func_full(const char *str, void *data,
716822e36caSMarc-André Lureau                               void (*fn)(const void *),
717822e36caSMarc-André Lureau                               GDestroyNotify data_free_func);
718822e36caSMarc-André Lureau 
719822e36caSMarc-André Lureau /**
72045b0f830SAndreas Färber  * qtest_add:
72145b0f830SAndreas Färber  * @testpath: Test case path
72245b0f830SAndreas Färber  * @Fixture: Fixture type
72345b0f830SAndreas Färber  * @tdata: Test case data
72445b0f830SAndreas Färber  * @fsetup: Test case setup function
72545b0f830SAndreas Färber  * @ftest: Test case function
72645b0f830SAndreas Färber  * @fteardown: Test case teardown function
72745b0f830SAndreas Färber  *
72845b0f830SAndreas Färber  * Add a GTester testcase with the given name, data and functions.
72945b0f830SAndreas Färber  * The path is prefixed with the architecture under test, as
73045b0f830SAndreas Färber  * returned by qtest_get_arch().
73145b0f830SAndreas Färber  */
73245b0f830SAndreas Färber #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
73345b0f830SAndreas Färber     do { \
73445b0f830SAndreas Färber         char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
73545b0f830SAndreas Färber         g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
73645b0f830SAndreas Färber         g_free(path); \
73745b0f830SAndreas Färber     } while (0)
73845b0f830SAndreas Färber 
739e1fa7f55SStefan Hajnoczi /**
740e1fa7f55SStefan Hajnoczi  * qtest_add_abrt_handler:
741e1fa7f55SStefan Hajnoczi  * @fn: Handler function
742e1fa7f55SStefan Hajnoczi  * @data: Argument that is passed to the handler
743e1fa7f55SStefan Hajnoczi  *
744e1fa7f55SStefan Hajnoczi  * Add a handler function that is invoked on SIGABRT. This can be used to
745e1fa7f55SStefan Hajnoczi  * terminate processes and perform other cleanup. The handler can be removed
746e1fa7f55SStefan Hajnoczi  * with qtest_remove_abrt_handler().
747e1fa7f55SStefan Hajnoczi  */
748041088c7SMarkus Armbruster void qtest_add_abrt_handler(GHookFunc fn, const void *data);
749063c23d9SMarc-André Lureau 
75045b0f830SAndreas Färber /**
751e1fa7f55SStefan Hajnoczi  * qtest_remove_abrt_handler:
752e1fa7f55SStefan Hajnoczi  * @data: Argument previously passed to qtest_add_abrt_handler()
753e1fa7f55SStefan Hajnoczi  *
754e1fa7f55SStefan Hajnoczi  * Remove an abrt handler that was previously added with
755e1fa7f55SStefan Hajnoczi  * qtest_add_abrt_handler().
756e1fa7f55SStefan Hajnoczi  */
757e1fa7f55SStefan Hajnoczi void qtest_remove_abrt_handler(void *data);
758e1fa7f55SStefan Hajnoczi 
759e1fa7f55SStefan Hajnoczi /**
76028760edcSDaniel P. Berrangé  * qtest_vqmp_assert_success_ref:
76128760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
76228760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
76328760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
76428760edcSDaniel P. Berrangé  * supported after '%'.
76528760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
76628760edcSDaniel P. Berrangé  *
76728760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
76828760edcSDaniel P. Berrangé  * the response, and returns the response.
76928760edcSDaniel P. Berrangé  */
77028760edcSDaniel P. Berrangé QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
77128760edcSDaniel P. Berrangé                                      const char *fmt, va_list args)
77228760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 0);
77328760edcSDaniel P. Berrangé 
77428760edcSDaniel P. Berrangé /**
77528760edcSDaniel P. Berrangé  * qtest_vqmp_assert_success:
77628760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
77728760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
77828760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
77928760edcSDaniel P. Berrangé  * supported after '%'.
78028760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
78128760edcSDaniel P. Berrangé  *
78228760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
78328760edcSDaniel P. Berrangé  * the response.
78428760edcSDaniel P. Berrangé  */
78528760edcSDaniel P. Berrangé void qtest_vqmp_assert_success(QTestState *qts,
78628760edcSDaniel P. Berrangé                                const char *fmt, va_list args)
78728760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 0);
78828760edcSDaniel P. Berrangé 
78928760edcSDaniel P. Berrangé #ifndef _WIN32
79028760edcSDaniel P. Berrangé /**
79128760edcSDaniel P. Berrangé  * qtest_vqmp_fds_assert_success_ref:
79228760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
79328760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
79428760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
79528760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
79628760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
79728760edcSDaniel P. Berrangé  * supported after '%'.
79828760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
79928760edcSDaniel P. Berrangé  *
80028760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU,
80128760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response,
80228760edcSDaniel P. Berrangé  * and returns the response.
80328760edcSDaniel P. Berrangé  */
80428760edcSDaniel P. Berrangé QDict *qtest_vqmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
80528760edcSDaniel P. Berrangé                                          const char *fmt, va_list args)
80628760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 0);
80728760edcSDaniel P. Berrangé 
80828760edcSDaniel P. Berrangé /**
80928760edcSDaniel P. Berrangé  * qtest_vqmp_fds_assert_success:
81028760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
81128760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
81228760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
81328760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
81428760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
81528760edcSDaniel P. Berrangé  * supported after '%'.
81628760edcSDaniel P. Berrangé  * @args: variable arguments for @fmt
81728760edcSDaniel P. Berrangé  *
81828760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU and
81928760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response.
82028760edcSDaniel P. Berrangé  */
82128760edcSDaniel P. Berrangé void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
82228760edcSDaniel P. Berrangé                                    const char *fmt, va_list args)
82328760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 0);
82428760edcSDaniel P. Berrangé #endif /* !_WIN32 */
82528760edcSDaniel P. Berrangé 
82628760edcSDaniel P. Berrangé /**
8275274274cSFabiano Rosas  * qtest_qmp_assert_failure_ref:
8285274274cSFabiano Rosas  * @qts: QTestState instance to operate on
8295274274cSFabiano Rosas  * @fmt: QMP message to send to qemu, formatted like
8305274274cSFabiano Rosas  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
8315274274cSFabiano Rosas  * supported after '%'.
8325274274cSFabiano Rosas  *
8335274274cSFabiano Rosas  * Sends a QMP message to QEMU, asserts that an 'error' key is present in
8345274274cSFabiano Rosas  * the response, and returns the response.
8355274274cSFabiano Rosas  */
8365274274cSFabiano Rosas QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
8375274274cSFabiano Rosas     G_GNUC_PRINTF(2, 3);
8385274274cSFabiano Rosas 
8395274274cSFabiano Rosas /**
8405274274cSFabiano Rosas  * qtest_vqmp_assert_failure_ref:
8415274274cSFabiano Rosas  * @qts: QTestState instance to operate on
8425274274cSFabiano Rosas  * @fmt: QMP message to send to qemu, formatted like
8435274274cSFabiano Rosas  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
8445274274cSFabiano Rosas  * supported after '%'.
8455274274cSFabiano Rosas  * @args: variable arguments for @fmt
8465274274cSFabiano Rosas  *
8475274274cSFabiano Rosas  * Sends a QMP message to QEMU, asserts that an 'error' key is present in
8485274274cSFabiano Rosas  * the response, and returns the response.
8495274274cSFabiano Rosas  */
8505274274cSFabiano Rosas QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
8515274274cSFabiano Rosas                                      const char *fmt, va_list args)
8525274274cSFabiano Rosas     G_GNUC_PRINTF(2, 0);
8535274274cSFabiano Rosas 
8545274274cSFabiano Rosas /**
85528760edcSDaniel P. Berrangé  * qtest_qmp_assert_success_ref:
85628760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
85728760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
85828760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
85928760edcSDaniel P. Berrangé  * supported after '%'.
86028760edcSDaniel P. Berrangé  *
86128760edcSDaniel P. Berrangé  * Sends a QMP message to QEMU, asserts that a 'return' key is present in
86228760edcSDaniel P. Berrangé  * the response, and returns the response.
86328760edcSDaniel P. Berrangé  */
86428760edcSDaniel P. Berrangé QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
86528760edcSDaniel P. Berrangé     G_GNUC_PRINTF(2, 3);
86628760edcSDaniel P. Berrangé 
86728760edcSDaniel P. Berrangé /**
8686fc9f3d3SThomas Huth  * qtest_qmp_assert_success:
8696fc9f3d3SThomas Huth  * @qts: QTestState instance to operate on
87051c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
871ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
872edbe36adSKevin Wolf  * supported after '%'.
873edbe36adSKevin Wolf  *
874edbe36adSKevin Wolf  * Sends a QMP message to QEMU and asserts that a 'return' key is present in
875edbe36adSKevin Wolf  * the response.
876edbe36adSKevin Wolf  */
8776fc9f3d3SThomas Huth void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
8789edc6313SMarc-André Lureau     G_GNUC_PRINTF(2, 3);
879edbe36adSKevin Wolf 
88028760edcSDaniel P. Berrangé #ifndef _WIN32
88128760edcSDaniel P. Berrangé /**
88228760edcSDaniel P. Berrangé  * qtest_qmp_fd_assert_success_ref:
88328760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
88428760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
88528760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
88628760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
88728760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
88828760edcSDaniel P. Berrangé  * supported after '%'.
88928760edcSDaniel P. Berrangé  *
89028760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU,
89128760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response,
89228760edcSDaniel P. Berrangé  * and returns the response.
89328760edcSDaniel P. Berrangé  */
89428760edcSDaniel P. Berrangé QDict *qtest_qmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
89528760edcSDaniel P. Berrangé                                         const char *fmt, ...)
89628760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 5);
89728760edcSDaniel P. Berrangé 
89828760edcSDaniel P. Berrangé /**
89928760edcSDaniel P. Berrangé  * qtest_qmp_fd_assert_success:
90028760edcSDaniel P. Berrangé  * @qts: QTestState instance to operate on
90128760edcSDaniel P. Berrangé  * @fds: the file descriptors to send
90228760edcSDaniel P. Berrangé  * @nfds: number of @fds to send
90328760edcSDaniel P. Berrangé  * @fmt: QMP message to send to qemu, formatted like
90428760edcSDaniel P. Berrangé  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
90528760edcSDaniel P. Berrangé  * supported after '%'.
90628760edcSDaniel P. Berrangé  *
90728760edcSDaniel P. Berrangé  * Sends a QMP message with file descriptors to QEMU and
90828760edcSDaniel P. Berrangé  * asserts that a 'return' key is present in the response.
90928760edcSDaniel P. Berrangé  */
91028760edcSDaniel P. Berrangé void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
91128760edcSDaniel P. Berrangé                                   const char *fmt, ...)
91228760edcSDaniel P. Berrangé     G_GNUC_PRINTF(4, 5);
91328760edcSDaniel P. Berrangé #endif /* !_WIN32 */
91428760edcSDaniel P. Berrangé 
91502ef6e87SThomas Huth /**
91602ef6e87SThomas Huth  * qtest_cb_for_every_machine:
91702ef6e87SThomas Huth  * @cb: Pointer to the callback function
9181f4a0d81SThomas Huth  * @skip_old_versioned: true if versioned old machine types should be skipped
91902ef6e87SThomas Huth  *
92002ef6e87SThomas Huth  *  Call a callback function for every name of all available machines.
92102ef6e87SThomas Huth  */
9221f4a0d81SThomas Huth void qtest_cb_for_every_machine(void (*cb)(const char *machine),
9231f4a0d81SThomas Huth                                 bool skip_old_versioned);
92402ef6e87SThomas Huth 
925acd80015SThomas Huth /**
926719051caSThomas Huth  * qtest_has_machine:
927719051caSThomas Huth  * @machine: The machine to look for
928719051caSThomas Huth  *
929719051caSThomas Huth  * Returns: true if the machine is available in the target binary.
930719051caSThomas Huth  */
931719051caSThomas Huth bool qtest_has_machine(const char *machine);
932719051caSThomas Huth 
933719051caSThomas Huth /**
934*1027fc0aSFabiano Rosas  * qtest_has_machine_with_env:
935*1027fc0aSFabiano Rosas  * @var: Environment variable from where to take the QEMU binary
936*1027fc0aSFabiano Rosas  * @machine: The machine to look for
937*1027fc0aSFabiano Rosas  *
938*1027fc0aSFabiano Rosas  * Returns: true if the machine is available in the specified binary.
939*1027fc0aSFabiano Rosas  */
940*1027fc0aSFabiano Rosas bool qtest_has_machine_with_env(const char *var, const char *machine);
941*1027fc0aSFabiano Rosas 
942*1027fc0aSFabiano Rosas /**
943ad9e129bSThomas Huth  * qtest_has_device:
944ad9e129bSThomas Huth  * @device: The device to look for
945ad9e129bSThomas Huth  *
946ad9e129bSThomas Huth  * Returns: true if the device is available in the target binary.
947ad9e129bSThomas Huth  */
948ad9e129bSThomas Huth bool qtest_has_device(const char *device);
949ad9e129bSThomas Huth 
950ad9e129bSThomas Huth /**
951b4510bb4SIgor Mammedov  * qtest_qmp_device_add_qdict:
952b4510bb4SIgor Mammedov  * @qts: QTestState instance to operate on
953b4510bb4SIgor Mammedov  * @drv: Name of the device that should be added
9541e458f11SStefan Weil  * @arguments: QDict with properties for the device to initialize
955b4510bb4SIgor Mammedov  *
956b4510bb4SIgor Mammedov  * Generic hot-plugging test via the device_add QMP command with properties
957b4510bb4SIgor Mammedov  * supplied in form of QDict. Use NULL for empty properties list.
958b4510bb4SIgor Mammedov  */
959b4510bb4SIgor Mammedov void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
960b4510bb4SIgor Mammedov                                 const QDict *arguments);
961b4510bb4SIgor Mammedov 
962b4510bb4SIgor Mammedov /**
963acd80015SThomas Huth  * qtest_qmp_device_add:
964e5758de4SThomas Huth  * @qts: QTestState instance to operate on
965acd80015SThomas Huth  * @driver: Name of the device that should be added
966acd80015SThomas Huth  * @id: Identification string
96751c778edSEduardo Habkost  * @fmt: QMP message to send to qemu, formatted like
968ad57e2b1SPeter Maydell  * qobject_from_jsonf_nofail().  See parse_interpolation() for what's
96982cab70bSMarkus Armbruster  * supported after '%'.
970acd80015SThomas Huth  *
971acd80015SThomas Huth  * Generic hot-plugging test via the device_add QMP command.
972acd80015SThomas Huth  */
973e5758de4SThomas Huth void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
9749edc6313SMarc-André Lureau                           const char *fmt, ...) G_GNUC_PRINTF(4, 5);
975acd80015SThomas Huth 
976acd80015SThomas Huth /**
9772c7294d7SMarc-André Lureau  * qtest_qmp_add_client:
9782c7294d7SMarc-André Lureau  * @qts: QTestState instance to operate on
9792c7294d7SMarc-André Lureau  * @protocol: the protocol to add to
9802c7294d7SMarc-André Lureau  * @fd: the client file-descriptor
9812c7294d7SMarc-André Lureau  *
98261683d27SMarc-André Lureau  * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
98361683d27SMarc-André Lureau  * ``add_client`` with the given @fd.
9842c7294d7SMarc-André Lureau  */
9852c7294d7SMarc-André Lureau void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
9862c7294d7SMarc-André Lureau 
9872c7294d7SMarc-André Lureau /**
988ea42a6c4SMichael Labiuk  * qtest_qmp_device_del_send:
989ea42a6c4SMichael Labiuk  * @qts: QTestState instance to operate on
990ea42a6c4SMichael Labiuk  * @id: Identification string
991ea42a6c4SMichael Labiuk  *
992ea42a6c4SMichael Labiuk  * Generic hot-unplugging test via the device_del QMP command.
993ea42a6c4SMichael Labiuk  */
994ea42a6c4SMichael Labiuk void qtest_qmp_device_del_send(QTestState *qts, const char *id);
995ea42a6c4SMichael Labiuk 
996ea42a6c4SMichael Labiuk /**
997acd80015SThomas Huth  * qtest_qmp_device_del:
998e5758de4SThomas Huth  * @qts: QTestState instance to operate on
999acd80015SThomas Huth  * @id: Identification string
1000acd80015SThomas Huth  *
1001acd80015SThomas Huth  * Generic hot-unplugging test via the device_del QMP command.
1002ea42a6c4SMichael Labiuk  * Waiting for command completion event.
1003acd80015SThomas Huth  */
1004e5758de4SThomas Huth void qtest_qmp_device_del(QTestState *qts, const char *id);
1005acd80015SThomas Huth 
1006c35665e1SIgor Mammedov /**
100721f80286SRichard Henderson  * qtest_probe_child:
100821f80286SRichard Henderson  * @s: QTestState instance to operate on.
100921f80286SRichard Henderson  *
101021f80286SRichard Henderson  * Returns: true if the child is still alive.
101121f80286SRichard Henderson  */
101221f80286SRichard Henderson bool qtest_probe_child(QTestState *s);
101321f80286SRichard Henderson 
1014d43e59e7SYury Kotov /**
1015d43e59e7SYury Kotov  * qtest_set_expected_status:
1016d43e59e7SYury Kotov  * @s: QTestState instance to operate on.
1017d43e59e7SYury Kotov  * @status: an expected exit status.
1018d43e59e7SYury Kotov  *
1019d43e59e7SYury Kotov  * Set expected exit status of the child.
1020d43e59e7SYury Kotov  */
1021d43e59e7SYury Kotov void qtest_set_expected_status(QTestState *s, int status);
1022d43e59e7SYury Kotov 
1023ca5d4641SAlexander Bulekov QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
1024ca5d4641SAlexander Bulekov                     void (*send)(void*, const char*));
1025ca5d4641SAlexander Bulekov 
1026ca5d4641SAlexander Bulekov void qtest_client_inproc_recv(void *opaque, const char *str);
1027188052a1SIris Chen 
1028188052a1SIris Chen /**
1029188052a1SIris Chen  * qtest_qom_set_bool:
1030188052a1SIris Chen  * @s: QTestState instance to operate on.
1031188052a1SIris Chen  * @path: Path to the property being set.
1032188052a1SIris Chen  * @property: Property being set.
1033188052a1SIris Chen  * @value: Value to set the property.
1034188052a1SIris Chen  *
1035188052a1SIris Chen  * Set the property with passed in value.
1036188052a1SIris Chen  */
1037188052a1SIris Chen void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,
1038188052a1SIris Chen                          bool value);
1039188052a1SIris Chen 
1040188052a1SIris Chen /**
1041188052a1SIris Chen  * qtest_qom_get_bool:
1042188052a1SIris Chen  * @s: QTestState instance to operate on.
1043188052a1SIris Chen  * @path: Path to the property being retrieved.
1044188052a1SIris Chen  * @property: Property from where the value is being retrieved.
1045188052a1SIris Chen  *
1046188052a1SIris Chen  * Returns: Value retrieved from property.
1047188052a1SIris Chen  */
1048188052a1SIris Chen bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
1049ed097649SMarc-André Lureau 
1050ed097649SMarc-André Lureau /**
1051ed097649SMarc-André Lureau  * qtest_pid:
1052ed097649SMarc-André Lureau  * @s: QTestState instance to operate on.
1053ed097649SMarc-André Lureau  *
1054ed097649SMarc-André Lureau  * Returns: the PID of the QEMU process, or <= 0
1055ed097649SMarc-André Lureau  */
1056ed097649SMarc-André Lureau pid_t qtest_pid(QTestState *s);
1057ed097649SMarc-André Lureau 
105825919c40SThomas Huth /**
105925919c40SThomas Huth  * have_qemu_img:
106025919c40SThomas Huth  *
106125919c40SThomas Huth  * Returns: true if "qemu-img" is available.
106225919c40SThomas Huth  */
106325919c40SThomas Huth bool have_qemu_img(void);
106425919c40SThomas Huth 
106525919c40SThomas Huth /**
106625919c40SThomas Huth  * mkimg:
106725919c40SThomas Huth  * @file: File name of the image that should be created
106825919c40SThomas Huth  * @fmt: Format, e.g. "qcow2" or "raw"
106925919c40SThomas Huth  * @size_mb: Size of the image in megabytes
107025919c40SThomas Huth  *
107125919c40SThomas Huth  * Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG
107225919c40SThomas Huth  * environment variable must point to the qemu-img file.
107325919c40SThomas Huth  *
107425919c40SThomas Huth  * Returns: true if the image has been created successfully.
107525919c40SThomas Huth  */
107625919c40SThomas Huth bool mkimg(const char *file, const char *fmt, unsigned size_mb);
107725919c40SThomas Huth 
107849ee3590SAnthony Liguori #endif
1079