]> git.proxmox.com Git - mirror_qemu.git/blame - tests/qtest/libqtest.h
Fix some typos in documentation and comments
[mirror_qemu.git] / tests / qtest / libqtest.h
CommitLineData
49ee3590
AL
1/*
2 * QTest
3 *
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
872536bf 6 * Copyright SUSE LINUX Products GmbH 2013
49ee3590
AL
7 *
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
872536bf 11 * Andreas Färber <afaerber@suse.de>
49ee3590
AL
12 *
13 * This work is licensed under the terms of the GNU GPL, version 2 or later.
14 * See the COPYING file in the top-level directory.
15 *
16 */
17#ifndef LIBQTEST_H
18#define LIBQTEST_H
19
5cb8f0db
PB
20#include "qapi/qmp/qobject.h"
21#include "qapi/qmp/qdict.h"
c6d3bcb4 22#include "libqmp.h"
5cb8f0db 23
49ee3590
AL
24typedef struct QTestState QTestState;
25
78b27bad 26/**
88b988c8 27 * qtest_initf:
51c778ed 28 * @fmt: Format for creating other arguments to pass to QEMU, formatted
78b27bad
EB
29 * like sprintf().
30 *
00825d96 31 * Convenience wrapper around qtest_init().
78b27bad
EB
32 *
33 * Returns: #QTestState instance.
34 */
9edc6313 35QTestState *qtest_initf(const char *fmt, ...) G_GNUC_PRINTF(1, 2);
78b27bad
EB
36
37/**
88b988c8 38 * qtest_vinitf:
78b27bad
EB
39 * @fmt: Format for creating other arguments to pass to QEMU, formatted
40 * like vsprintf().
41 * @ap: Format arguments.
42 *
00825d96 43 * Convenience wrapper around qtest_init().
78b27bad
EB
44 *
45 * Returns: #QTestState instance.
46 */
9edc6313 47QTestState *qtest_vinitf(const char *fmt, va_list ap) G_GNUC_PRINTF(1, 0);
78b27bad 48
49ee3590
AL
49/**
50 * qtest_init:
88b988c8
MA
51 * @extra_args: other arguments to pass to QEMU. CAUTION: these
52 * arguments are subject to word splitting and shell evaluation.
6acf801d
AF
53 *
54 * Returns: #QTestState instance.
49ee3590
AL
55 */
56QTestState *qtest_init(const char *extra_args);
57
f66e7ac8
MA
58/**
59 * qtest_init_without_qmp_handshake:
ddee57e0
EB
60 * @extra_args: other arguments to pass to QEMU. CAUTION: these
61 * arguments are subject to word splitting and shell evaluation.
f66e7ac8
MA
62 *
63 * Returns: #QTestState instance.
64 */
192f26a7 65QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
f66e7ac8 66
6c90a82c
JS
67/**
68 * qtest_init_with_serial:
69 * @extra_args: other arguments to pass to QEMU. CAUTION: these
70 * arguments are subject to word splitting and shell evaluation.
71 * @sock_fd: pointer to store the socket file descriptor for
72 * connection with serial.
73 *
74 * Returns: #QTestState instance.
75 */
76QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
77
69c056fb
BM
78/**
79 * qtest_wait_qemu:
80 * @s: #QTestState instance to operate on.
81 *
82 * Wait for the QEMU process to terminate. It is safe to call this function
83 * multiple times.
84 */
85void qtest_wait_qemu(QTestState *s);
86
7a23c523
SH
87/**
88 * qtest_kill_qemu:
89 * @s: #QTestState instance to operate on.
90 *
91 * Kill the QEMU process and wait for it to terminate. It is safe to call this
92 * function multiple times. Normally qtest_quit() is used instead because it
93 * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
94 * and qtest_quit() will be called later.
95 */
96void qtest_kill_qemu(QTestState *s);
97
49ee3590
AL
98/**
99 * qtest_quit:
6acf801d 100 * @s: #QTestState instance to operate on.
49ee3590
AL
101 *
102 * Shut down the QEMU process associated to @s.
103 */
104void qtest_quit(QTestState *s);
105
490081b2 106#ifndef _WIN32
24d5588c
YK
107/**
108 * qtest_qmp_fds:
109 * @s: #QTestState instance to operate on.
110 * @fds: array of file descriptors
111 * @fds_num: number of elements in @fds
51c778ed 112 * @fmt: QMP message to send to qemu, formatted like
ad57e2b1 113 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
24d5588c
YK
114 * supported after '%'.
115 *
116 * Sends a QMP message to QEMU with fds and returns the response.
117 */
118QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
119 const char *fmt, ...)
9edc6313 120 G_GNUC_PRINTF(4, 5);
490081b2 121#endif /* _WIN32 */
24d5588c 122
0c460dac
SH
123/**
124 * qtest_qmp:
125 * @s: #QTestState instance to operate on.
51c778ed 126 * @fmt: QMP message to send to qemu, formatted like
ad57e2b1 127 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
6ce80fd8 128 * supported after '%'.
0c460dac
SH
129 *
130 * Sends a QMP message to QEMU and returns the response.
131 */
e3dc93be 132QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
9edc6313 133 G_GNUC_PRINTF(2, 3);
0c460dac 134
ba4ed393 135/**
4277f1eb 136 * qtest_qmp_send:
ba4ed393 137 * @s: #QTestState instance to operate on.
51c778ed 138 * @fmt: QMP message to send to qemu, formatted like
ad57e2b1 139 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
6ce80fd8 140 * supported after '%'.
ba4ed393
JS
141 *
142 * Sends a QMP message to QEMU and leaves the response in the stream.
143 */
e3dc93be 144void qtest_qmp_send(QTestState *s, const char *fmt, ...)
9edc6313 145 G_GNUC_PRINTF(2, 3);
ba4ed393 146
aed877c5
MA
147/**
148 * qtest_qmp_send_raw:
149 * @s: #QTestState instance to operate on.
51c778ed 150 * @fmt: text to send, formatted like sprintf()
aed877c5
MA
151 *
152 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
153 * this is useful for negative tests.
154 */
155void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
9edc6313 156 G_GNUC_PRINTF(2, 3);
aed877c5 157
9fb7bb06
SH
158/**
159 * qtest_socket_server:
160 * @socket_path: the UNIX domain socket path
161 *
162 * Create and return a listen socket file descriptor, or abort on failure.
163 */
164int qtest_socket_server(const char *socket_path);
165
490081b2 166#ifndef _WIN32
0c460dac 167/**
24d5588c
YK
168 * qtest_vqmp_fds:
169 * @s: #QTestState instance to operate on.
170 * @fds: array of file descriptors
171 * @fds_num: number of elements in @fds
172 * @fmt: QMP message to send to QEMU, formatted like
ad57e2b1 173 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
24d5588c
YK
174 * supported after '%'.
175 * @ap: QMP message arguments
176 *
177 * Sends a QMP message to QEMU with fds and returns the response.
178 */
179QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
180 const char *fmt, va_list ap)
9edc6313 181 G_GNUC_PRINTF(4, 0);
490081b2 182#endif /* _WIN32 */
24d5588c
YK
183
184/**
185 * qtest_vqmp:
0c460dac 186 * @s: #QTestState instance to operate on.
bb340eb2 187 * @fmt: QMP message to send to QEMU, formatted like
ad57e2b1 188 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
6ce80fd8 189 * supported after '%'.
0c460dac
SH
190 * @ap: QMP message arguments
191 *
192 * Sends a QMP message to QEMU and returns the response.
193 */
248eef02 194QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
9edc6313 195 G_GNUC_PRINTF(2, 0);
0c460dac 196
490081b2 197#ifndef _WIN32
24d5588c
YK
198/**
199 * qtest_qmp_vsend_fds:
200 * @s: #QTestState instance to operate on.
201 * @fds: array of file descriptors
202 * @fds_num: number of elements in @fds
203 * @fmt: QMP message to send to QEMU, formatted like
ad57e2b1 204 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
24d5588c
YK
205 * supported after '%'.
206 * @ap: QMP message arguments
207 *
208 * Sends a QMP message to QEMU and leaves the response in the stream.
209 */
210void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
211 const char *fmt, va_list ap)
9edc6313 212 G_GNUC_PRINTF(4, 0);
490081b2 213#endif /* _WIN32 */
24d5588c 214
ba4ed393 215/**
4277f1eb 216 * qtest_qmp_vsend:
ba4ed393 217 * @s: #QTestState instance to operate on.
bb340eb2 218 * @fmt: QMP message to send to QEMU, formatted like
ad57e2b1 219 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
6ce80fd8 220 * supported after '%'.
ba4ed393
JS
221 * @ap: QMP message arguments
222 *
223 * Sends a QMP message to QEMU and leaves the response in the stream.
224 */
e3dc93be 225void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
9edc6313 226 G_GNUC_PRINTF(2, 0);
ba4ed393 227
66e0c7b1 228/**
1c3e2a38 229 * qtest_qmp_receive_dict:
66e0c7b1
AF
230 * @s: #QTestState instance to operate on.
231 *
232 * Reads a QMP message from QEMU and returns the response.
233 */
1c3e2a38 234QDict *qtest_qmp_receive_dict(QTestState *s);
66e0c7b1 235
c22045bf
ML
236/**
237 * qtest_qmp_receive:
238 * @s: #QTestState instance to operate on.
239 *
240 * Reads a QMP message from QEMU and returns the response.
241 * Buffers all the events received meanwhile, until a
242 * call to qtest_qmp_eventwait
243 */
244QDict *qtest_qmp_receive(QTestState *s);
245
8fe941f7
JS
246/**
247 * qtest_qmp_eventwait:
248 * @s: #QTestState instance to operate on.
51c778ed 249 * @event: event to wait for.
8fe941f7 250 *
e8ec0117 251 * Continuously polls for QMP responses until it receives the desired event.
8fe941f7
JS
252 */
253void qtest_qmp_eventwait(QTestState *s, const char *event);
254
7ffe3124
JS
255/**
256 * qtest_qmp_eventwait_ref:
257 * @s: #QTestState instance to operate on.
51c778ed 258 * @event: event to wait for.
7ffe3124 259 *
e8ec0117 260 * Continuously polls for QMP responses until it receives the desired event.
7ffe3124
JS
261 * Returns a copy of the event for further investigation.
262 */
263QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
264
c22045bf
ML
265/**
266 * qtest_qmp_event_ref:
267 * @s: #QTestState instance to operate on.
268 * @event: event to return.
269 *
270 * Removes non-matching events from the buffer that was set by
271 * qtest_qmp_receive, until an event bearing the given name is found,
272 * and returns it.
273 * If no event matches, clears the buffer and returns NULL.
274 *
275 */
276QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
277
5fb48d96 278/**
6bb87be8 279 * qtest_hmp:
5fb48d96 280 * @s: #QTestState instance to operate on.
51c778ed 281 * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
5fb48d96
MA
282 *
283 * Send HMP command to QEMU via QMP's human-monitor-command.
6bb87be8 284 * QMP events are discarded.
5fb48d96
MA
285 *
286 * Returns: the command's output. The caller should g_free() it.
287 */
9edc6313 288char *qtest_hmp(QTestState *s, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
5fb48d96
MA
289
290/**
291 * qtest_hmpv:
292 * @s: #QTestState instance to operate on.
bb340eb2 293 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
5fb48d96
MA
294 * @ap: HMP command arguments
295 *
296 * Send HMP command to QEMU via QMP's human-monitor-command.
6bb87be8 297 * QMP events are discarded.
5fb48d96
MA
298 *
299 * Returns: the command's output. The caller should g_free() it.
300 */
248eef02 301char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
9edc6313 302 G_GNUC_PRINTF(2, 0);
5fb48d96 303
eb062cfa
MAL
304void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
305
49ee3590
AL
306/**
307 * qtest_get_irq:
6acf801d 308 * @s: #QTestState instance to operate on.
49ee3590
AL
309 * @num: Interrupt to observe.
310 *
6acf801d 311 * Returns: The level of the @num interrupt.
49ee3590
AL
312 */
313bool qtest_get_irq(QTestState *s, int num);
314
315/**
316 * qtest_irq_intercept_in:
6acf801d 317 * @s: #QTestState instance to operate on.
49ee3590
AL
318 * @string: QOM path of a device.
319 *
320 * Associate qtest irqs with the GPIO-in pins of the device
321 * whose path is specified by @string.
322 */
323void qtest_irq_intercept_in(QTestState *s, const char *string);
324
325/**
326 * qtest_irq_intercept_out:
6acf801d 327 * @s: #QTestState instance to operate on.
49ee3590
AL
328 * @string: QOM path of a device.
329 *
330 * Associate qtest irqs with the GPIO-out pins of the device
331 * whose path is specified by @string.
332 */
333void qtest_irq_intercept_out(QTestState *s, const char *string);
334
9813dc6a
SG
335/**
336 * qtest_set_irq_in:
337 * @s: QTestState instance to operate on.
338 * @string: QOM path of a device
339 * @name: IRQ name
340 * @irq: IRQ number
341 * @level: IRQ level
342 *
343 * Force given device/irq GPIO-in pin to the given level.
344 */
345void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
346 int irq, int level);
347
49ee3590
AL
348/**
349 * qtest_outb:
6acf801d 350 * @s: #QTestState instance to operate on.
49ee3590
AL
351 * @addr: I/O port to write to.
352 * @value: Value being written.
353 *
354 * Write an 8-bit value to an I/O port.
355 */
356void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
357
358/**
359 * qtest_outw:
6acf801d 360 * @s: #QTestState instance to operate on.
49ee3590
AL
361 * @addr: I/O port to write to.
362 * @value: Value being written.
363 *
364 * Write a 16-bit value to an I/O port.
365 */
366void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
367
368/**
369 * qtest_outl:
6acf801d 370 * @s: #QTestState instance to operate on.
49ee3590
AL
371 * @addr: I/O port to write to.
372 * @value: Value being written.
373 *
374 * Write a 32-bit value to an I/O port.
375 */
376void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
377
378/**
379 * qtest_inb:
6acf801d 380 * @s: #QTestState instance to operate on.
49ee3590 381 * @addr: I/O port to read from.
49ee3590
AL
382 *
383 * Returns an 8-bit value from an I/O port.
384 */
385uint8_t qtest_inb(QTestState *s, uint16_t addr);
386
387/**
388 * qtest_inw:
6acf801d 389 * @s: #QTestState instance to operate on.
49ee3590 390 * @addr: I/O port to read from.
49ee3590
AL
391 *
392 * Returns a 16-bit value from an I/O port.
393 */
394uint16_t qtest_inw(QTestState *s, uint16_t addr);
395
396/**
397 * qtest_inl:
6acf801d 398 * @s: #QTestState instance to operate on.
49ee3590 399 * @addr: I/O port to read from.
49ee3590
AL
400 *
401 * Returns a 32-bit value from an I/O port.
402 */
403uint32_t qtest_inl(QTestState *s, uint16_t addr);
404
872536bf
AF
405/**
406 * qtest_writeb:
407 * @s: #QTestState instance to operate on.
408 * @addr: Guest address to write to.
409 * @value: Value being written.
410 *
411 * Writes an 8-bit value to memory.
412 */
413void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
414
415/**
416 * qtest_writew:
417 * @s: #QTestState instance to operate on.
418 * @addr: Guest address to write to.
419 * @value: Value being written.
420 *
421 * Writes a 16-bit value to memory.
422 */
423void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
424
425/**
426 * qtest_writel:
427 * @s: #QTestState instance to operate on.
428 * @addr: Guest address to write to.
429 * @value: Value being written.
430 *
431 * Writes a 32-bit value to memory.
432 */
433void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
434
435/**
436 * qtest_writeq:
437 * @s: #QTestState instance to operate on.
438 * @addr: Guest address to write to.
439 * @value: Value being written.
440 *
441 * Writes a 64-bit value to memory.
442 */
443void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
444
445/**
446 * qtest_readb:
447 * @s: #QTestState instance to operate on.
448 * @addr: Guest address to read from.
449 *
450 * Reads an 8-bit value from memory.
451 *
452 * Returns: Value read.
453 */
454uint8_t qtest_readb(QTestState *s, uint64_t addr);
455
456/**
457 * qtest_readw:
458 * @s: #QTestState instance to operate on.
459 * @addr: Guest address to read from.
460 *
461 * Reads a 16-bit value from memory.
462 *
463 * Returns: Value read.
464 */
465uint16_t qtest_readw(QTestState *s, uint64_t addr);
466
467/**
468 * qtest_readl:
469 * @s: #QTestState instance to operate on.
470 * @addr: Guest address to read from.
471 *
472 * Reads a 32-bit value from memory.
473 *
474 * Returns: Value read.
475 */
476uint32_t qtest_readl(QTestState *s, uint64_t addr);
477
478/**
479 * qtest_readq:
480 * @s: #QTestState instance to operate on.
481 * @addr: Guest address to read from.
482 *
483 * Reads a 64-bit value from memory.
484 *
485 * Returns: Value read.
486 */
487uint64_t qtest_readq(QTestState *s, uint64_t addr);
488
49ee3590
AL
489/**
490 * qtest_memread:
6acf801d 491 * @s: #QTestState instance to operate on.
49ee3590
AL
492 * @addr: Guest address to read from.
493 * @data: Pointer to where memory contents will be stored.
494 * @size: Number of bytes to read.
495 *
496 * Read guest memory into a buffer.
497 */
498void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
499
eeddd59f
LV
500/**
501 * qtest_rtas_call:
502 * @s: #QTestState instance to operate on.
503 * @name: name of the command to call.
504 * @nargs: Number of args.
505 * @args: Guest address to read args from.
506 * @nret: Number of return value.
507 * @ret: Guest address to write return values to.
508 *
509 * Call an RTAS function
510 */
511uint64_t qtest_rtas_call(QTestState *s, const char *name,
512 uint32_t nargs, uint64_t args,
513 uint32_t nret, uint64_t ret);
514
7a6a740d
JS
515/**
516 * qtest_bufread:
517 * @s: #QTestState instance to operate on.
518 * @addr: Guest address to read from.
519 * @data: Pointer to where memory contents will be stored.
520 * @size: Number of bytes to read.
521 *
522 * Read guest memory into a buffer and receive using a base64 encoding.
523 */
524void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
525
49ee3590
AL
526/**
527 * qtest_memwrite:
6acf801d 528 * @s: #QTestState instance to operate on.
49ee3590
AL
529 * @addr: Guest address to write to.
530 * @data: Pointer to the bytes that will be written to guest memory.
531 * @size: Number of bytes to write.
532 *
533 * Write a buffer to guest memory.
534 */
535void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
536
7a6a740d
JS
537/**
538 * qtest_bufwrite:
539 * @s: #QTestState instance to operate on.
540 * @addr: Guest address to write to.
541 * @data: Pointer to the bytes that will be written to guest memory.
542 * @size: Number of bytes to write.
543 *
544 * Write a buffer to guest memory and transmit using a base64 encoding.
545 */
546void qtest_bufwrite(QTestState *s, uint64_t addr,
547 const void *data, size_t size);
548
86298845
JS
549/**
550 * qtest_memset:
551 * @s: #QTestState instance to operate on.
552 * @addr: Guest address to write to.
553 * @patt: Byte pattern to fill the guest memory region with.
554 * @size: Number of bytes to write.
555 *
556 * Write a pattern to guest memory.
557 */
558void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
559
49ee3590
AL
560/**
561 * qtest_clock_step_next:
6acf801d
AF
562 * @s: #QTestState instance to operate on.
563 *
bc72ad67 564 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
49ee3590 565 *
bc72ad67 566 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
567 */
568int64_t qtest_clock_step_next(QTestState *s);
569
570/**
571 * qtest_clock_step:
572 * @s: QTestState instance to operate on.
573 * @step: Number of nanoseconds to advance the clock by.
574 *
bc72ad67 575 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
6acf801d 576 *
bc72ad67 577 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
578 */
579int64_t qtest_clock_step(QTestState *s, int64_t step);
580
581/**
582 * qtest_clock_set:
583 * @s: QTestState instance to operate on.
584 * @val: Nanoseconds value to advance the clock to.
585 *
bc72ad67 586 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
6acf801d 587 *
bc72ad67 588 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
589 */
590int64_t qtest_clock_set(QTestState *s, int64_t val);
591
54ce6f22
LV
592/**
593 * qtest_big_endian:
594 * @s: QTestState instance to operate on.
595 *
596 * Returns: True if the architecture under test has a big endian configuration.
597 */
598bool qtest_big_endian(QTestState *s);
599
49ee3590
AL
600/**
601 * qtest_get_arch:
602 *
6acf801d 603 * Returns: The architecture for the QEMU executable under test.
49ee3590
AL
604 */
605const char *qtest_get_arch(void);
606
e741aff0
IM
607/**
608 * qtest_has_accel:
609 * @accel_name: Accelerator name to check for.
610 *
611 * Returns: true if the accelerator is built in.
612 */
613bool qtest_has_accel(const char *accel_name);
614
49ee3590
AL
615/**
616 * qtest_add_func:
617 * @str: Test case path.
618 * @fn: Test case function
619 *
620 * Add a GTester testcase with the given name and function.
621 * The path is prefixed with the architecture under test, as
6acf801d 622 * returned by qtest_get_arch().
49ee3590 623 */
041088c7 624void qtest_add_func(const char *str, void (*fn)(void));
49ee3590 625
7949c0e3
AF
626/**
627 * qtest_add_data_func:
628 * @str: Test case path.
629 * @data: Test case data
630 * @fn: Test case function
631 *
632 * Add a GTester testcase with the given name, data and function.
633 * The path is prefixed with the architecture under test, as
634 * returned by qtest_get_arch().
635 */
041088c7
MA
636void qtest_add_data_func(const char *str, const void *data,
637 void (*fn)(const void *));
7949c0e3 638
822e36ca
MAL
639/**
640 * qtest_add_data_func_full:
641 * @str: Test case path.
642 * @data: Test case data
643 * @fn: Test case function
644 * @data_free_func: GDestroyNotify for data
645 *
646 * Add a GTester testcase with the given name, data and function.
647 * The path is prefixed with the architecture under test, as
648 * returned by qtest_get_arch().
649 *
650 * @data is passed to @data_free_func() on test completion.
651 */
652void qtest_add_data_func_full(const char *str, void *data,
653 void (*fn)(const void *),
654 GDestroyNotify data_free_func);
655
45b0f830
AF
656/**
657 * qtest_add:
658 * @testpath: Test case path
659 * @Fixture: Fixture type
660 * @tdata: Test case data
661 * @fsetup: Test case setup function
662 * @ftest: Test case function
663 * @fteardown: Test case teardown function
664 *
665 * Add a GTester testcase with the given name, data and functions.
666 * The path is prefixed with the architecture under test, as
667 * returned by qtest_get_arch().
668 */
669#define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
670 do { \
671 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
672 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
673 g_free(path); \
674 } while (0)
675
e1fa7f55
SH
676/**
677 * qtest_add_abrt_handler:
678 * @fn: Handler function
679 * @data: Argument that is passed to the handler
680 *
681 * Add a handler function that is invoked on SIGABRT. This can be used to
682 * terminate processes and perform other cleanup. The handler can be removed
683 * with qtest_remove_abrt_handler().
684 */
041088c7 685void qtest_add_abrt_handler(GHookFunc fn, const void *data);
063c23d9 686
e1fa7f55
SH
687/**
688 * qtest_remove_abrt_handler:
689 * @data: Argument previously passed to qtest_add_abrt_handler()
690 *
691 * Remove an abrt handler that was previously added with
692 * qtest_add_abrt_handler().
693 */
694void qtest_remove_abrt_handler(void *data);
695
8fe941f7 696/**
6fc9f3d3
TH
697 * qtest_qmp_assert_success:
698 * @qts: QTestState instance to operate on
51c778ed 699 * @fmt: QMP message to send to qemu, formatted like
ad57e2b1 700 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
edbe36ad
KW
701 * supported after '%'.
702 *
703 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
704 * the response.
705 */
6fc9f3d3 706void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
9edc6313 707 G_GNUC_PRINTF(2, 3);
edbe36ad 708
02ef6e87
TH
709/**
710 * qtest_cb_for_every_machine:
711 * @cb: Pointer to the callback function
1f4a0d81 712 * @skip_old_versioned: true if versioned old machine types should be skipped
02ef6e87
TH
713 *
714 * Call a callback function for every name of all available machines.
715 */
1f4a0d81
TH
716void qtest_cb_for_every_machine(void (*cb)(const char *machine),
717 bool skip_old_versioned);
02ef6e87 718
719051ca
TH
719/**
720 * qtest_has_machine:
721 * @machine: The machine to look for
722 *
723 * Returns: true if the machine is available in the target binary.
724 */
725bool qtest_has_machine(const char *machine);
726
ad9e129b
TH
727/**
728 * qtest_has_device:
729 * @device: The device to look for
730 *
731 * Returns: true if the device is available in the target binary.
732 */
733bool qtest_has_device(const char *device);
734
b4510bb4
IM
735/**
736 * qtest_qmp_device_add_qdict:
737 * @qts: QTestState instance to operate on
738 * @drv: Name of the device that should be added
1e458f11 739 * @arguments: QDict with properties for the device to initialize
b4510bb4
IM
740 *
741 * Generic hot-plugging test via the device_add QMP command with properties
742 * supplied in form of QDict. Use NULL for empty properties list.
743 */
744void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
745 const QDict *arguments);
746
acd80015
TH
747/**
748 * qtest_qmp_device_add:
e5758de4 749 * @qts: QTestState instance to operate on
acd80015
TH
750 * @driver: Name of the device that should be added
751 * @id: Identification string
51c778ed 752 * @fmt: QMP message to send to qemu, formatted like
ad57e2b1 753 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
82cab70b 754 * supported after '%'.
acd80015
TH
755 *
756 * Generic hot-plugging test via the device_add QMP command.
757 */
e5758de4 758void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
9edc6313 759 const char *fmt, ...) G_GNUC_PRINTF(4, 5);
acd80015 760
490081b2 761#ifndef _WIN32
2c7294d7
MAL
762/**
763 * qtest_qmp_add_client:
764 * @qts: QTestState instance to operate on
765 * @protocol: the protocol to add to
766 * @fd: the client file-descriptor
767 *
768 * Call QMP ``getfd`` followed by ``add_client`` with the given @fd.
769 */
770void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
490081b2 771#endif /* _WIN32 */
2c7294d7 772
ea42a6c4
ML
773/**
774 * qtest_qmp_device_del_send:
775 * @qts: QTestState instance to operate on
776 * @id: Identification string
777 *
778 * Generic hot-unplugging test via the device_del QMP command.
779 */
780void qtest_qmp_device_del_send(QTestState *qts, const char *id);
781
acd80015
TH
782/**
783 * qtest_qmp_device_del:
e5758de4 784 * @qts: QTestState instance to operate on
acd80015
TH
785 * @id: Identification string
786 *
787 * Generic hot-unplugging test via the device_del QMP command.
ea42a6c4 788 * Waiting for command completion event.
acd80015 789 */
e5758de4 790void qtest_qmp_device_del(QTestState *qts, const char *id);
acd80015 791
21f80286
RH
792/**
793 * qtest_probe_child:
794 * @s: QTestState instance to operate on.
795 *
796 * Returns: true if the child is still alive.
797 */
798bool qtest_probe_child(QTestState *s);
799
d43e59e7
YK
800/**
801 * qtest_set_expected_status:
802 * @s: QTestState instance to operate on.
803 * @status: an expected exit status.
804 *
805 * Set expected exit status of the child.
806 */
807void qtest_set_expected_status(QTestState *s, int status);
808
ca5d4641
AB
809QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
810 void (*send)(void*, const char*));
811
812void qtest_client_inproc_recv(void *opaque, const char *str);
188052a1
IC
813
814/**
815 * qtest_qom_set_bool:
816 * @s: QTestState instance to operate on.
817 * @path: Path to the property being set.
818 * @property: Property being set.
819 * @value: Value to set the property.
820 *
821 * Set the property with passed in value.
822 */
823void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,
824 bool value);
825
826/**
827 * qtest_qom_get_bool:
828 * @s: QTestState instance to operate on.
829 * @path: Path to the property being retrieved.
830 * @property: Property from where the value is being retrieved.
831 *
832 * Returns: Value retrieved from property.
833 */
834bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
49ee3590 835#endif