X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/9e0ad3472dae5236052d455948396d8579bfc904..5e302a7de64411160ece00a9e894aab923b0c3e6:/tests/libqtest.h diff --git a/tests/libqtest.h b/tests/libqtest.h index 03469b8781..37f37adbf7 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -17,13 +17,7 @@ #ifndef LIBQTEST_H #define LIBQTEST_H -#include -#include -#include -#include -#include #include "qapi/qmp/qdict.h" -#include "glib-compat.h" typedef struct QTestState QTestState; @@ -63,6 +57,15 @@ void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...); */ QDict *qtest_qmp(QTestState *s, const char *fmt, ...); +/** + * qtest_async_qmp: + * @s: #QTestState instance to operate on. + * @fmt...: QMP message to send to qemu + * + * Sends a QMP message to QEMU and leaves the response in the stream. + */ +void qtest_async_qmp(QTestState *s, const char *fmt, ...); + /** * qtest_qmpv_discard_response: * @s: #QTestState instance to operate on. @@ -83,6 +86,16 @@ void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap); */ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); +/** + * qtest_async_qmpv: + * @s: #QTestState instance to operate on. + * @fmt: QMP message to send to QEMU + * @ap: QMP message arguments + * + * Sends a QMP message to QEMU and leaves the response in the stream. + */ +void qtest_async_qmpv(QTestState *s, const char *fmt, va_list ap); + /** * qtest_receive: * @s: #QTestState instance to operate on. @@ -91,6 +104,38 @@ QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap); */ QDict *qtest_qmp_receive(QTestState *s); +/** + * qtest_qmp_eventwait: + * @s: #QTestState instance to operate on. + * @s: #event event to wait for. + * + * Continuosly polls for QMP responses until it receives the desired event. + */ +void qtest_qmp_eventwait(QTestState *s, const char *event); + +/** + * qtest_hmpv: + * @s: #QTestState instance to operate on. + * @fmt...: HMP command to send to QEMU + * + * Send HMP command to QEMU via QMP's human-monitor-command. + * + * Returns: the command's output. The caller should g_free() it. + */ +char *qtest_hmp(QTestState *s, const char *fmt, ...); + +/** + * qtest_hmpv: + * @s: #QTestState instance to operate on. + * @fmt: HMP command to send to QEMU + * @ap: HMP command arguments + * + * Send HMP command to QEMU via QMP's human-monitor-command. + * + * Returns: the command's output. The caller should g_free() it. + */ +char *qtest_hmpv(QTestState *s, const char *fmt, va_list ap); + /** * qtest_get_irq: * @s: #QTestState instance to operate on. @@ -272,6 +317,17 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr); */ void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); +/** + * qtest_bufread: + * @s: #QTestState instance to operate on. + * @addr: Guest address to read from. + * @data: Pointer to where memory contents will be stored. + * @size: Number of bytes to read. + * + * Read guest memory into a buffer and receive using a base64 encoding. + */ +void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size); + /** * qtest_memwrite: * @s: #QTestState instance to operate on. @@ -283,6 +339,18 @@ void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); */ void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size); +/** + * qtest_bufwrite: + * @s: #QTestState instance to operate on. + * @addr: Guest address to write to. + * @data: Pointer to the bytes that will be written to guest memory. + * @size: Number of bytes to write. + * + * Write a buffer to guest memory and transmit using a base64 encoding. + */ +void qtest_bufwrite(QTestState *s, uint64_t addr, + const void *data, size_t size); + /** * qtest_memset: * @s: #QTestState instance to operate on. @@ -342,7 +410,7 @@ const char *qtest_get_arch(void); * The path is prefixed with the architecture under test, as * returned by qtest_get_arch(). */ -void qtest_add_func(const char *str, void (*fn)); +void qtest_add_func(const char *str, void (*fn)(void)); /** * qtest_add_data_func: @@ -354,7 +422,8 @@ void qtest_add_func(const char *str, void (*fn)); * The path is prefixed with the architecture under test, as * returned by qtest_get_arch(). */ -void qtest_add_data_func(const char *str, const void *data, void (*fn)); +void qtest_add_data_func(const char *str, const void *data, + void (*fn)(const void *)); /** * qtest_add: @@ -376,6 +445,8 @@ void qtest_add_data_func(const char *str, const void *data, void (*fn)); g_free(path); \ } while (0) +void qtest_add_abrt_handler(GHookFunc fn, const void *data); + /** * qtest_start: * @args: other arguments to pass to QEMU @@ -410,6 +481,14 @@ static inline void qtest_end(void) */ QDict *qmp(const char *fmt, ...); +/** + * qmp_async: + * @fmt...: QMP message to send to qemu + * + * Sends a QMP message to QEMU and leaves the response in the stream. + */ +void qmp_async(const char *fmt, ...); + /** * qmp_discard_response: * @fmt...: QMP message to send to qemu @@ -428,6 +507,27 @@ static inline QDict *qmp_receive(void) return qtest_qmp_receive(global_qtest); } +/** + * qmp_eventwait: + * @s: #event event to wait for. + * + * Continuosly polls for QMP responses until it receives the desired event. + */ +static inline void qmp_eventwait(const char *event) +{ + return qtest_qmp_eventwait(global_qtest, event); +} + +/** + * hmp: + * @fmt...: HMP command to send to QEMU + * + * Send HMP command to QEMU via QMP's human-monitor-command. + * + * Returns: the command's output. The caller should g_free() it. + */ +char *hmp(const char *fmt, ...); + /** * get_irq: * @num: Interrupt to observe. @@ -651,6 +751,19 @@ static inline void memread(uint64_t addr, void *data, size_t size) qtest_memread(global_qtest, addr, data, size); } +/** + * bufread: + * @addr: Guest address to read from. + * @data: Pointer to where memory contents will be stored. + * @size: Number of bytes to read. + * + * Read guest memory into a buffer, receive using a base64 encoding. + */ +static inline void bufread(uint64_t addr, void *data, size_t size) +{ + qtest_bufread(global_qtest, addr, data, size); +} + /** * memwrite: * @addr: Guest address to write to. @@ -664,6 +777,19 @@ static inline void memwrite(uint64_t addr, const void *data, size_t size) qtest_memwrite(global_qtest, addr, data, size); } +/** + * bufwrite: + * @addr: Guest address to write to. + * @data: Pointer to the bytes that will be written to guest memory. + * @size: Number of bytes to write. + * + * Write a buffer to guest memory, transmit using a base64 encoding. + */ +static inline void bufwrite(uint64_t addr, const void *data, size_t size) +{ + qtest_bufwrite(global_qtest, addr, data, size); +} + /** * qmemset: * @addr: Guest address to write to. @@ -722,4 +848,11 @@ static inline int64_t clock_set(int64_t val) */ bool qtest_big_endian(void); + +QDict *qmp_fd_receive(int fd); +void qmp_fd_sendv(int fd, const char *fmt, va_list ap); +void qmp_fd_send(int fd, const char *fmt, ...); +QDict *qmp_fdv(int fd, const char *fmt, va_list ap); +QDict *qmp_fd(int fd, const char *fmt, ...); + #endif