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