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