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