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