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