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