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