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