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