]> git.proxmox.com Git - mirror_qemu.git/blame - tests/libqtest.h
Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.0-pull-request...
[mirror_qemu.git] / tests / 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"
22
49ee3590
AL
23typedef struct QTestState QTestState;
24
25extern QTestState *global_qtest;
26
78b27bad 27/**
88b988c8 28 * qtest_initf:
78b27bad
EB
29 * @fmt...: Format for creating other arguments to pass to QEMU, formatted
30 * like sprintf().
31 *
88b988c8 32 * Convenience wrapper around qtest_start().
78b27bad
EB
33 *
34 * Returns: #QTestState instance.
35 */
88b988c8 36QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
78b27bad
EB
37
38/**
88b988c8 39 * qtest_vinitf:
78b27bad
EB
40 * @fmt: Format for creating other arguments to pass to QEMU, formatted
41 * like vsprintf().
42 * @ap: Format arguments.
43 *
88b988c8 44 * Convenience wrapper around qtest_start().
78b27bad
EB
45 *
46 * Returns: #QTestState instance.
47 */
88b988c8 48QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
78b27bad 49
49ee3590
AL
50/**
51 * qtest_init:
88b988c8
MA
52 * @extra_args: other arguments to pass to QEMU. CAUTION: these
53 * arguments are subject to word splitting and shell evaluation.
6acf801d
AF
54 *
55 * Returns: #QTestState instance.
49ee3590
AL
56 */
57QTestState *qtest_init(const char *extra_args);
58
f66e7ac8
MA
59/**
60 * qtest_init_without_qmp_handshake:
ddee57e0
EB
61 * @extra_args: other arguments to pass to QEMU. CAUTION: these
62 * arguments are subject to word splitting and shell evaluation.
f66e7ac8
MA
63 *
64 * Returns: #QTestState instance.
65 */
192f26a7 66QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
f66e7ac8 67
6c90a82c
JS
68/**
69 * qtest_init_with_serial:
70 * @extra_args: other arguments to pass to QEMU. CAUTION: these
71 * arguments are subject to word splitting and shell evaluation.
72 * @sock_fd: pointer to store the socket file descriptor for
73 * connection with serial.
74 *
75 * Returns: #QTestState instance.
76 */
77QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
78
49ee3590
AL
79/**
80 * qtest_quit:
6acf801d 81 * @s: #QTestState instance to operate on.
49ee3590
AL
82 *
83 * Shut down the QEMU process associated to @s.
84 */
85void qtest_quit(QTestState *s);
86
0c460dac
SH
87/**
88 * qtest_qmp:
89 * @s: #QTestState instance to operate on.
bb340eb2 90 * @fmt...: QMP message to send to qemu, formatted like
6ce80fd8
MA
91 * qobject_from_jsonf_nofail(). See parse_escape() for what's
92 * supported after '%'.
0c460dac
SH
93 *
94 * Sends a QMP message to QEMU and returns the response.
95 */
e3dc93be
MA
96QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
97 GCC_FMT_ATTR(2, 3);
0c460dac 98
ba4ed393 99/**
4277f1eb 100 * qtest_qmp_send:
ba4ed393 101 * @s: #QTestState instance to operate on.
bb340eb2 102 * @fmt...: QMP message to send to qemu, formatted like
6ce80fd8
MA
103 * qobject_from_jsonf_nofail(). See parse_escape() for what's
104 * supported after '%'.
ba4ed393
JS
105 *
106 * Sends a QMP message to QEMU and leaves the response in the stream.
107 */
e3dc93be
MA
108void qtest_qmp_send(QTestState *s, const char *fmt, ...)
109 GCC_FMT_ATTR(2, 3);
ba4ed393 110
aed877c5
MA
111/**
112 * qtest_qmp_send_raw:
113 * @s: #QTestState instance to operate on.
114 * @fmt...: text to send, formatted like sprintf()
115 *
116 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
117 * this is useful for negative tests.
118 */
119void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
120 GCC_FMT_ATTR(2, 3);
121
0c460dac
SH
122/**
123 * qtest_qmpv:
124 * @s: #QTestState instance to operate on.
bb340eb2 125 * @fmt: QMP message to send to QEMU, formatted like
6ce80fd8
MA
126 * qobject_from_jsonf_nofail(). See parse_escape() for what's
127 * supported after '%'.
0c460dac
SH
128 * @ap: QMP message arguments
129 *
130 * Sends a QMP message to QEMU and returns the response.
131 */
248eef02 132QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
e3dc93be 133 GCC_FMT_ATTR(2, 0);
0c460dac 134
ba4ed393 135/**
4277f1eb 136 * qtest_qmp_vsend:
ba4ed393 137 * @s: #QTestState instance to operate on.
bb340eb2 138 * @fmt: QMP message to send to QEMU, formatted like
6ce80fd8
MA
139 * qobject_from_jsonf_nofail(). See parse_escape() for what's
140 * supported after '%'.
ba4ed393
JS
141 * @ap: QMP message arguments
142 *
143 * Sends a QMP message to QEMU and leaves the response in the stream.
144 */
e3dc93be
MA
145void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
146 GCC_FMT_ATTR(2, 0);
ba4ed393 147
66e0c7b1
AF
148/**
149 * qtest_receive:
150 * @s: #QTestState instance to operate on.
151 *
152 * Reads a QMP message from QEMU and returns the response.
153 */
154QDict *qtest_qmp_receive(QTestState *s);
155
8fe941f7
JS
156/**
157 * qtest_qmp_eventwait:
158 * @s: #QTestState instance to operate on.
159 * @s: #event event to wait for.
160 *
e8ec0117 161 * Continuously polls for QMP responses until it receives the desired event.
8fe941f7
JS
162 */
163void qtest_qmp_eventwait(QTestState *s, const char *event);
164
7ffe3124
JS
165/**
166 * qtest_qmp_eventwait_ref:
167 * @s: #QTestState instance to operate on.
168 * @s: #event event to wait for.
169 *
e8ec0117 170 * Continuously polls for QMP responses until it receives the desired event.
7ffe3124
JS
171 * Returns a copy of the event for further investigation.
172 */
173QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
174
3cd46d42
MA
175/**
176 * qtest_qmp_receive_success:
177 * @s: #QTestState instance to operate on
178 * @event_cb: Event callback
179 * @opaque: Argument for @event_cb
180 *
181 * Poll QMP messages until a command success response is received.
182 * If @event_cb, call it for each event received, passing @opaque,
183 * the event's name and data.
184 * Return the success response's "return" member.
185 */
186QDict *qtest_qmp_receive_success(QTestState *s,
187 void (*event_cb)(void *opaque,
188 const char *name,
189 QDict *data),
190 void *opaque);
191
5fb48d96 192/**
6bb87be8 193 * qtest_hmp:
5fb48d96 194 * @s: #QTestState instance to operate on.
7b899f4d 195 * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
5fb48d96
MA
196 *
197 * Send HMP command to QEMU via QMP's human-monitor-command.
6bb87be8 198 * QMP events are discarded.
5fb48d96
MA
199 *
200 * Returns: the command's output. The caller should g_free() it.
201 */
7b899f4d 202char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
5fb48d96
MA
203
204/**
205 * qtest_hmpv:
206 * @s: #QTestState instance to operate on.
bb340eb2 207 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
5fb48d96
MA
208 * @ap: HMP command arguments
209 *
210 * Send HMP command to QEMU via QMP's human-monitor-command.
6bb87be8 211 * QMP events are discarded.
5fb48d96
MA
212 *
213 * Returns: the command's output. The caller should g_free() it.
214 */
248eef02 215char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
bb340eb2 216 GCC_FMT_ATTR(2, 0);
5fb48d96 217
49ee3590
AL
218/**
219 * qtest_get_irq:
6acf801d 220 * @s: #QTestState instance to operate on.
49ee3590
AL
221 * @num: Interrupt to observe.
222 *
6acf801d 223 * Returns: The level of the @num interrupt.
49ee3590
AL
224 */
225bool qtest_get_irq(QTestState *s, int num);
226
227/**
228 * qtest_irq_intercept_in:
6acf801d 229 * @s: #QTestState instance to operate on.
49ee3590
AL
230 * @string: QOM path of a device.
231 *
232 * Associate qtest irqs with the GPIO-in pins of the device
233 * whose path is specified by @string.
234 */
235void qtest_irq_intercept_in(QTestState *s, const char *string);
236
237/**
238 * qtest_irq_intercept_out:
6acf801d 239 * @s: #QTestState instance to operate on.
49ee3590
AL
240 * @string: QOM path of a device.
241 *
242 * Associate qtest irqs with the GPIO-out pins of the device
243 * whose path is specified by @string.
244 */
245void qtest_irq_intercept_out(QTestState *s, const char *string);
246
9813dc6a
SG
247/**
248 * qtest_set_irq_in:
249 * @s: QTestState instance to operate on.
250 * @string: QOM path of a device
251 * @name: IRQ name
252 * @irq: IRQ number
253 * @level: IRQ level
254 *
255 * Force given device/irq GPIO-in pin to the given level.
256 */
257void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
258 int irq, int level);
259
49ee3590
AL
260/**
261 * qtest_outb:
6acf801d 262 * @s: #QTestState instance to operate on.
49ee3590
AL
263 * @addr: I/O port to write to.
264 * @value: Value being written.
265 *
266 * Write an 8-bit value to an I/O port.
267 */
268void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
269
270/**
271 * qtest_outw:
6acf801d 272 * @s: #QTestState instance to operate on.
49ee3590
AL
273 * @addr: I/O port to write to.
274 * @value: Value being written.
275 *
276 * Write a 16-bit value to an I/O port.
277 */
278void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
279
280/**
281 * qtest_outl:
6acf801d 282 * @s: #QTestState instance to operate on.
49ee3590
AL
283 * @addr: I/O port to write to.
284 * @value: Value being written.
285 *
286 * Write a 32-bit value to an I/O port.
287 */
288void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
289
290/**
291 * qtest_inb:
6acf801d 292 * @s: #QTestState instance to operate on.
49ee3590 293 * @addr: I/O port to read from.
49ee3590
AL
294 *
295 * Returns an 8-bit value from an I/O port.
296 */
297uint8_t qtest_inb(QTestState *s, uint16_t addr);
298
299/**
300 * qtest_inw:
6acf801d 301 * @s: #QTestState instance to operate on.
49ee3590 302 * @addr: I/O port to read from.
49ee3590
AL
303 *
304 * Returns a 16-bit value from an I/O port.
305 */
306uint16_t qtest_inw(QTestState *s, uint16_t addr);
307
308/**
309 * qtest_inl:
6acf801d 310 * @s: #QTestState instance to operate on.
49ee3590 311 * @addr: I/O port to read from.
49ee3590
AL
312 *
313 * Returns a 32-bit value from an I/O port.
314 */
315uint32_t qtest_inl(QTestState *s, uint16_t addr);
316
872536bf
AF
317/**
318 * qtest_writeb:
319 * @s: #QTestState instance to operate on.
320 * @addr: Guest address to write to.
321 * @value: Value being written.
322 *
323 * Writes an 8-bit value to memory.
324 */
325void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
326
327/**
328 * qtest_writew:
329 * @s: #QTestState instance to operate on.
330 * @addr: Guest address to write to.
331 * @value: Value being written.
332 *
333 * Writes a 16-bit value to memory.
334 */
335void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
336
337/**
338 * qtest_writel:
339 * @s: #QTestState instance to operate on.
340 * @addr: Guest address to write to.
341 * @value: Value being written.
342 *
343 * Writes a 32-bit value to memory.
344 */
345void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
346
347/**
348 * qtest_writeq:
349 * @s: #QTestState instance to operate on.
350 * @addr: Guest address to write to.
351 * @value: Value being written.
352 *
353 * Writes a 64-bit value to memory.
354 */
355void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
356
357/**
358 * qtest_readb:
359 * @s: #QTestState instance to operate on.
360 * @addr: Guest address to read from.
361 *
362 * Reads an 8-bit value from memory.
363 *
364 * Returns: Value read.
365 */
366uint8_t qtest_readb(QTestState *s, uint64_t addr);
367
368/**
369 * qtest_readw:
370 * @s: #QTestState instance to operate on.
371 * @addr: Guest address to read from.
372 *
373 * Reads a 16-bit value from memory.
374 *
375 * Returns: Value read.
376 */
377uint16_t qtest_readw(QTestState *s, uint64_t addr);
378
379/**
380 * qtest_readl:
381 * @s: #QTestState instance to operate on.
382 * @addr: Guest address to read from.
383 *
384 * Reads a 32-bit value from memory.
385 *
386 * Returns: Value read.
387 */
388uint32_t qtest_readl(QTestState *s, uint64_t addr);
389
390/**
391 * qtest_readq:
392 * @s: #QTestState instance to operate on.
393 * @addr: Guest address to read from.
394 *
395 * Reads a 64-bit value from memory.
396 *
397 * Returns: Value read.
398 */
399uint64_t qtest_readq(QTestState *s, uint64_t addr);
400
49ee3590
AL
401/**
402 * qtest_memread:
6acf801d 403 * @s: #QTestState instance to operate on.
49ee3590
AL
404 * @addr: Guest address to read from.
405 * @data: Pointer to where memory contents will be stored.
406 * @size: Number of bytes to read.
407 *
408 * Read guest memory into a buffer.
409 */
410void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
411
eeddd59f
LV
412/**
413 * qtest_rtas_call:
414 * @s: #QTestState instance to operate on.
415 * @name: name of the command to call.
416 * @nargs: Number of args.
417 * @args: Guest address to read args from.
418 * @nret: Number of return value.
419 * @ret: Guest address to write return values to.
420 *
421 * Call an RTAS function
422 */
423uint64_t qtest_rtas_call(QTestState *s, const char *name,
424 uint32_t nargs, uint64_t args,
425 uint32_t nret, uint64_t ret);
426
7a6a740d
JS
427/**
428 * qtest_bufread:
429 * @s: #QTestState instance to operate on.
430 * @addr: Guest address to read from.
431 * @data: Pointer to where memory contents will be stored.
432 * @size: Number of bytes to read.
433 *
434 * Read guest memory into a buffer and receive using a base64 encoding.
435 */
436void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
437
49ee3590
AL
438/**
439 * qtest_memwrite:
6acf801d 440 * @s: #QTestState instance to operate on.
49ee3590
AL
441 * @addr: Guest address to write to.
442 * @data: Pointer to the bytes that will be written to guest memory.
443 * @size: Number of bytes to write.
444 *
445 * Write a buffer to guest memory.
446 */
447void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
448
7a6a740d
JS
449/**
450 * qtest_bufwrite:
451 * @s: #QTestState instance to operate on.
452 * @addr: Guest address to write to.
453 * @data: Pointer to the bytes that will be written to guest memory.
454 * @size: Number of bytes to write.
455 *
456 * Write a buffer to guest memory and transmit using a base64 encoding.
457 */
458void qtest_bufwrite(QTestState *s, uint64_t addr,
459 const void *data, size_t size);
460
86298845
JS
461/**
462 * qtest_memset:
463 * @s: #QTestState instance to operate on.
464 * @addr: Guest address to write to.
465 * @patt: Byte pattern to fill the guest memory region with.
466 * @size: Number of bytes to write.
467 *
468 * Write a pattern to guest memory.
469 */
470void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
471
49ee3590
AL
472/**
473 * qtest_clock_step_next:
6acf801d
AF
474 * @s: #QTestState instance to operate on.
475 *
bc72ad67 476 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
49ee3590 477 *
bc72ad67 478 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
479 */
480int64_t qtest_clock_step_next(QTestState *s);
481
482/**
483 * qtest_clock_step:
484 * @s: QTestState instance to operate on.
485 * @step: Number of nanoseconds to advance the clock by.
486 *
bc72ad67 487 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
6acf801d 488 *
bc72ad67 489 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
490 */
491int64_t qtest_clock_step(QTestState *s, int64_t step);
492
493/**
494 * qtest_clock_set:
495 * @s: QTestState instance to operate on.
496 * @val: Nanoseconds value to advance the clock to.
497 *
bc72ad67 498 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
6acf801d 499 *
bc72ad67 500 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590
AL
501 */
502int64_t qtest_clock_set(QTestState *s, int64_t val);
503
54ce6f22
LV
504/**
505 * qtest_big_endian:
506 * @s: QTestState instance to operate on.
507 *
508 * Returns: True if the architecture under test has a big endian configuration.
509 */
510bool qtest_big_endian(QTestState *s);
511
49ee3590
AL
512/**
513 * qtest_get_arch:
514 *
6acf801d 515 * Returns: The architecture for the QEMU executable under test.
49ee3590
AL
516 */
517const char *qtest_get_arch(void);
518
519/**
520 * qtest_add_func:
521 * @str: Test case path.
522 * @fn: Test case function
523 *
524 * Add a GTester testcase with the given name and function.
525 * The path is prefixed with the architecture under test, as
6acf801d 526 * returned by qtest_get_arch().
49ee3590 527 */
041088c7 528void qtest_add_func(const char *str, void (*fn)(void));
49ee3590 529
7949c0e3
AF
530/**
531 * qtest_add_data_func:
532 * @str: Test case path.
533 * @data: Test case data
534 * @fn: Test case function
535 *
536 * Add a GTester testcase with the given name, data and function.
537 * The path is prefixed with the architecture under test, as
538 * returned by qtest_get_arch().
539 */
041088c7
MA
540void qtest_add_data_func(const char *str, const void *data,
541 void (*fn)(const void *));
7949c0e3 542
822e36ca
MAL
543/**
544 * qtest_add_data_func_full:
545 * @str: Test case path.
546 * @data: Test case data
547 * @fn: Test case function
548 * @data_free_func: GDestroyNotify for data
549 *
550 * Add a GTester testcase with the given name, data and function.
551 * The path is prefixed with the architecture under test, as
552 * returned by qtest_get_arch().
553 *
554 * @data is passed to @data_free_func() on test completion.
555 */
556void qtest_add_data_func_full(const char *str, void *data,
557 void (*fn)(const void *),
558 GDestroyNotify data_free_func);
559
45b0f830
AF
560/**
561 * qtest_add:
562 * @testpath: Test case path
563 * @Fixture: Fixture type
564 * @tdata: Test case data
565 * @fsetup: Test case setup function
566 * @ftest: Test case function
567 * @fteardown: Test case teardown function
568 *
569 * Add a GTester testcase with the given name, data and functions.
570 * The path is prefixed with the architecture under test, as
571 * returned by qtest_get_arch().
572 */
573#define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
574 do { \
575 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
576 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
577 g_free(path); \
578 } while (0)
579
041088c7 580void qtest_add_abrt_handler(GHookFunc fn, const void *data);
063c23d9 581
49ee3590
AL
582/**
583 * qtest_start:
584 * @args: other arguments to pass to QEMU
585 *
6acf801d
AF
586 * Start QEMU and assign the resulting #QTestState to a global variable.
587 * The global variable is used by "shortcut" functions documented below.
588 *
589 * Returns: #QTestState instance.
49ee3590 590 */
6acf801d
AF
591static inline QTestState *qtest_start(const char *args)
592{
96b8ca47
SH
593 global_qtest = qtest_init(args);
594 return global_qtest;
6acf801d 595}
49ee3590 596
1d9358e6
MA
597/**
598 * qtest_end:
599 *
600 * Shut down the QEMU process started by qtest_start().
601 */
602static inline void qtest_end(void)
603{
fc281c80
EGE
604 if (!global_qtest) {
605 return;
606 }
1d9358e6 607 qtest_quit(global_qtest);
96b8ca47 608 global_qtest = NULL;
1d9358e6
MA
609}
610
0c460dac
SH
611/**
612 * qmp:
bb340eb2 613 * @fmt...: QMP message to send to qemu, formatted like
6ce80fd8
MA
614 * qobject_from_jsonf_nofail(). See parse_escape() for what's
615 * supported after '%'.
0c460dac
SH
616 *
617 * Sends a QMP message to QEMU and returns the response.
618 */
e3dc93be 619QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
0c460dac 620
ba4ed393 621/**
4277f1eb 622 * qmp_send:
bb340eb2 623 * @fmt...: QMP message to send to qemu, formatted like
6ce80fd8
MA
624 * qobject_from_jsonf_nofail(). See parse_escape() for what's
625 * supported after '%'.
ba4ed393
JS
626 *
627 * Sends a QMP message to QEMU and leaves the response in the stream.
628 */
e3dc93be 629void qmp_send(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
ba4ed393 630
66e0c7b1
AF
631/**
632 * qmp_receive:
633 *
634 * Reads a QMP message from QEMU and returns the response.
635 */
636static inline QDict *qmp_receive(void)
637{
638 return qtest_qmp_receive(global_qtest);
639}
640
8fe941f7
JS
641/**
642 * qmp_eventwait:
643 * @s: #event event to wait for.
644 *
e8ec0117 645 * Continuously polls for QMP responses until it receives the desired event.
8fe941f7
JS
646 */
647static inline void qmp_eventwait(const char *event)
648{
649 return qtest_qmp_eventwait(global_qtest, event);
650}
651
7ffe3124
JS
652/**
653 * qmp_eventwait_ref:
654 * @s: #event event to wait for.
655 *
e8ec0117 656 * Continuously polls for QMP responses until it receives the desired event.
7ffe3124
JS
657 * Returns a copy of the event for further investigation.
658 */
659static inline QDict *qmp_eventwait_ref(const char *event)
660{
661 return qtest_qmp_eventwait_ref(global_qtest, event);
662}
663
5fb48d96
MA
664/**
665 * hmp:
7b899f4d 666 * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
5fb48d96
MA
667 *
668 * Send HMP command to QEMU via QMP's human-monitor-command.
669 *
670 * Returns: the command's output. The caller should g_free() it.
671 */
7b899f4d 672char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
5fb48d96 673
49ee3590
AL
674/**
675 * get_irq:
676 * @num: Interrupt to observe.
677 *
6acf801d 678 * Returns: The level of the @num interrupt.
49ee3590 679 */
6acf801d
AF
680static inline bool get_irq(int num)
681{
682 return qtest_get_irq(global_qtest, num);
683}
49ee3590
AL
684
685/**
686 * irq_intercept_in:
687 * @string: QOM path of a device.
688 *
689 * Associate qtest irqs with the GPIO-in pins of the device
690 * whose path is specified by @string.
691 */
6acf801d
AF
692static inline void irq_intercept_in(const char *string)
693{
694 qtest_irq_intercept_in(global_qtest, string);
695}
49ee3590
AL
696
697/**
698 * qtest_irq_intercept_out:
699 * @string: QOM path of a device.
700 *
701 * Associate qtest irqs with the GPIO-out pins of the device
702 * whose path is specified by @string.
703 */
6acf801d
AF
704static inline void irq_intercept_out(const char *string)
705{
706 qtest_irq_intercept_out(global_qtest, string);
707}
49ee3590
AL
708
709/**
710 * outb:
711 * @addr: I/O port to write to.
712 * @value: Value being written.
713 *
714 * Write an 8-bit value to an I/O port.
715 */
6acf801d
AF
716static inline void outb(uint16_t addr, uint8_t value)
717{
718 qtest_outb(global_qtest, addr, value);
719}
49ee3590
AL
720
721/**
722 * outw:
723 * @addr: I/O port to write to.
724 * @value: Value being written.
725 *
726 * Write a 16-bit value to an I/O port.
727 */
6acf801d
AF
728static inline void outw(uint16_t addr, uint16_t value)
729{
730 qtest_outw(global_qtest, addr, value);
731}
49ee3590
AL
732
733/**
734 * outl:
735 * @addr: I/O port to write to.
736 * @value: Value being written.
737 *
738 * Write a 32-bit value to an I/O port.
739 */
6acf801d
AF
740static inline void outl(uint16_t addr, uint32_t value)
741{
742 qtest_outl(global_qtest, addr, value);
743}
49ee3590
AL
744
745/**
746 * inb:
747 * @addr: I/O port to read from.
49ee3590 748 *
6acf801d
AF
749 * Reads an 8-bit value from an I/O port.
750 *
751 * Returns: Value read.
49ee3590 752 */
6acf801d
AF
753static inline uint8_t inb(uint16_t addr)
754{
755 return qtest_inb(global_qtest, addr);
756}
49ee3590
AL
757
758/**
759 * inw:
760 * @addr: I/O port to read from.
49ee3590 761 *
6acf801d
AF
762 * Reads a 16-bit value from an I/O port.
763 *
764 * Returns: Value read.
49ee3590 765 */
6acf801d
AF
766static inline uint16_t inw(uint16_t addr)
767{
768 return qtest_inw(global_qtest, addr);
769}
49ee3590
AL
770
771/**
772 * inl:
773 * @addr: I/O port to read from.
49ee3590 774 *
6acf801d
AF
775 * Reads a 32-bit value from an I/O port.
776 *
777 * Returns: Value read.
49ee3590 778 */
6acf801d
AF
779static inline uint32_t inl(uint16_t addr)
780{
781 return qtest_inl(global_qtest, addr);
782}
49ee3590 783
872536bf
AF
784/**
785 * writeb:
786 * @addr: Guest address to write to.
787 * @value: Value being written.
788 *
789 * Writes an 8-bit value to guest memory.
790 */
791static inline void writeb(uint64_t addr, uint8_t value)
792{
793 qtest_writeb(global_qtest, addr, value);
794}
795
796/**
797 * writew:
798 * @addr: Guest address to write to.
799 * @value: Value being written.
800 *
801 * Writes a 16-bit value to guest memory.
802 */
803static inline void writew(uint64_t addr, uint16_t value)
804{
805 qtest_writew(global_qtest, addr, value);
806}
807
808/**
809 * writel:
810 * @addr: Guest address to write to.
811 * @value: Value being written.
812 *
813 * Writes a 32-bit value to guest memory.
814 */
815static inline void writel(uint64_t addr, uint32_t value)
816{
817 qtest_writel(global_qtest, addr, value);
818}
819
820/**
821 * writeq:
822 * @addr: Guest address to write to.
823 * @value: Value being written.
824 *
825 * Writes a 64-bit value to guest memory.
826 */
827static inline void writeq(uint64_t addr, uint64_t value)
828{
829 qtest_writeq(global_qtest, addr, value);
830}
831
832/**
833 * readb:
834 * @addr: Guest address to read from.
835 *
836 * Reads an 8-bit value from guest memory.
837 *
838 * Returns: Value read.
839 */
840static inline uint8_t readb(uint64_t addr)
841{
842 return qtest_readb(global_qtest, addr);
843}
844
845/**
846 * readw:
847 * @addr: Guest address to read from.
848 *
849 * Reads a 16-bit value from guest memory.
850 *
851 * Returns: Value read.
852 */
853static inline uint16_t readw(uint64_t addr)
854{
855 return qtest_readw(global_qtest, addr);
856}
857
858/**
859 * readl:
860 * @addr: Guest address to read from.
861 *
862 * Reads a 32-bit value from guest memory.
863 *
864 * Returns: Value read.
865 */
866static inline uint32_t readl(uint64_t addr)
867{
868 return qtest_readl(global_qtest, addr);
869}
870
871/**
872 * readq:
873 * @addr: Guest address to read from.
874 *
875 * Reads a 64-bit value from guest memory.
876 *
877 * Returns: Value read.
878 */
879static inline uint64_t readq(uint64_t addr)
880{
881 return qtest_readq(global_qtest, addr);
882}
883
49ee3590
AL
884/**
885 * memread:
886 * @addr: Guest address to read from.
887 * @data: Pointer to where memory contents will be stored.
888 * @size: Number of bytes to read.
889 *
890 * Read guest memory into a buffer.
891 */
6acf801d
AF
892static inline void memread(uint64_t addr, void *data, size_t size)
893{
894 qtest_memread(global_qtest, addr, data, size);
895}
49ee3590 896
7a6a740d
JS
897/**
898 * bufread:
899 * @addr: Guest address to read from.
900 * @data: Pointer to where memory contents will be stored.
901 * @size: Number of bytes to read.
902 *
903 * Read guest memory into a buffer, receive using a base64 encoding.
904 */
905static inline void bufread(uint64_t addr, void *data, size_t size)
906{
907 qtest_bufread(global_qtest, addr, data, size);
908}
909
49ee3590
AL
910/**
911 * memwrite:
912 * @addr: Guest address to write to.
913 * @data: Pointer to the bytes that will be written to guest memory.
914 * @size: Number of bytes to write.
915 *
916 * Write a buffer to guest memory.
917 */
6acf801d
AF
918static inline void memwrite(uint64_t addr, const void *data, size_t size)
919{
920 qtest_memwrite(global_qtest, addr, data, size);
921}
49ee3590 922
7a6a740d
JS
923/**
924 * bufwrite:
925 * @addr: Guest address to write to.
926 * @data: Pointer to the bytes that will be written to guest memory.
927 * @size: Number of bytes to write.
928 *
929 * Write a buffer to guest memory, transmit using a base64 encoding.
930 */
931static inline void bufwrite(uint64_t addr, const void *data, size_t size)
932{
933 qtest_bufwrite(global_qtest, addr, data, size);
934}
935
86298845
JS
936/**
937 * qmemset:
938 * @addr: Guest address to write to.
939 * @patt: Byte pattern to fill the guest memory region with.
940 * @size: Number of bytes to write.
941 *
942 * Write a pattern to guest memory.
943 */
944static inline void qmemset(uint64_t addr, uint8_t patt, size_t size)
945{
946 qtest_memset(global_qtest, addr, patt, size);
947}
948
49ee3590
AL
949/**
950 * clock_step_next:
951 *
bc72ad67 952 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
6acf801d 953 *
bc72ad67 954 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590 955 */
6acf801d
AF
956static inline int64_t clock_step_next(void)
957{
958 return qtest_clock_step_next(global_qtest);
959}
49ee3590
AL
960
961/**
962 * clock_step:
963 * @step: Number of nanoseconds to advance the clock by.
964 *
bc72ad67 965 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
6acf801d 966 *
bc72ad67 967 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590 968 */
6acf801d
AF
969static inline int64_t clock_step(int64_t step)
970{
971 return qtest_clock_step(global_qtest, step);
972}
49ee3590
AL
973
974/**
975 * clock_set:
976 * @val: Nanoseconds value to advance the clock to.
977 *
bc72ad67 978 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
6acf801d 979 *
bc72ad67 980 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
49ee3590 981 */
6acf801d
AF
982static inline int64_t clock_set(int64_t val)
983{
984 return qtest_clock_set(global_qtest, val);
985}
49ee3590 986
dc47995e 987QDict *qmp_fd_receive(int fd);
e3dc93be
MA
988void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
989void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
e2f64a68
MA
990void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
991void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
e3dc93be
MA
992QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
993QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
dc47995e 994
02ef6e87
TH
995/**
996 * qtest_cb_for_every_machine:
997 * @cb: Pointer to the callback function
1f4a0d81 998 * @skip_old_versioned: true if versioned old machine types should be skipped
02ef6e87
TH
999 *
1000 * Call a callback function for every name of all available machines.
1001 */
1f4a0d81
TH
1002void qtest_cb_for_every_machine(void (*cb)(const char *machine),
1003 bool skip_old_versioned);
02ef6e87 1004
acd80015
TH
1005/**
1006 * qtest_qmp_device_add:
1007 * @driver: Name of the device that should be added
1008 * @id: Identification string
82cab70b
MA
1009 * @fmt...: QMP message to send to qemu, formatted like
1010 * qobject_from_jsonf_nofail(). See parse_escape() for what's
1011 * supported after '%'.
acd80015
TH
1012 *
1013 * Generic hot-plugging test via the device_add QMP command.
1014 */
1015void qtest_qmp_device_add(const char *driver, const char *id, const char *fmt,
1016 ...) GCC_FMT_ATTR(3, 4);
1017
1018/**
1019 * qtest_qmp_device_del:
1020 * @id: Identification string
1021 *
1022 * Generic hot-unplugging test via the device_del QMP command.
1023 */
1024void qtest_qmp_device_del(const char *id);
1025
c35665e1
IM
1026/**
1027 * qmp_rsp_is_err:
1028 * @rsp: QMP response to check for error
1029 *
1030 * Test @rsp for error and discard @rsp.
1031 * Returns 'true' if there is error in @rsp and 'false' otherwise.
1032 */
1033bool qmp_rsp_is_err(QDict *rsp);
1034
ebb4d82d
MAL
1035/**
1036 * qmp_assert_error_class:
1037 * @rsp: QMP response to check for error
1038 * @class: an error class
1039 *
1040 * Assert the response has the given error class and discard @rsp.
1041 */
1042void qmp_assert_error_class(QDict *rsp, const char *class);
1043
21f80286
RH
1044/**
1045 * qtest_probe_child:
1046 * @s: QTestState instance to operate on.
1047 *
1048 * Returns: true if the child is still alive.
1049 */
1050bool qtest_probe_child(QTestState *s);
1051
49ee3590 1052#endif