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