target/ppc: Detect erroneous condition in interrupt delivery
[qemu/kevin.git] / tests / libqtest.h
blob5937f919123eb7d24dc38e8b3d11f636f0fb1491
1 /*
2 * QTest
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
6 * Copyright SUSE LINUX Products GmbH 2013
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
11 * Andreas Färber <afaerber@suse.de>
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.
17 #ifndef LIBQTEST_H
18 #define LIBQTEST_H
20 typedef struct QTestState QTestState;
22 extern QTestState *global_qtest;
24 /**
25 * qtest_initf:
26 * @fmt...: Format for creating other arguments to pass to QEMU, formatted
27 * like sprintf().
29 * Convenience wrapper around qtest_start().
31 * Returns: #QTestState instance.
33 QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
35 /**
36 * qtest_vinitf:
37 * @fmt: Format for creating other arguments to pass to QEMU, formatted
38 * like vsprintf().
39 * @ap: Format arguments.
41 * Convenience wrapper around qtest_start().
43 * Returns: #QTestState instance.
45 QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0);
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.
52 * Returns: #QTestState instance.
54 QTestState *qtest_init(const char *extra_args);
56 /**
57 * qtest_init_without_qmp_handshake:
58 * @extra_args: other arguments to pass to QEMU. CAUTION: these
59 * arguments are subject to word splitting and shell evaluation.
61 * Returns: #QTestState instance.
63 QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
65 /**
66 * qtest_init_with_serial:
67 * @extra_args: other arguments to pass to QEMU. CAUTION: these
68 * arguments are subject to word splitting and shell evaluation.
69 * @sock_fd: pointer to store the socket file descriptor for
70 * connection with serial.
72 * Returns: #QTestState instance.
74 QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
76 /**
77 * qtest_quit:
78 * @s: #QTestState instance to operate on.
80 * Shut down the QEMU process associated to @s.
82 void qtest_quit(QTestState *s);
84 /**
85 * qtest_qmp:
86 * @s: #QTestState instance to operate on.
87 * @fmt...: QMP message to send to qemu, formatted like
88 * qobject_from_jsonf_nofail(). See parse_escape() for what's
89 * supported after '%'.
91 * Sends a QMP message to QEMU and returns the response.
93 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
94 GCC_FMT_ATTR(2, 3);
96 /**
97 * qtest_qmp_send:
98 * @s: #QTestState instance to operate on.
99 * @fmt...: QMP message to send to qemu, formatted like
100 * qobject_from_jsonf_nofail(). See parse_escape() for what's
101 * supported after '%'.
103 * Sends a QMP message to QEMU and leaves the response in the stream.
105 void qtest_qmp_send(QTestState *s, const char *fmt, ...)
106 GCC_FMT_ATTR(2, 3);
109 * qtest_qmp_send_raw:
110 * @s: #QTestState instance to operate on.
111 * @fmt...: text to send, formatted like sprintf()
113 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
114 * this is useful for negative tests.
116 void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
117 GCC_FMT_ATTR(2, 3);
120 * qtest_qmpv:
121 * @s: #QTestState instance to operate on.
122 * @fmt: QMP message to send to QEMU, formatted like
123 * qobject_from_jsonf_nofail(). See parse_escape() for what's
124 * supported after '%'.
125 * @ap: QMP message arguments
127 * Sends a QMP message to QEMU and returns the response.
129 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
130 GCC_FMT_ATTR(2, 0);
133 * qtest_qmp_vsend:
134 * @s: #QTestState instance to operate on.
135 * @fmt: QMP message to send to QEMU, formatted like
136 * qobject_from_jsonf_nofail(). See parse_escape() for what's
137 * supported after '%'.
138 * @ap: QMP message arguments
140 * Sends a QMP message to QEMU and leaves the response in the stream.
142 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
143 GCC_FMT_ATTR(2, 0);
146 * qtest_receive:
147 * @s: #QTestState instance to operate on.
149 * Reads a QMP message from QEMU and returns the response.
151 QDict *qtest_qmp_receive(QTestState *s);
154 * qtest_qmp_eventwait:
155 * @s: #QTestState instance to operate on.
156 * @s: #event event to wait for.
158 * Continuously polls for QMP responses until it receives the desired event.
160 void qtest_qmp_eventwait(QTestState *s, const char *event);
163 * qtest_qmp_eventwait_ref:
164 * @s: #QTestState instance to operate on.
165 * @s: #event event to wait for.
167 * Continuously polls for QMP responses until it receives the desired event.
168 * Returns a copy of the event for further investigation.
170 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
173 * qtest_qmp_receive_success:
174 * @s: #QTestState instance to operate on
175 * @event_cb: Event callback
176 * @opaque: Argument for @event_cb
178 * Poll QMP messages until a command success response is received.
179 * If @event_cb, call it for each event received, passing @opaque,
180 * the event's name and data.
181 * Return the success response's "return" member.
183 QDict *qtest_qmp_receive_success(QTestState *s,
184 void (*event_cb)(void *opaque,
185 const char *name,
186 QDict *data),
187 void *opaque);
190 * qtest_hmp:
191 * @s: #QTestState instance to operate on.
192 * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
194 * Send HMP command to QEMU via QMP's human-monitor-command.
195 * QMP events are discarded.
197 * Returns: the command's output. The caller should g_free() it.
199 char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
202 * qtest_hmpv:
203 * @s: #QTestState instance to operate on.
204 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
205 * @ap: HMP command arguments
207 * Send HMP command to QEMU via QMP's human-monitor-command.
208 * QMP events are discarded.
210 * Returns: the command's output. The caller should g_free() it.
212 char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
213 GCC_FMT_ATTR(2, 0);
216 * qtest_get_irq:
217 * @s: #QTestState instance to operate on.
218 * @num: Interrupt to observe.
220 * Returns: The level of the @num interrupt.
222 bool qtest_get_irq(QTestState *s, int num);
225 * qtest_irq_intercept_in:
226 * @s: #QTestState instance to operate on.
227 * @string: QOM path of a device.
229 * Associate qtest irqs with the GPIO-in pins of the device
230 * whose path is specified by @string.
232 void qtest_irq_intercept_in(QTestState *s, const char *string);
235 * qtest_irq_intercept_out:
236 * @s: #QTestState instance to operate on.
237 * @string: QOM path of a device.
239 * Associate qtest irqs with the GPIO-out pins of the device
240 * whose path is specified by @string.
242 void qtest_irq_intercept_out(QTestState *s, const char *string);
245 * qtest_set_irq_in:
246 * @s: QTestState instance to operate on.
247 * @string: QOM path of a device
248 * @name: IRQ name
249 * @irq: IRQ number
250 * @level: IRQ level
252 * Force given device/irq GPIO-in pin to the given level.
254 void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
255 int irq, int level);
258 * qtest_outb:
259 * @s: #QTestState instance to operate on.
260 * @addr: I/O port to write to.
261 * @value: Value being written.
263 * Write an 8-bit value to an I/O port.
265 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
268 * qtest_outw:
269 * @s: #QTestState instance to operate on.
270 * @addr: I/O port to write to.
271 * @value: Value being written.
273 * Write a 16-bit value to an I/O port.
275 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
278 * qtest_outl:
279 * @s: #QTestState instance to operate on.
280 * @addr: I/O port to write to.
281 * @value: Value being written.
283 * Write a 32-bit value to an I/O port.
285 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
288 * qtest_inb:
289 * @s: #QTestState instance to operate on.
290 * @addr: I/O port to read from.
292 * Returns an 8-bit value from an I/O port.
294 uint8_t qtest_inb(QTestState *s, uint16_t addr);
297 * qtest_inw:
298 * @s: #QTestState instance to operate on.
299 * @addr: I/O port to read from.
301 * Returns a 16-bit value from an I/O port.
303 uint16_t qtest_inw(QTestState *s, uint16_t addr);
306 * qtest_inl:
307 * @s: #QTestState instance to operate on.
308 * @addr: I/O port to read from.
310 * Returns a 32-bit value from an I/O port.
312 uint32_t qtest_inl(QTestState *s, uint16_t addr);
315 * qtest_writeb:
316 * @s: #QTestState instance to operate on.
317 * @addr: Guest address to write to.
318 * @value: Value being written.
320 * Writes an 8-bit value to memory.
322 void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
325 * qtest_writew:
326 * @s: #QTestState instance to operate on.
327 * @addr: Guest address to write to.
328 * @value: Value being written.
330 * Writes a 16-bit value to memory.
332 void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
335 * qtest_writel:
336 * @s: #QTestState instance to operate on.
337 * @addr: Guest address to write to.
338 * @value: Value being written.
340 * Writes a 32-bit value to memory.
342 void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
345 * qtest_writeq:
346 * @s: #QTestState instance to operate on.
347 * @addr: Guest address to write to.
348 * @value: Value being written.
350 * Writes a 64-bit value to memory.
352 void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
355 * qtest_readb:
356 * @s: #QTestState instance to operate on.
357 * @addr: Guest address to read from.
359 * Reads an 8-bit value from memory.
361 * Returns: Value read.
363 uint8_t qtest_readb(QTestState *s, uint64_t addr);
366 * qtest_readw:
367 * @s: #QTestState instance to operate on.
368 * @addr: Guest address to read from.
370 * Reads a 16-bit value from memory.
372 * Returns: Value read.
374 uint16_t qtest_readw(QTestState *s, uint64_t addr);
377 * qtest_readl:
378 * @s: #QTestState instance to operate on.
379 * @addr: Guest address to read from.
381 * Reads a 32-bit value from memory.
383 * Returns: Value read.
385 uint32_t qtest_readl(QTestState *s, uint64_t addr);
388 * qtest_readq:
389 * @s: #QTestState instance to operate on.
390 * @addr: Guest address to read from.
392 * Reads a 64-bit value from memory.
394 * Returns: Value read.
396 uint64_t qtest_readq(QTestState *s, uint64_t addr);
399 * qtest_memread:
400 * @s: #QTestState instance to operate on.
401 * @addr: Guest address to read from.
402 * @data: Pointer to where memory contents will be stored.
403 * @size: Number of bytes to read.
405 * Read guest memory into a buffer.
407 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
410 * qtest_rtas_call:
411 * @s: #QTestState instance to operate on.
412 * @name: name of the command to call.
413 * @nargs: Number of args.
414 * @args: Guest address to read args from.
415 * @nret: Number of return value.
416 * @ret: Guest address to write return values to.
418 * Call an RTAS function
420 uint64_t qtest_rtas_call(QTestState *s, const char *name,
421 uint32_t nargs, uint64_t args,
422 uint32_t nret, uint64_t ret);
425 * qtest_bufread:
426 * @s: #QTestState instance to operate on.
427 * @addr: Guest address to read from.
428 * @data: Pointer to where memory contents will be stored.
429 * @size: Number of bytes to read.
431 * Read guest memory into a buffer and receive using a base64 encoding.
433 void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
436 * qtest_memwrite:
437 * @s: #QTestState instance to operate on.
438 * @addr: Guest address to write to.
439 * @data: Pointer to the bytes that will be written to guest memory.
440 * @size: Number of bytes to write.
442 * Write a buffer to guest memory.
444 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
447 * qtest_bufwrite:
448 * @s: #QTestState instance to operate on.
449 * @addr: Guest address to write to.
450 * @data: Pointer to the bytes that will be written to guest memory.
451 * @size: Number of bytes to write.
453 * Write a buffer to guest memory and transmit using a base64 encoding.
455 void qtest_bufwrite(QTestState *s, uint64_t addr,
456 const void *data, size_t size);
459 * qtest_memset:
460 * @s: #QTestState instance to operate on.
461 * @addr: Guest address to write to.
462 * @patt: Byte pattern to fill the guest memory region with.
463 * @size: Number of bytes to write.
465 * Write a pattern to guest memory.
467 void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
470 * qtest_clock_step_next:
471 * @s: #QTestState instance to operate on.
473 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
475 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
477 int64_t qtest_clock_step_next(QTestState *s);
480 * qtest_clock_step:
481 * @s: QTestState instance to operate on.
482 * @step: Number of nanoseconds to advance the clock by.
484 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
486 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
488 int64_t qtest_clock_step(QTestState *s, int64_t step);
491 * qtest_clock_set:
492 * @s: QTestState instance to operate on.
493 * @val: Nanoseconds value to advance the clock to.
495 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
497 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
499 int64_t qtest_clock_set(QTestState *s, int64_t val);
502 * qtest_big_endian:
503 * @s: QTestState instance to operate on.
505 * Returns: True if the architecture under test has a big endian configuration.
507 bool qtest_big_endian(QTestState *s);
510 * qtest_get_arch:
512 * Returns: The architecture for the QEMU executable under test.
514 const char *qtest_get_arch(void);
517 * qtest_add_func:
518 * @str: Test case path.
519 * @fn: Test case function
521 * Add a GTester testcase with the given name and function.
522 * The path is prefixed with the architecture under test, as
523 * returned by qtest_get_arch().
525 void qtest_add_func(const char *str, void (*fn)(void));
528 * qtest_add_data_func:
529 * @str: Test case path.
530 * @data: Test case data
531 * @fn: Test case function
533 * Add a GTester testcase with the given name, data and function.
534 * The path is prefixed with the architecture under test, as
535 * returned by qtest_get_arch().
537 void qtest_add_data_func(const char *str, const void *data,
538 void (*fn)(const void *));
541 * qtest_add_data_func_full:
542 * @str: Test case path.
543 * @data: Test case data
544 * @fn: Test case function
545 * @data_free_func: GDestroyNotify for data
547 * Add a GTester testcase with the given name, data and function.
548 * The path is prefixed with the architecture under test, as
549 * returned by qtest_get_arch().
551 * @data is passed to @data_free_func() on test completion.
553 void qtest_add_data_func_full(const char *str, void *data,
554 void (*fn)(const void *),
555 GDestroyNotify data_free_func);
558 * qtest_add:
559 * @testpath: Test case path
560 * @Fixture: Fixture type
561 * @tdata: Test case data
562 * @fsetup: Test case setup function
563 * @ftest: Test case function
564 * @fteardown: Test case teardown function
566 * Add a GTester testcase with the given name, data and functions.
567 * The path is prefixed with the architecture under test, as
568 * returned by qtest_get_arch().
570 #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
571 do { \
572 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
573 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
574 g_free(path); \
575 } while (0)
577 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
580 * qtest_start:
581 * @args: other arguments to pass to QEMU
583 * Start QEMU and assign the resulting #QTestState to a global variable.
584 * The global variable is used by "shortcut" functions documented below.
586 * Returns: #QTestState instance.
588 static inline QTestState *qtest_start(const char *args)
590 global_qtest = qtest_init(args);
591 return global_qtest;
595 * qtest_end:
597 * Shut down the QEMU process started by qtest_start().
599 static inline void qtest_end(void)
601 qtest_quit(global_qtest);
602 global_qtest = NULL;
606 * qmp:
607 * @fmt...: QMP message to send to qemu, formatted like
608 * qobject_from_jsonf_nofail(). See parse_escape() for what's
609 * supported after '%'.
611 * Sends a QMP message to QEMU and returns the response.
613 QDict *qmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
616 * qmp_send:
617 * @fmt...: QMP message to send to qemu, formatted like
618 * qobject_from_jsonf_nofail(). See parse_escape() for what's
619 * supported after '%'.
621 * Sends a QMP message to QEMU and leaves the response in the stream.
623 void qmp_send(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
626 * qmp_receive:
628 * Reads a QMP message from QEMU and returns the response.
630 static inline QDict *qmp_receive(void)
632 return qtest_qmp_receive(global_qtest);
636 * qmp_eventwait:
637 * @s: #event event to wait for.
639 * Continuously polls for QMP responses until it receives the desired event.
641 static inline void qmp_eventwait(const char *event)
643 return qtest_qmp_eventwait(global_qtest, event);
647 * qmp_eventwait_ref:
648 * @s: #event event to wait for.
650 * Continuously polls for QMP responses until it receives the desired event.
651 * Returns a copy of the event for further investigation.
653 static inline QDict *qmp_eventwait_ref(const char *event)
655 return qtest_qmp_eventwait_ref(global_qtest, event);
659 * hmp:
660 * @fmt...: HMP command to send to QEMU, formats arguments like sprintf().
662 * Send HMP command to QEMU via QMP's human-monitor-command.
664 * Returns: the command's output. The caller should g_free() it.
666 char *hmp(const char *fmt, ...) GCC_FMT_ATTR(1, 2);
669 * get_irq:
670 * @num: Interrupt to observe.
672 * Returns: The level of the @num interrupt.
674 static inline bool get_irq(int num)
676 return qtest_get_irq(global_qtest, num);
680 * irq_intercept_in:
681 * @string: QOM path of a device.
683 * Associate qtest irqs with the GPIO-in pins of the device
684 * whose path is specified by @string.
686 static inline void irq_intercept_in(const char *string)
688 qtest_irq_intercept_in(global_qtest, string);
692 * qtest_irq_intercept_out:
693 * @string: QOM path of a device.
695 * Associate qtest irqs with the GPIO-out pins of the device
696 * whose path is specified by @string.
698 static inline void irq_intercept_out(const char *string)
700 qtest_irq_intercept_out(global_qtest, string);
704 * outb:
705 * @addr: I/O port to write to.
706 * @value: Value being written.
708 * Write an 8-bit value to an I/O port.
710 static inline void outb(uint16_t addr, uint8_t value)
712 qtest_outb(global_qtest, addr, value);
716 * outw:
717 * @addr: I/O port to write to.
718 * @value: Value being written.
720 * Write a 16-bit value to an I/O port.
722 static inline void outw(uint16_t addr, uint16_t value)
724 qtest_outw(global_qtest, addr, value);
728 * outl:
729 * @addr: I/O port to write to.
730 * @value: Value being written.
732 * Write a 32-bit value to an I/O port.
734 static inline void outl(uint16_t addr, uint32_t value)
736 qtest_outl(global_qtest, addr, value);
740 * inb:
741 * @addr: I/O port to read from.
743 * Reads an 8-bit value from an I/O port.
745 * Returns: Value read.
747 static inline uint8_t inb(uint16_t addr)
749 return qtest_inb(global_qtest, addr);
753 * inw:
754 * @addr: I/O port to read from.
756 * Reads a 16-bit value from an I/O port.
758 * Returns: Value read.
760 static inline uint16_t inw(uint16_t addr)
762 return qtest_inw(global_qtest, addr);
766 * inl:
767 * @addr: I/O port to read from.
769 * Reads a 32-bit value from an I/O port.
771 * Returns: Value read.
773 static inline uint32_t inl(uint16_t addr)
775 return qtest_inl(global_qtest, addr);
779 * writeb:
780 * @addr: Guest address to write to.
781 * @value: Value being written.
783 * Writes an 8-bit value to guest memory.
785 static inline void writeb(uint64_t addr, uint8_t value)
787 qtest_writeb(global_qtest, addr, value);
791 * writew:
792 * @addr: Guest address to write to.
793 * @value: Value being written.
795 * Writes a 16-bit value to guest memory.
797 static inline void writew(uint64_t addr, uint16_t value)
799 qtest_writew(global_qtest, addr, value);
803 * writel:
804 * @addr: Guest address to write to.
805 * @value: Value being written.
807 * Writes a 32-bit value to guest memory.
809 static inline void writel(uint64_t addr, uint32_t value)
811 qtest_writel(global_qtest, addr, value);
815 * writeq:
816 * @addr: Guest address to write to.
817 * @value: Value being written.
819 * Writes a 64-bit value to guest memory.
821 static inline void writeq(uint64_t addr, uint64_t value)
823 qtest_writeq(global_qtest, addr, value);
827 * readb:
828 * @addr: Guest address to read from.
830 * Reads an 8-bit value from guest memory.
832 * Returns: Value read.
834 static inline uint8_t readb(uint64_t addr)
836 return qtest_readb(global_qtest, addr);
840 * readw:
841 * @addr: Guest address to read from.
843 * Reads a 16-bit value from guest memory.
845 * Returns: Value read.
847 static inline uint16_t readw(uint64_t addr)
849 return qtest_readw(global_qtest, addr);
853 * readl:
854 * @addr: Guest address to read from.
856 * Reads a 32-bit value from guest memory.
858 * Returns: Value read.
860 static inline uint32_t readl(uint64_t addr)
862 return qtest_readl(global_qtest, addr);
866 * readq:
867 * @addr: Guest address to read from.
869 * Reads a 64-bit value from guest memory.
871 * Returns: Value read.
873 static inline uint64_t readq(uint64_t addr)
875 return qtest_readq(global_qtest, addr);
879 * memread:
880 * @addr: Guest address to read from.
881 * @data: Pointer to where memory contents will be stored.
882 * @size: Number of bytes to read.
884 * Read guest memory into a buffer.
886 static inline void memread(uint64_t addr, void *data, size_t size)
888 qtest_memread(global_qtest, addr, data, size);
892 * bufread:
893 * @addr: Guest address to read from.
894 * @data: Pointer to where memory contents will be stored.
895 * @size: Number of bytes to read.
897 * Read guest memory into a buffer, receive using a base64 encoding.
899 static inline void bufread(uint64_t addr, void *data, size_t size)
901 qtest_bufread(global_qtest, addr, data, size);
905 * memwrite:
906 * @addr: Guest address to write to.
907 * @data: Pointer to the bytes that will be written to guest memory.
908 * @size: Number of bytes to write.
910 * Write a buffer to guest memory.
912 static inline void memwrite(uint64_t addr, const void *data, size_t size)
914 qtest_memwrite(global_qtest, addr, data, size);
918 * bufwrite:
919 * @addr: Guest address to write to.
920 * @data: Pointer to the bytes that will be written to guest memory.
921 * @size: Number of bytes to write.
923 * Write a buffer to guest memory, transmit using a base64 encoding.
925 static inline void bufwrite(uint64_t addr, const void *data, size_t size)
927 qtest_bufwrite(global_qtest, addr, data, size);
931 * qmemset:
932 * @addr: Guest address to write to.
933 * @patt: Byte pattern to fill the guest memory region with.
934 * @size: Number of bytes to write.
936 * Write a pattern to guest memory.
938 static inline void qmemset(uint64_t addr, uint8_t patt, size_t size)
940 qtest_memset(global_qtest, addr, patt, size);
944 * clock_step_next:
946 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
948 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
950 static inline int64_t clock_step_next(void)
952 return qtest_clock_step_next(global_qtest);
956 * clock_step:
957 * @step: Number of nanoseconds to advance the clock by.
959 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
961 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
963 static inline int64_t clock_step(int64_t step)
965 return qtest_clock_step(global_qtest, step);
969 * clock_set:
970 * @val: Nanoseconds value to advance the clock to.
972 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
974 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
976 static inline int64_t clock_set(int64_t val)
978 return qtest_clock_set(global_qtest, val);
981 QDict *qmp_fd_receive(int fd);
982 void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
983 void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
984 void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
985 void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
986 QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
987 QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
990 * qtest_cb_for_every_machine:
991 * @cb: Pointer to the callback function
992 * @skip_old_versioned: true if versioned old machine types should be skipped
994 * Call a callback function for every name of all available machines.
996 void qtest_cb_for_every_machine(void (*cb)(const char *machine),
997 bool skip_old_versioned);
1000 * qtest_qmp_device_add:
1001 * @driver: Name of the device that should be added
1002 * @id: Identification string
1003 * @fmt...: QMP message to send to qemu, formatted like
1004 * qobject_from_jsonf_nofail(). See parse_escape() for what's
1005 * supported after '%'.
1007 * Generic hot-plugging test via the device_add QMP command.
1009 void qtest_qmp_device_add(const char *driver, const char *id, const char *fmt,
1010 ...) GCC_FMT_ATTR(3, 4);
1013 * qtest_qmp_device_del:
1014 * @id: Identification string
1016 * Generic hot-unplugging test via the device_del QMP command.
1018 void qtest_qmp_device_del(const char *id);
1021 * qmp_rsp_is_err:
1022 * @rsp: QMP response to check for error
1024 * Test @rsp for error and discard @rsp.
1025 * Returns 'true' if there is error in @rsp and 'false' otherwise.
1027 bool qmp_rsp_is_err(QDict *rsp);
1030 * qmp_assert_error_class:
1031 * @rsp: QMP response to check for error
1032 * @class: an error class
1034 * Assert the response has the given error class and discard @rsp.
1036 void qmp_assert_error_class(QDict *rsp, const char *class);
1039 * qtest_probe_child:
1040 * @s: QTestState instance to operate on.
1042 * Returns: true if the child is still alive.
1044 bool qtest_probe_child(QTestState *s);
1046 #endif