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