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