master
h 1,211 lines 34.6 KB
Raw
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 "qobject/qobject.h"
21 #include "qobject/qdict.h"
22 #include "qobject/qlist.h"
23 #include "libqmp.h"
24
25 typedef struct QTestState QTestState;
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, ...) G_GNUC_PRINTF(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) G_GNUC_PRINTF(1, 0);
49
50 /**
51 * qtest_qemu_binary:
52 * @var: environment variable name
53 *
54 * Look up @var and return its value as the qemu binary path.
55 * If @var is NULL, look up the default var name.
56 */
57 const char *qtest_qemu_binary(const char *var);
58
59 /**
60 * qtest_init_after_exec:
61 * @qts: the previous QEMU state
62 *
63 * Return a test state representing new QEMU after @qts exec's it.
64 */
65 QTestState *qtest_init_after_exec(QTestState *qts);
66
67 /**
68 * qtest_qemu_args:
69 * @extra_args: Other arguments to pass to QEMU.
70 *
71 * Return the command line used to start QEMU, sans binary.
72 */
73 gchar *qtest_qemu_args(const char *extra_args);
74
75 /**
76 * qtest_init:
77 * @extra_args: other arguments to pass to QEMU. CAUTION: these
78 * arguments are subject to word splitting and shell evaluation.
79 *
80 * Returns: #QTestState instance.
81 */
82 QTestState *qtest_init(const char *extra_args);
83
84 /**
85 * qtest_init_ext:
86 * @var: Environment variable from where to take the QEMU binary
87 * @extra_args: Other arguments to pass to QEMU. CAUTION: these
88 * arguments are subject to word splitting and shell evaluation.
89 * @capabilities: list of QMP capabilities (strings) to enable
90 * @do_connect: connect to qemu monitor and qtest socket.
91 *
92 * Like qtest_init(), but use a different environment variable for the
93 * QEMU binary, allow specify capabilities and skip connecting
94 * to QEMU monitor.
95 *
96 * Returns: #QTestState instance.
97 */
98 QTestState *qtest_init_ext(const char *var, const char *extra_args,
99 QList *capabilities, bool do_connect);
100
101 /**
102 * qtest_init_without_qmp_handshake:
103 * @extra_args: other arguments to pass to QEMU. CAUTION: these
104 * arguments are subject to word splitting and shell evaluation.
105 *
106 * Returns: #QTestState instance.
107 */
108 QTestState *qtest_init_without_qmp_handshake(const char *extra_args);
109
110 /**
111 * qtest_connect
112 * @s: #QTestState instance to connect
113 * Connect to qemu monitor and qtest socket, after skipping them in
114 * qtest_init_ext. Does not handshake with the monitor.
115 */
116 void qtest_connect(QTestState *s);
117
118 /**
119 * qtest_qmp_handshake:
120 * @s: #QTestState instance to operate on.
121 * @capabilities: list of QMP capabilities (strings) to enable
122 * Perform handshake after connecting to qemu monitor.
123 */
124 void qtest_qmp_handshake(QTestState *s, QList *capabilities);
125
126 /**
127 * qtest_init_with_serial:
128 * @extra_args: other arguments to pass to QEMU. CAUTION: these
129 * arguments are subject to word splitting and shell evaluation.
130 * @sock_fd: pointer to store the socket file descriptor for
131 * connection with serial.
132 *
133 * Returns: #QTestState instance.
134 */
135 QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd);
136
137 /**
138 * qtest_system_reset:
139 * @s: #QTestState instance to operate on.
140 *
141 * Send a "system_reset" command to the QEMU under test, and wait for
142 * the reset to complete before returning.
143 */
144 void qtest_system_reset(QTestState *s);
145
146 /**
147 * qtest_system_reset_nowait:
148 * @s: #QTestState instance to operate on.
149 *
150 * Send a "system_reset" command to the QEMU under test, but do not
151 * wait for the reset to complete before returning. The caller is
152 * responsible for waiting for either the RESET event or some other
153 * event of interest to them before proceeding.
154 *
155 * This function should only be used if you're specifically testing
156 * for some other event; in that case you can't use qtest_system_reset()
157 * because it will read and discard any other QMP events that arrive
158 * before the RESET event.
159 */
160 void qtest_system_reset_nowait(QTestState *s);
161
162 /**
163 * qtest_wait_qemu:
164 * @s: #QTestState instance to operate on.
165 *
166 * Wait for the QEMU process to terminate. It is safe to call this function
167 * multiple times.
168 */
169 void qtest_wait_qemu(QTestState *s);
170
171 /**
172 * qtest_kill_qemu:
173 * @s: #QTestState instance to operate on.
174 *
175 * Kill the QEMU process and wait for it to terminate. It is safe to call this
176 * function multiple times. Normally qtest_quit() is used instead because it
177 * also frees QTestState. Use qtest_kill_qemu() when you just want to kill QEMU
178 * and qtest_quit() will be called later.
179 */
180 void qtest_kill_qemu(QTestState *s);
181
182 /**
183 * qtest_quit:
184 * @s: #QTestState instance to operate on.
185 *
186 * Shut down the QEMU process associated to @s.
187 */
188 void qtest_quit(QTestState *s);
189
190 #ifndef _WIN32
191 /**
192 * qtest_qmp_fds:
193 * @s: #QTestState instance to operate on.
194 * @fds: array of file descriptors
195 * @fds_num: number of elements in @fds
196 * @fmt: QMP message to send to qemu, formatted like
197 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
198 * supported after '%'.
199 *
200 * Sends a QMP message to QEMU with fds and returns the response.
201 */
202 QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
203 const char *fmt, ...)
204 G_GNUC_PRINTF(4, 5);
205 #endif /* _WIN32 */
206
207 /**
208 * qtest_qmp:
209 * @s: #QTestState instance to operate on.
210 * @fmt: QMP message to send to qemu, formatted like
211 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
212 * supported after '%'.
213 *
214 * Sends a QMP message to QEMU and returns the response.
215 */
216 QDict *qtest_qmp(QTestState *s, const char *fmt, ...)
217 G_GNUC_PRINTF(2, 3);
218
219 /**
220 * qtest_qmp_send:
221 * @s: #QTestState instance to operate on.
222 * @fmt: QMP message to send to qemu, formatted like
223 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
224 * supported after '%'.
225 *
226 * Sends a QMP message to QEMU and leaves the response in the stream.
227 */
228 void qtest_qmp_send(QTestState *s, const char *fmt, ...)
229 G_GNUC_PRINTF(2, 3);
230
231 /**
232 * qtest_qmp_send_raw:
233 * @s: #QTestState instance to operate on.
234 * @fmt: text to send, formatted like sprintf()
235 *
236 * Sends text to the QMP monitor verbatim. Need not be valid JSON;
237 * this is useful for negative tests.
238 */
239 void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
240 G_GNUC_PRINTF(2, 3);
241
242 /**
243 * qtest_socket_server:
244 * @socket_path: the UNIX domain socket path
245 *
246 * Create and return a listen socket file descriptor, or abort on failure.
247 */
248 int qtest_socket_server(const char *socket_path);
249
250 #ifndef _WIN32
251 /**
252 * qtest_vqmp_fds:
253 * @s: #QTestState instance to operate on.
254 * @fds: array of file descriptors
255 * @fds_num: number of elements in @fds
256 * @fmt: QMP message to send to QEMU, formatted like
257 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
258 * supported after '%'.
259 * @ap: QMP message arguments
260 *
261 * Sends a QMP message to QEMU with fds and returns the response.
262 */
263 QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
264 const char *fmt, va_list ap)
265 G_GNUC_PRINTF(4, 0);
266 #endif /* _WIN32 */
267
268 /**
269 * qtest_vqmp:
270 * @s: #QTestState instance to operate on.
271 * @fmt: QMP message to send to QEMU, formatted like
272 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
273 * supported after '%'.
274 * @ap: QMP message arguments
275 *
276 * Sends a QMP message to QEMU and returns the response.
277 */
278 QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
279 G_GNUC_PRINTF(2, 0);
280
281 #ifndef _WIN32
282 /**
283 * qtest_qmp_vsend_fds:
284 * @s: #QTestState instance to operate on.
285 * @fds: array of file descriptors
286 * @fds_num: number of elements in @fds
287 * @fmt: QMP message to send to QEMU, formatted like
288 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
289 * supported after '%'.
290 * @ap: QMP message arguments
291 *
292 * Sends a QMP message to QEMU and leaves the response in the stream.
293 */
294 void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
295 const char *fmt, va_list ap)
296 G_GNUC_PRINTF(4, 0);
297 #endif /* _WIN32 */
298
299 /**
300 * qtest_qmp_vsend:
301 * @s: #QTestState instance to operate on.
302 * @fmt: QMP message to send to QEMU, formatted like
303 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
304 * supported after '%'.
305 * @ap: QMP message arguments
306 *
307 * Sends a QMP message to QEMU and leaves the response in the stream.
308 */
309 void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
310 G_GNUC_PRINTF(2, 0);
311
312 /**
313 * qtest_qmp_receive_dict:
314 * @s: #QTestState instance to operate on.
315 *
316 * Reads a QMP message from QEMU and returns the response.
317 */
318 QDict *qtest_qmp_receive_dict(QTestState *s);
319
320 /**
321 * qtest_qmp_receive:
322 * @s: #QTestState instance to operate on.
323 *
324 * Reads a QMP message from QEMU and returns the response.
325 *
326 * If a callback is registered with qtest_qmp_set_event_callback,
327 * it will be invoked for every event seen, otherwise events
328 * will be buffered until a call to one of the qtest_qmp_eventwait
329 * family of functions.
330 */
331 QDict *qtest_qmp_receive(QTestState *s);
332
333 /*
334 * QTestQMPEventCallback:
335 * @s: #QTestState instance event was received on
336 * @name: name of the event type
337 * @event: #QDict for the event details
338 * @opaque: opaque data from time of callback registration
339 *
340 * This callback will be invoked whenever an event is received.
341 * If the callback returns true the event will be consumed,
342 * otherwise it will be put on the list of pending events.
343 * Pending events can be later handled by calling either
344 * qtest_qmp_eventwait or qtest_qmp_eventwait_ref.
345 *
346 * Return: true to consume the event, false to let it be queued
347 */
348 typedef bool (*QTestQMPEventCallback)(QTestState *s, const char *name,
349 QDict *event, void *opaque);
350
351 /**
352 * qtest_qmp_set_event_callback:
353 * @s: #QTestSTate instance to operate on
354 * @cb: callback to invoke for events
355 * @opaque: data to pass to @cb
356 *
357 * Register a callback to be invoked whenever an event arrives
358 */
359 void qtest_qmp_set_event_callback(QTestState *s,
360 QTestQMPEventCallback cb, void *opaque);
361
362 /**
363 * qtest_qmp_eventwait:
364 * @s: #QTestState instance to operate on.
365 * @event: event to wait for.
366 *
367 * Continuously polls for QMP responses until it receives the desired event.
368 *
369 * Any callback registered with qtest_qmp_set_event_callback will
370 * be invoked for every event seen.
371 */
372 void qtest_qmp_eventwait(QTestState *s, const char *event);
373
374 /**
375 * qtest_qmp_eventwait_ref:
376 * @s: #QTestState instance to operate on.
377 * @event: event to wait for.
378 *
379 * Continuously polls for QMP responses until it receives the desired event.
380 *
381 * Any callback registered with qtest_qmp_set_event_callback will
382 * be invoked for every event seen.
383 *
384 * Returns a copy of the event for further investigation.
385 */
386 QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event);
387
388 /**
389 * qtest_qmp_event_ref:
390 * @s: #QTestState instance to operate on.
391 * @event: event to return.
392 *
393 * Removes non-matching events from the buffer that was set by
394 * qtest_qmp_receive, until an event bearing the given name is found,
395 * and returns it.
396 * If no event matches, clears the buffer and returns NULL.
397 *
398 */
399 QDict *qtest_qmp_event_ref(QTestState *s, const char *event);
400
401 /**
402 * qtest_hmp:
403 * @s: #QTestState instance to operate on.
404 * @fmt: HMP command to send to QEMU, formats arguments like sprintf().
405 *
406 * Send HMP command to QEMU via QMP's human-monitor-command.
407 * QMP events are discarded.
408 *
409 * Returns: the command's output. The caller should g_free() it.
410 */
411 char *qtest_hmp(QTestState *s, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
412
413 /**
414 * qtest_vhmp:
415 * @s: #QTestState instance to operate on.
416 * @fmt: HMP command to send to QEMU, formats arguments like vsprintf().
417 * @ap: HMP command arguments
418 *
419 * Send HMP command to QEMU via QMP's human-monitor-command.
420 * QMP events are discarded.
421 *
422 * Returns: the command's output. The caller should g_free() it.
423 */
424 char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap)
425 G_GNUC_PRINTF(2, 0);
426
427 /**
428 * qtest_qemu_io:
429 * @s: #QTestState instance to operate on.
430 * @device: block device node-name or BlockBackend name.
431 * @fmt: qemu-io command to send, formats arguments like sprintf().
432 *
433 * Send a qemu-io command via the qtest protocol.
434 */
435 void qtest_qemu_io(QTestState *s, const char *device,
436 const char *fmt, ...) G_GNUC_PRINTF(3, 4);
437
438 void qtest_module_load(QTestState *s, const char *prefix, const char *libname);
439
440 /**
441 * qtest_qom_tests:
442 * @s: #QTestState instance to operate on.
443 *
444 * Run QOM property get/set round-trip tests on all non-abstract types.
445 */
446 void qtest_qom_tests(QTestState *s);
447
448 /**
449 * qtest_get_irq:
450 * @s: #QTestState instance to operate on.
451 * @num: Interrupt to observe.
452 *
453 * Returns: The level of the @num interrupt.
454 */
455 bool qtest_get_irq(QTestState *s, int num);
456
457 /**
458 * qtest_irq_intercept_in:
459 * @s: #QTestState instance to operate on.
460 * @string: QOM path of a device.
461 *
462 * Associate qtest irqs with the GPIO-in pins of the device
463 * whose path is specified by @string.
464 */
465 void qtest_irq_intercept_in(QTestState *s, const char *string);
466
467 /**
468 * qtest_irq_intercept_out:
469 * @s: #QTestState instance to operate on.
470 * @string: QOM path of a device.
471 *
472 * Associate qtest irqs with the GPIO-out pins of the device
473 * whose path is specified by @string.
474 */
475 void qtest_irq_intercept_out(QTestState *s, const char *string);
476
477 /**
478 * qtest_irq_intercept_out_named:
479 * @s: #QTestState instance to operate on.
480 * @qom_path: QOM path of a device.
481 * @name: Name of the GPIO out pin
482 *
483 * Associate a qtest irq with the named GPIO-out pin of the device
484 * whose path is specified by @string and whose name is @name.
485 */
486 void qtest_irq_intercept_out_named(QTestState *s, const char *qom_path, const char *name);
487
488 /**
489 * qtest_set_irq_in:
490 * @s: QTestState instance to operate on.
491 * @string: QOM path of a device
492 * @name: IRQ name
493 * @irq: IRQ number
494 * @level: IRQ level
495 *
496 * Force given device/irq GPIO-in pin to the given level.
497 */
498 void qtest_set_irq_in(QTestState *s, const char *string, const char *name,
499 int irq, int level);
500
501 /**
502 * qtest_outb:
503 * @s: #QTestState instance to operate on.
504 * @addr: I/O port to write to.
505 * @value: Value being written.
506 *
507 * Write an 8-bit value to an I/O port.
508 */
509 void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
510
511 /**
512 * qtest_outw:
513 * @s: #QTestState instance to operate on.
514 * @addr: I/O port to write to.
515 * @value: Value being written.
516 *
517 * Write a 16-bit value to an I/O port.
518 */
519 void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
520
521 /**
522 * qtest_outl:
523 * @s: #QTestState instance to operate on.
524 * @addr: I/O port to write to.
525 * @value: Value being written.
526 *
527 * Write a 32-bit value to an I/O port.
528 */
529 void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
530
531 /**
532 * qtest_inb:
533 * @s: #QTestState instance to operate on.
534 * @addr: I/O port to read from.
535 *
536 * Returns an 8-bit value from an I/O port.
537 */
538 uint8_t qtest_inb(QTestState *s, uint16_t addr);
539
540 /**
541 * qtest_inw:
542 * @s: #QTestState instance to operate on.
543 * @addr: I/O port to read from.
544 *
545 * Returns a 16-bit value from an I/O port.
546 */
547 uint16_t qtest_inw(QTestState *s, uint16_t addr);
548
549 /**
550 * qtest_inl:
551 * @s: #QTestState instance to operate on.
552 * @addr: I/O port to read from.
553 *
554 * Returns a 32-bit value from an I/O port.
555 */
556 uint32_t qtest_inl(QTestState *s, uint16_t addr);
557
558 /**
559 * qtest_writeb:
560 * @s: #QTestState instance to operate on.
561 * @addr: Guest address to write to.
562 * @value: Value being written.
563 *
564 * Writes an 8-bit value to memory.
565 */
566 void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
567
568 /**
569 * qtest_writew:
570 * @s: #QTestState instance to operate on.
571 * @addr: Guest address to write to.
572 * @value: Value being written.
573 *
574 * Writes a 16-bit value to memory.
575 */
576 void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
577
578 /**
579 * qtest_writel:
580 * @s: #QTestState instance to operate on.
581 * @addr: Guest address to write to.
582 * @value: Value being written.
583 *
584 * Writes a 32-bit value to memory.
585 */
586 void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
587
588 /**
589 * qtest_writeq:
590 * @s: #QTestState instance to operate on.
591 * @addr: Guest address to write to.
592 * @value: Value being written.
593 *
594 * Writes a 64-bit value to memory.
595 */
596 void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
597
598 /**
599 * qtest_readb:
600 * @s: #QTestState instance to operate on.
601 * @addr: Guest address to read from.
602 *
603 * Reads an 8-bit value from memory.
604 *
605 * Returns: Value read.
606 */
607 uint8_t qtest_readb(QTestState *s, uint64_t addr);
608
609 /**
610 * qtest_readw:
611 * @s: #QTestState instance to operate on.
612 * @addr: Guest address to read from.
613 *
614 * Reads a 16-bit value from memory.
615 *
616 * Returns: Value read.
617 */
618 uint16_t qtest_readw(QTestState *s, uint64_t addr);
619
620 /**
621 * qtest_readl:
622 * @s: #QTestState instance to operate on.
623 * @addr: Guest address to read from.
624 *
625 * Reads a 32-bit value from memory.
626 *
627 * Returns: Value read.
628 */
629 uint32_t qtest_readl(QTestState *s, uint64_t addr);
630
631 /**
632 * qtest_readq:
633 * @s: #QTestState instance to operate on.
634 * @addr: Guest address to read from.
635 *
636 * Reads a 64-bit value from memory.
637 *
638 * Returns: Value read.
639 */
640 uint64_t qtest_readq(QTestState *s, uint64_t addr);
641
642 /**
643 * qtest_memread:
644 * @s: #QTestState instance to operate on.
645 * @addr: Guest address to read from.
646 * @data: Pointer to where memory contents will be stored.
647 * @size: Number of bytes to read.
648 *
649 * Read guest memory into a buffer.
650 */
651 void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
652
653 /**
654 * qtest_rtas_call:
655 * @s: #QTestState instance to operate on.
656 * @name: name of the command to call.
657 * @nargs: Number of args.
658 * @args: Guest address to read args from.
659 * @nret: Number of return value.
660 * @ret: Guest address to write return values to.
661 *
662 * Call an RTAS function
663 */
664 uint64_t qtest_rtas_call(QTestState *s, const char *name,
665 uint32_t nargs, uint64_t args,
666 uint32_t nret, uint64_t ret);
667
668 /**
669 * qtest_csr_call:
670 * @s: #QTestState instance to operate on.
671 * @name: name of the command to call.
672 * @cpu: hart number.
673 * @csr: CSR number.
674 * @val: Value for reading/writing.
675 *
676 * Call an RISC-V CSR read/write function
677 */
678 uint64_t qtest_csr_call(QTestState *s, const char *name,
679 uint64_t cpu, int csr,
680 uint64_t *val);
681
682 /**
683 * qtest_bufread:
684 * @s: #QTestState instance to operate on.
685 * @addr: Guest address to read from.
686 * @data: Pointer to where memory contents will be stored.
687 * @size: Number of bytes to read.
688 *
689 * Read guest memory into a buffer and receive using a base64 encoding.
690 */
691 void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size);
692
693 /**
694 * qtest_memwrite:
695 * @s: #QTestState instance to operate on.
696 * @addr: Guest address to write to.
697 * @data: Pointer to the bytes that will be written to guest memory.
698 * @size: Number of bytes to write.
699 *
700 * Write a buffer to guest memory.
701 */
702 void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
703
704 /**
705 * qtest_bufwrite:
706 * @s: #QTestState instance to operate on.
707 * @addr: Guest address to write to.
708 * @data: Pointer to the bytes that will be written to guest memory.
709 * @size: Number of bytes to write.
710 *
711 * Write a buffer to guest memory and transmit using a base64 encoding.
712 */
713 void qtest_bufwrite(QTestState *s, uint64_t addr,
714 const void *data, size_t size);
715
716 /**
717 * qtest_memset:
718 * @s: #QTestState instance to operate on.
719 * @addr: Guest address to write to.
720 * @patt: Byte pattern to fill the guest memory region with.
721 * @size: Number of bytes to write.
722 *
723 * Write a pattern to guest memory.
724 */
725 void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
726
727 /**
728 * qtest_clock_step_next:
729 * @s: #QTestState instance to operate on.
730 *
731 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
732 *
733 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
734 */
735 int64_t qtest_clock_step_next(QTestState *s);
736
737 /**
738 * qtest_clock_step:
739 * @s: QTestState instance to operate on.
740 * @step: Number of nanoseconds to advance the clock by.
741 *
742 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
743 *
744 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
745 */
746 int64_t qtest_clock_step(QTestState *s, int64_t step);
747
748 /**
749 * qtest_clock_set:
750 * @s: QTestState instance to operate on.
751 * @val: Nanoseconds value to advance the clock to.
752 *
753 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
754 *
755 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
756 */
757 int64_t qtest_clock_set(QTestState *s, int64_t val);
758
759 /**
760 * qtest_big_endian:
761 * @s: QTestState instance to operate on.
762 *
763 * Returns: True if the architecture under test has a big endian configuration.
764 */
765 bool qtest_big_endian(QTestState *s);
766
767 /**
768 * qtest_get_arch:
769 *
770 * Returns: The architecture for the QEMU executable under test.
771 */
772 const char *qtest_get_arch(void);
773
774 /**
775 * qtest_has_accel:
776 * @accel_name: Accelerator name to check for.
777 *
778 * Returns: true if the accelerator is built in.
779 */
780 bool qtest_has_accel(const char *accel_name);
781
782 /**
783 * qtest_add_func:
784 * @str: Test case path.
785 * @fn: Test case function
786 *
787 * Add a GTester testcase with the given name and function.
788 * The path is prefixed with the architecture under test, as
789 * returned by qtest_get_arch().
790 */
791 void qtest_add_func(const char *str, void (*fn)(void));
792
793 /**
794 * qtest_add_data_func:
795 * @str: Test case path.
796 * @data: Test case data
797 * @fn: Test case function
798 *
799 * Add a GTester testcase with the given name, data and function.
800 * The path is prefixed with the architecture under test, as
801 * returned by qtest_get_arch().
802 */
803 void qtest_add_data_func(const char *str, const void *data,
804 void (*fn)(const void *));
805
806 /**
807 * qtest_add_data_func_full:
808 * @str: Test case path.
809 * @data: Test case data
810 * @fn: Test case function
811 * @data_free_func: GDestroyNotify for data
812 *
813 * Add a GTester testcase with the given name, data and function.
814 * The path is prefixed with the architecture under test, as
815 * returned by qtest_get_arch().
816 *
817 * @data is passed to @data_free_func() on test completion.
818 */
819 void qtest_add_data_func_full(const char *str, void *data,
820 void (*fn)(const void *),
821 GDestroyNotify data_free_func);
822
823 /**
824 * qtest_add:
825 * @testpath: Test case path
826 * @Fixture: Fixture type
827 * @tdata: Test case data
828 * @fsetup: Test case setup function
829 * @ftest: Test case function
830 * @fteardown: Test case teardown function
831 *
832 * Add a GTester testcase with the given name, data and functions.
833 * The path is prefixed with the architecture under test, as
834 * returned by qtest_get_arch().
835 */
836 #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \
837 do { \
838 char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \
839 g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \
840 g_free(path); \
841 } while (0)
842
843 /**
844 * qtest_add_abrt_handler:
845 * @fn: Handler function
846 * @data: Argument that is passed to the handler
847 *
848 * Add a handler function that is invoked on SIGABRT. This can be used to
849 * terminate processes and perform other cleanup. The handler can be removed
850 * with qtest_remove_abrt_handler().
851 */
852 void qtest_add_abrt_handler(GHookFunc fn, const void *data);
853
854 /**
855 * qtest_remove_abrt_handler:
856 * @data: Argument previously passed to qtest_add_abrt_handler()
857 *
858 * Remove an abrt handler that was previously added with
859 * qtest_add_abrt_handler().
860 */
861 void qtest_remove_abrt_handler(void *data);
862
863 /**
864 * qtest_vqmp_assert_success_ref:
865 * @qts: QTestState instance to operate on
866 * @fmt: QMP message to send to qemu, formatted like
867 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
868 * supported after '%'.
869 * @args: variable arguments for @fmt
870 *
871 * Sends a QMP message to QEMU, asserts that a 'return' key is present in
872 * the response, and returns the response.
873 */
874 QDict *qtest_vqmp_assert_success_ref(QTestState *qts,
875 const char *fmt, va_list args)
876 G_GNUC_PRINTF(2, 0);
877
878 /**
879 * qtest_vqmp_assert_success:
880 * @qts: QTestState instance to operate on
881 * @fmt: QMP message to send to qemu, formatted like
882 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
883 * supported after '%'.
884 * @args: variable arguments for @fmt
885 *
886 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
887 * the response.
888 */
889 void qtest_vqmp_assert_success(QTestState *qts,
890 const char *fmt, va_list args)
891 G_GNUC_PRINTF(2, 0);
892
893 #ifndef _WIN32
894 /**
895 * qtest_vqmp_fds_assert_success_ref:
896 * @qts: QTestState instance to operate on
897 * @fds: the file descriptors to send
898 * @nfds: number of @fds to send
899 * @fmt: QMP message to send to qemu, formatted like
900 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
901 * supported after '%'.
902 * @args: variable arguments for @fmt
903 *
904 * Sends a QMP message with file descriptors to QEMU,
905 * asserts that a 'return' key is present in the response,
906 * and returns the response.
907 */
908 QDict *qtest_vqmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
909 const char *fmt, va_list args)
910 G_GNUC_PRINTF(4, 0);
911
912 /**
913 * qtest_vqmp_fds_assert_success:
914 * @qts: QTestState instance to operate on
915 * @fds: the file descriptors to send
916 * @nfds: number of @fds to send
917 * @fmt: QMP message to send to qemu, formatted like
918 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
919 * supported after '%'.
920 * @args: variable arguments for @fmt
921 *
922 * Sends a QMP message with file descriptors to QEMU and
923 * asserts that a 'return' key is present in the response.
924 */
925 void qtest_vqmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
926 const char *fmt, va_list args)
927 G_GNUC_PRINTF(4, 0);
928 #endif /* !_WIN32 */
929
930 /**
931 * qtest_qmp_assert_failure_ref:
932 * @qts: QTestState instance to operate on
933 * @fmt: QMP message to send to qemu, formatted like
934 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
935 * supported after '%'.
936 *
937 * Sends a QMP message to QEMU, asserts that an 'error' key is present in
938 * the response, and returns the response.
939 */
940 QDict *qtest_qmp_assert_failure_ref(QTestState *qts, const char *fmt, ...)
941 G_GNUC_PRINTF(2, 3);
942
943 /**
944 * qtest_vqmp_assert_failure_ref:
945 * @qts: QTestState instance to operate on
946 * @fmt: QMP message to send to qemu, formatted like
947 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
948 * supported after '%'.
949 * @args: variable arguments for @fmt
950 *
951 * Sends a QMP message to QEMU, asserts that an 'error' key is present in
952 * the response, and returns the response.
953 */
954 QDict *qtest_vqmp_assert_failure_ref(QTestState *qts,
955 const char *fmt, va_list args)
956 G_GNUC_PRINTF(2, 0);
957
958 /**
959 * qtest_qmp_assert_success_ref:
960 * @qts: QTestState instance to operate on
961 * @fmt: QMP message to send to qemu, formatted like
962 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
963 * supported after '%'.
964 *
965 * Sends a QMP message to QEMU, asserts that a 'return' key is present in
966 * the response, and returns the response.
967 */
968 QDict *qtest_qmp_assert_success_ref(QTestState *qts, const char *fmt, ...)
969 G_GNUC_PRINTF(2, 3);
970
971 /**
972 * qtest_qmp_assert_success:
973 * @qts: QTestState instance to operate on
974 * @fmt: QMP message to send to qemu, formatted like
975 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
976 * supported after '%'.
977 *
978 * Sends a QMP message to QEMU and asserts that a 'return' key is present in
979 * the response.
980 */
981 void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
982 G_GNUC_PRINTF(2, 3);
983
984 #ifndef _WIN32
985 /**
986 * qtest_qmp_fds_assert_success_ref:
987 * @qts: QTestState instance to operate on
988 * @fds: the file descriptors to send
989 * @nfds: number of @fds to send
990 * @fmt: QMP message to send to qemu, formatted like
991 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
992 * supported after '%'.
993 *
994 * Sends a QMP message with file descriptors to QEMU,
995 * asserts that a 'return' key is present in the response,
996 * and returns the response.
997 */
998 QDict *qtest_qmp_fds_assert_success_ref(QTestState *qts, int *fds, size_t nfds,
999 const char *fmt, ...)
1000 G_GNUC_PRINTF(4, 5);
1001
1002 /**
1003 * qtest_qmp_fds_assert_success:
1004 * @qts: QTestState instance to operate on
1005 * @fds: the file descriptors to send
1006 * @nfds: number of @fds to send
1007 * @fmt: QMP message to send to qemu, formatted like
1008 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
1009 * supported after '%'.
1010 *
1011 * Sends a QMP message with file descriptors to QEMU and
1012 * asserts that a 'return' key is present in the response.
1013 */
1014 void qtest_qmp_fds_assert_success(QTestState *qts, int *fds, size_t nfds,
1015 const char *fmt, ...)
1016 G_GNUC_PRINTF(4, 5);
1017 #endif /* !_WIN32 */
1018
1019 /**
1020 * qtest_cb_for_every_machine:
1021 * @cb: Pointer to the callback function
1022 * @skip_old_versioned: true if versioned old machine types should be skipped
1023 *
1024 * Call a callback function for every name of all available machines.
1025 */
1026 void qtest_cb_for_every_machine(void (*cb)(const char *machine),
1027 bool skip_old_versioned);
1028
1029 /**
1030 * qtest_resolve_machine_alias:
1031 * @var: Environment variable from where to take the QEMU binary
1032 * @alias: The alias to resolve
1033 *
1034 * Returns: the machine type corresponding to the alias if any,
1035 * otherwise NULL.
1036 */
1037 char *qtest_resolve_machine_alias(const char *var, const char *alias);
1038
1039 /**
1040 * qtest_has_machine:
1041 * @machine: The machine to look for
1042 *
1043 * Returns: true if the machine is available in the target binary.
1044 */
1045 bool qtest_has_machine(const char *machine);
1046
1047 /**
1048 * qtest_has_machine_with_env:
1049 * @var: Environment variable from where to take the QEMU binary
1050 * @machine: The machine to look for
1051 *
1052 * Returns: true if the machine is available in the specified binary.
1053 */
1054 bool qtest_has_machine_with_env(const char *var, const char *machine);
1055
1056 /**
1057 * qtest_has_cpu_model:
1058 * @cpu: The cpu to look for
1059 *
1060 * Returns: true if the cpu is available in the target binary.
1061 */
1062 bool qtest_has_cpu_model(const char *cpu);
1063
1064 /**
1065 * qtest_has_device:
1066 * @device: The device to look for
1067 *
1068 * Returns: true if the device is available in the target binary.
1069 */
1070 bool qtest_has_device(const char *device);
1071
1072 /**
1073 * qtest_qmp_device_add_qdict:
1074 * @qts: QTestState instance to operate on
1075 * @drv: Name of the device that should be added
1076 * @arguments: QDict with properties for the device to initialize
1077 *
1078 * Generic hot-plugging test via the device_add QMP command with properties
1079 * supplied in form of QDict. Use NULL for empty properties list.
1080 */
1081 void qtest_qmp_device_add_qdict(QTestState *qts, const char *drv,
1082 const QDict *arguments);
1083
1084 /**
1085 * qtest_qmp_device_add:
1086 * @qts: QTestState instance to operate on
1087 * @driver: Name of the device that should be added
1088 * @id: Identification string
1089 * @fmt: QMP message to send to qemu, formatted like
1090 * qobject_from_jsonf_nofail(). See parse_interpolation() for what's
1091 * supported after '%'.
1092 *
1093 * Generic hot-plugging test via the device_add QMP command.
1094 */
1095 void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id,
1096 const char *fmt, ...) G_GNUC_PRINTF(4, 5);
1097
1098 /**
1099 * qtest_qmp_add_client:
1100 * @qts: QTestState instance to operate on
1101 * @protocol: the protocol to add to
1102 * @fd: the client file-descriptor
1103 *
1104 * Call QMP ``getfd`` (on Windows ``get-win32-socket``) followed by
1105 * ``add_client`` with the given @fd.
1106 */
1107 void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
1108
1109 /**
1110 * qtest_qmp_device_del_send:
1111 * @qts: QTestState instance to operate on
1112 * @id: Identification string
1113 *
1114 * Generic hot-unplugging test via the device_del QMP command.
1115 */
1116 void qtest_qmp_device_del_send(QTestState *qts, const char *id);
1117
1118 /**
1119 * qtest_qmp_device_del:
1120 * @qts: QTestState instance to operate on
1121 * @id: Identification string
1122 *
1123 * Generic hot-unplugging test via the device_del QMP command.
1124 * Waiting for command completion event.
1125 */
1126 void qtest_qmp_device_del(QTestState *qts, const char *id);
1127
1128 /**
1129 * qtest_probe_child:
1130 * @s: QTestState instance to operate on.
1131 *
1132 * Returns: true if the child is still alive.
1133 */
1134 bool qtest_probe_child(QTestState *s);
1135
1136 /**
1137 * qtest_set_expected_status:
1138 * @s: QTestState instance to operate on.
1139 * @status: an expected exit status.
1140 *
1141 * Set expected exit status of the child.
1142 */
1143 void qtest_set_expected_status(QTestState *s, int status);
1144
1145 QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch,
1146 void (*send)(void*, const char*));
1147
1148 void qtest_client_inproc_recv(void *opaque, const char *str);
1149
1150 /**
1151 * qtest_qom_set_bool:
1152 * @s: QTestState instance to operate on.
1153 * @path: Path to the property being set.
1154 * @property: Property being set.
1155 * @value: Value to set the property.
1156 *
1157 * Set the property with passed in value.
1158 */
1159 void qtest_qom_set_bool(QTestState *s, const char *path, const char *property,
1160 bool value);
1161
1162 /**
1163 * qtest_qom_get_bool:
1164 * @s: QTestState instance to operate on.
1165 * @path: Path to the property being retrieved.
1166 * @property: Property from where the value is being retrieved.
1167 *
1168 * Returns: Value retrieved from property.
1169 */
1170 bool qtest_qom_get_bool(QTestState *s, const char *path, const char *property);
1171
1172 /**
1173 * qtest_pid:
1174 * @s: QTestState instance to operate on.
1175 *
1176 * Returns: the PID of the QEMU process, or <= 0
1177 */
1178 pid_t qtest_pid(QTestState *s);
1179
1180 /**
1181 * have_qemu_img:
1182 *
1183 * Returns: true if "qemu-img" is available.
1184 */
1185 bool have_qemu_img(void);
1186
1187 /**
1188 * mkimg:
1189 * @file: File name of the image that should be created
1190 * @fmt: Format, e.g. "qcow2" or "raw"
1191 * @size_mb: Size of the image in megabytes
1192 *
1193 * Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG
1194 * environment variable must point to the qemu-img file.
1195 *
1196 * Returns: true if the image has been created successfully.
1197 */
1198 bool mkimg(const char *file, const char *fmt, unsigned size_mb);
1199
1200 /**
1201 * qtest_verbose:
1202 * @domain: The logging domain
1203 *
1204 * Read the QTEST_LOG environment variable and return whether the
1205 * specified domain is enabled for verbose logging. Enable specific
1206 * logging domains with QTEST_LOG=<domain> or use QTEST_LOG=-<domain> to
1207 * enable all domains except for the specific one.
1208 */
1209 bool qtest_verbose(const char *domain);
1210
1211 #endif