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