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