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