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