X-Git-Url: https://repo.jachan.dev/qemu.git/blobdiff_plain/82c6f513735297ad76acaaf2e87f0c5a0b3647a7..a1c2bbc87b227dbf8e00b9684544eff9c861fcf7:/tests/libqtest.h?ds=sidebyside diff --git a/tests/libqtest.h b/tests/libqtest.h index 8f323c7030..f7402e0cc1 100644 --- a/tests/libqtest.h +++ b/tests/libqtest.h @@ -17,11 +17,6 @@ #ifndef LIBQTEST_H #define LIBQTEST_H -#include -#include -#include -#include -#include #include "qapi/qmp/qdict.h" typedef struct QTestState QTestState; @@ -62,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. @@ -82,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. @@ -90,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. @@ -271,6 +317,32 @@ uint64_t qtest_readq(QTestState *s, uint64_t addr); */ void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); +/** + * qtest_rtas_call: + * @s: #QTestState instance to operate on. + * @name: name of the command to call. + * @nargs: Number of args. + * @args: Guest address to read args from. + * @nret: Number of return value. + * @ret: Guest address to write return values to. + * + * Call an RTAS function + */ +uint64_t qtest_rtas_call(QTestState *s, const char *name, + uint32_t nargs, uint64_t args, + uint32_t nret, uint64_t ret); + +/** + * 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. @@ -282,6 +354,29 @@ 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. + * @addr: Guest address to write to. + * @patt: Byte pattern to fill the guest memory region with. + * @size: Number of bytes to write. + * + * Write a pattern to guest memory. + */ +void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size); + /** * qtest_clock_step_next: * @s: #QTestState instance to operate on. @@ -330,7 +425,59 @@ 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: + * @str: Test case path. + * @data: Test case data + * @fn: Test case function + * + * Add a GTester testcase with the given name, data and function. + * 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)(const void *)); + +/** + * qtest_add_data_func_full: + * @str: Test case path. + * @data: Test case data + * @fn: Test case function + * @data_free_func: GDestroyNotify for data + * + * Add a GTester testcase with the given name, data and function. + * The path is prefixed with the architecture under test, as + * returned by qtest_get_arch(). + * + * @data is passed to @data_free_func() on test completion. + */ +void qtest_add_data_func_full(const char *str, void *data, + void (*fn)(const void *), + GDestroyNotify data_free_func); + +/** + * qtest_add: + * @testpath: Test case path + * @Fixture: Fixture type + * @tdata: Test case data + * @fsetup: Test case setup function + * @ftest: Test case function + * @fteardown: Test case teardown function + * + * Add a GTester testcase with the given name, data and functions. + * The path is prefixed with the architecture under test, as + * returned by qtest_get_arch(). + */ +#define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \ + do { \ + char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \ + g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \ + g_free(path); \ + } while (0) + +void qtest_add_abrt_handler(GHookFunc fn, const void *data); /** * qtest_start: @@ -366,6 +513,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 @@ -384,6 +539,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. @@ -607,6 +783,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. @@ -620,6 +809,32 @@ 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. + * @patt: Byte pattern to fill the guest memory region with. + * @size: Number of bytes to write. + * + * Write a pattern to guest memory. + */ +static inline void qmemset(uint64_t addr, uint8_t patt, size_t size) +{ + qtest_memset(global_qtest, addr, patt, size); +} + /** * clock_step_next: * @@ -658,4 +873,18 @@ static inline int64_t clock_set(int64_t val) return qtest_clock_set(global_qtest, val); } +/** + * qtest_big_endian: + * + * Returns: True if the architecture under test has a big endian configuration. + */ +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