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