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