blob: 9deebdcdfa4068e4f2cc4d3286c036aba3e29088 [file] [log] [blame]
Anthony Liguori49ee3592012-03-28 15:42:05 +02001/*
2 * QTest
3 *
4 * Copyright IBM, Corp. 2012
5 * Copyright Red Hat, Inc. 2012
Andreas Färber872536b2013-02-16 22:44:03 +01006 * Copyright SUSE LINUX Products GmbH 2013
Anthony Liguori49ee3592012-03-28 15:42:05 +02007 *
8 * Authors:
9 * Anthony Liguori <aliguori@us.ibm.com>
10 * Paolo Bonzini <pbonzini@redhat.com>
Andreas Färber872536b2013-02-16 22:44:03 +010011 * Andreas Färber <afaerber@suse.de>
Anthony Liguori49ee3592012-03-28 15:42:05 +020012 *
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
Markus Armbruster1d9358e2013-06-20 08:55:29 +020020#include <stddef.h>
Anthony Liguori49ee3592012-03-28 15:42:05 +020021#include <stdint.h>
22#include <stdbool.h>
Andreas Färberb73cf9e2013-02-16 22:44:02 +010023#include <stdarg.h>
Anthony Liguori49ee3592012-03-28 15:42:05 +020024#include <sys/types.h>
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +010025#include "qapi/qmp/qdict.h"
Anthony Liguori49ee3592012-03-28 15:42:05 +020026
27typedef struct QTestState QTestState;
28
29extern QTestState *global_qtest;
30
31/**
32 * qtest_init:
33 * @extra_args: other arguments to pass to QEMU.
Andreas Färber6acf8012013-02-16 22:44:01 +010034 *
35 * Returns: #QTestState instance.
Anthony Liguori49ee3592012-03-28 15:42:05 +020036 */
37QTestState *qtest_init(const char *extra_args);
38
39/**
40 * qtest_quit:
Andreas Färber6acf8012013-02-16 22:44:01 +010041 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +020042 *
43 * Shut down the QEMU process associated to @s.
44 */
45void qtest_quit(QTestState *s);
46
47/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010048 * qtest_qmp_discard_response:
Andreas Färber6acf8012013-02-16 22:44:01 +010049 * @s: #QTestState instance to operate on.
Kevin Wolfa3ca1632012-04-26 19:07:55 +020050 * @fmt...: QMP message to send to qemu
51 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010052 * Sends a QMP message to QEMU and consumes the response.
Kevin Wolfa3ca1632012-04-26 19:07:55 +020053 */
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010054void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...);
Kevin Wolfa3ca1632012-04-26 19:07:55 +020055
56/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +010057 * qtest_qmp:
58 * @s: #QTestState instance to operate on.
59 * @fmt...: QMP message to send to qemu
60 *
61 * Sends a QMP message to QEMU and returns the response.
62 */
63QDict *qtest_qmp(QTestState *s, const char *fmt, ...);
64
65/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010066 * qtest_qmpv_discard_response:
Andreas Färberb73cf9e2013-02-16 22:44:02 +010067 * @s: #QTestState instance to operate on.
68 * @fmt: QMP message to send to QEMU
69 * @ap: QMP message arguments
70 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010071 * Sends a QMP message to QEMU and consumes the response.
Andreas Färberb73cf9e2013-02-16 22:44:02 +010072 */
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010073void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap);
Andreas Färberb73cf9e2013-02-16 22:44:02 +010074
75/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +010076 * qtest_qmpv:
77 * @s: #QTestState instance to operate on.
78 * @fmt: QMP message to send to QEMU
79 * @ap: QMP message arguments
80 *
81 * Sends a QMP message to QEMU and returns the response.
82 */
83QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
84
85/**
Anthony Liguori49ee3592012-03-28 15:42:05 +020086 * qtest_get_irq:
Andreas Färber6acf8012013-02-16 22:44:01 +010087 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +020088 * @num: Interrupt to observe.
89 *
Andreas Färber6acf8012013-02-16 22:44:01 +010090 * Returns: The level of the @num interrupt.
Anthony Liguori49ee3592012-03-28 15:42:05 +020091 */
92bool qtest_get_irq(QTestState *s, int num);
93
94/**
95 * qtest_irq_intercept_in:
Andreas Färber6acf8012013-02-16 22:44:01 +010096 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +020097 * @string: QOM path of a device.
98 *
99 * Associate qtest irqs with the GPIO-in pins of the device
100 * whose path is specified by @string.
101 */
102void qtest_irq_intercept_in(QTestState *s, const char *string);
103
104/**
105 * qtest_irq_intercept_out:
Andreas Färber6acf8012013-02-16 22:44:01 +0100106 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200107 * @string: QOM path of a device.
108 *
109 * Associate qtest irqs with the GPIO-out pins of the device
110 * whose path is specified by @string.
111 */
112void qtest_irq_intercept_out(QTestState *s, const char *string);
113
114/**
115 * qtest_outb:
Andreas Färber6acf8012013-02-16 22:44:01 +0100116 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200117 * @addr: I/O port to write to.
118 * @value: Value being written.
119 *
120 * Write an 8-bit value to an I/O port.
121 */
122void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
123
124/**
125 * qtest_outw:
Andreas Färber6acf8012013-02-16 22:44:01 +0100126 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200127 * @addr: I/O port to write to.
128 * @value: Value being written.
129 *
130 * Write a 16-bit value to an I/O port.
131 */
132void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
133
134/**
135 * qtest_outl:
Andreas Färber6acf8012013-02-16 22:44:01 +0100136 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200137 * @addr: I/O port to write to.
138 * @value: Value being written.
139 *
140 * Write a 32-bit value to an I/O port.
141 */
142void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
143
144/**
145 * qtest_inb:
Andreas Färber6acf8012013-02-16 22:44:01 +0100146 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200147 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200148 *
149 * Returns an 8-bit value from an I/O port.
150 */
151uint8_t qtest_inb(QTestState *s, uint16_t addr);
152
153/**
154 * qtest_inw:
Andreas Färber6acf8012013-02-16 22:44:01 +0100155 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200156 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200157 *
158 * Returns a 16-bit value from an I/O port.
159 */
160uint16_t qtest_inw(QTestState *s, uint16_t addr);
161
162/**
163 * qtest_inl:
Andreas Färber6acf8012013-02-16 22:44:01 +0100164 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200165 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200166 *
167 * Returns a 32-bit value from an I/O port.
168 */
169uint32_t qtest_inl(QTestState *s, uint16_t addr);
170
171/**
Andreas Färber872536b2013-02-16 22:44:03 +0100172 * qtest_writeb:
173 * @s: #QTestState instance to operate on.
174 * @addr: Guest address to write to.
175 * @value: Value being written.
176 *
177 * Writes an 8-bit value to memory.
178 */
179void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
180
181/**
182 * qtest_writew:
183 * @s: #QTestState instance to operate on.
184 * @addr: Guest address to write to.
185 * @value: Value being written.
186 *
187 * Writes a 16-bit value to memory.
188 */
189void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
190
191/**
192 * qtest_writel:
193 * @s: #QTestState instance to operate on.
194 * @addr: Guest address to write to.
195 * @value: Value being written.
196 *
197 * Writes a 32-bit value to memory.
198 */
199void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
200
201/**
202 * qtest_writeq:
203 * @s: #QTestState instance to operate on.
204 * @addr: Guest address to write to.
205 * @value: Value being written.
206 *
207 * Writes a 64-bit value to memory.
208 */
209void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
210
211/**
212 * qtest_readb:
213 * @s: #QTestState instance to operate on.
214 * @addr: Guest address to read from.
215 *
216 * Reads an 8-bit value from memory.
217 *
218 * Returns: Value read.
219 */
220uint8_t qtest_readb(QTestState *s, uint64_t addr);
221
222/**
223 * qtest_readw:
224 * @s: #QTestState instance to operate on.
225 * @addr: Guest address to read from.
226 *
227 * Reads a 16-bit value from memory.
228 *
229 * Returns: Value read.
230 */
231uint16_t qtest_readw(QTestState *s, uint64_t addr);
232
233/**
234 * qtest_readl:
235 * @s: #QTestState instance to operate on.
236 * @addr: Guest address to read from.
237 *
238 * Reads a 32-bit value from memory.
239 *
240 * Returns: Value read.
241 */
242uint32_t qtest_readl(QTestState *s, uint64_t addr);
243
244/**
245 * qtest_readq:
246 * @s: #QTestState instance to operate on.
247 * @addr: Guest address to read from.
248 *
249 * Reads a 64-bit value from memory.
250 *
251 * Returns: Value read.
252 */
253uint64_t qtest_readq(QTestState *s, uint64_t addr);
254
255/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200256 * qtest_memread:
Andreas Färber6acf8012013-02-16 22:44:01 +0100257 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200258 * @addr: Guest address to read from.
259 * @data: Pointer to where memory contents will be stored.
260 * @size: Number of bytes to read.
261 *
262 * Read guest memory into a buffer.
263 */
264void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
265
266/**
267 * qtest_memwrite:
Andreas Färber6acf8012013-02-16 22:44:01 +0100268 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200269 * @addr: Guest address to write to.
270 * @data: Pointer to the bytes that will be written to guest memory.
271 * @size: Number of bytes to write.
272 *
273 * Write a buffer to guest memory.
274 */
275void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
276
277/**
278 * qtest_clock_step_next:
Andreas Färber6acf8012013-02-16 22:44:01 +0100279 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200280 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100281 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
Andreas Färber6acf8012013-02-16 22:44:01 +0100282 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100283 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200284 */
285int64_t qtest_clock_step_next(QTestState *s);
286
287/**
288 * qtest_clock_step:
289 * @s: QTestState instance to operate on.
290 * @step: Number of nanoseconds to advance the clock by.
291 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100292 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
Andreas Färber6acf8012013-02-16 22:44:01 +0100293 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100294 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200295 */
296int64_t qtest_clock_step(QTestState *s, int64_t step);
297
298/**
299 * qtest_clock_set:
300 * @s: QTestState instance to operate on.
301 * @val: Nanoseconds value to advance the clock to.
302 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100303 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
Andreas Färber6acf8012013-02-16 22:44:01 +0100304 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100305 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200306 */
307int64_t qtest_clock_set(QTestState *s, int64_t val);
308
309/**
310 * qtest_get_arch:
311 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100312 * Returns: The architecture for the QEMU executable under test.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200313 */
314const char *qtest_get_arch(void);
315
316/**
317 * qtest_add_func:
318 * @str: Test case path.
319 * @fn: Test case function
320 *
321 * Add a GTester testcase with the given name and function.
322 * The path is prefixed with the architecture under test, as
Andreas Färber6acf8012013-02-16 22:44:01 +0100323 * returned by qtest_get_arch().
Anthony Liguori49ee3592012-03-28 15:42:05 +0200324 */
325void qtest_add_func(const char *str, void (*fn));
326
327/**
328 * qtest_start:
329 * @args: other arguments to pass to QEMU
330 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100331 * Start QEMU and assign the resulting #QTestState to a global variable.
332 * The global variable is used by "shortcut" functions documented below.
333 *
334 * Returns: #QTestState instance.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200335 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100336static inline QTestState *qtest_start(const char *args)
337{
338 global_qtest = qtest_init(args);
339 return global_qtest;
340}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200341
342/**
Markus Armbruster1d9358e2013-06-20 08:55:29 +0200343 * qtest_end:
344 *
345 * Shut down the QEMU process started by qtest_start().
346 */
347static inline void qtest_end(void)
348{
349 qtest_quit(global_qtest);
350 global_qtest = NULL;
351}
352
353/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +0100354 * qmp:
355 * @fmt...: QMP message to send to qemu
356 *
357 * Sends a QMP message to QEMU and returns the response.
358 */
359static inline QDict *qmp(const char *fmt, ...)
360{
361 va_list ap;
362 QDict *response;
363
364 va_start(ap, fmt);
365 response = qtest_qmpv(global_qtest, fmt, ap);
366 va_end(ap);
367 return response;
368}
369
370/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100371 * qmp_discard_response:
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200372 * @fmt...: QMP message to send to qemu
373 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100374 * Sends a QMP message to QEMU and consumes the response.
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200375 */
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100376static inline void qmp_discard_response(const char *fmt, ...)
Andreas Färberb73cf9e2013-02-16 22:44:02 +0100377{
378 va_list ap;
379
380 va_start(ap, fmt);
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100381 qtest_qmpv_discard_response(global_qtest, fmt, ap);
Andreas Färberb73cf9e2013-02-16 22:44:02 +0100382 va_end(ap);
383}
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200384
385/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200386 * get_irq:
387 * @num: Interrupt to observe.
388 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100389 * Returns: The level of the @num interrupt.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200390 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100391static inline bool get_irq(int num)
392{
393 return qtest_get_irq(global_qtest, num);
394}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200395
396/**
397 * irq_intercept_in:
398 * @string: QOM path of a device.
399 *
400 * Associate qtest irqs with the GPIO-in pins of the device
401 * whose path is specified by @string.
402 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100403static inline void irq_intercept_in(const char *string)
404{
405 qtest_irq_intercept_in(global_qtest, string);
406}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200407
408/**
409 * qtest_irq_intercept_out:
410 * @string: QOM path of a device.
411 *
412 * Associate qtest irqs with the GPIO-out pins of the device
413 * whose path is specified by @string.
414 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100415static inline void irq_intercept_out(const char *string)
416{
417 qtest_irq_intercept_out(global_qtest, string);
418}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200419
420/**
421 * outb:
422 * @addr: I/O port to write to.
423 * @value: Value being written.
424 *
425 * Write an 8-bit value to an I/O port.
426 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100427static inline void outb(uint16_t addr, uint8_t value)
428{
429 qtest_outb(global_qtest, addr, value);
430}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200431
432/**
433 * outw:
434 * @addr: I/O port to write to.
435 * @value: Value being written.
436 *
437 * Write a 16-bit value to an I/O port.
438 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100439static inline void outw(uint16_t addr, uint16_t value)
440{
441 qtest_outw(global_qtest, addr, value);
442}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200443
444/**
445 * outl:
446 * @addr: I/O port to write to.
447 * @value: Value being written.
448 *
449 * Write a 32-bit value to an I/O port.
450 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100451static inline void outl(uint16_t addr, uint32_t value)
452{
453 qtest_outl(global_qtest, addr, value);
454}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200455
456/**
457 * inb:
458 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200459 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100460 * Reads an 8-bit value from an I/O port.
461 *
462 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200463 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100464static inline uint8_t inb(uint16_t addr)
465{
466 return qtest_inb(global_qtest, addr);
467}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200468
469/**
470 * inw:
471 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200472 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100473 * Reads a 16-bit value from an I/O port.
474 *
475 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200476 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100477static inline uint16_t inw(uint16_t addr)
478{
479 return qtest_inw(global_qtest, addr);
480}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200481
482/**
483 * inl:
484 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200485 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100486 * Reads a 32-bit value from an I/O port.
487 *
488 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200489 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100490static inline uint32_t inl(uint16_t addr)
491{
492 return qtest_inl(global_qtest, addr);
493}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200494
495/**
Andreas Färber872536b2013-02-16 22:44:03 +0100496 * writeb:
497 * @addr: Guest address to write to.
498 * @value: Value being written.
499 *
500 * Writes an 8-bit value to guest memory.
501 */
502static inline void writeb(uint64_t addr, uint8_t value)
503{
504 qtest_writeb(global_qtest, addr, value);
505}
506
507/**
508 * writew:
509 * @addr: Guest address to write to.
510 * @value: Value being written.
511 *
512 * Writes a 16-bit value to guest memory.
513 */
514static inline void writew(uint64_t addr, uint16_t value)
515{
516 qtest_writew(global_qtest, addr, value);
517}
518
519/**
520 * writel:
521 * @addr: Guest address to write to.
522 * @value: Value being written.
523 *
524 * Writes a 32-bit value to guest memory.
525 */
526static inline void writel(uint64_t addr, uint32_t value)
527{
528 qtest_writel(global_qtest, addr, value);
529}
530
531/**
532 * writeq:
533 * @addr: Guest address to write to.
534 * @value: Value being written.
535 *
536 * Writes a 64-bit value to guest memory.
537 */
538static inline void writeq(uint64_t addr, uint64_t value)
539{
540 qtest_writeq(global_qtest, addr, value);
541}
542
543/**
544 * readb:
545 * @addr: Guest address to read from.
546 *
547 * Reads an 8-bit value from guest memory.
548 *
549 * Returns: Value read.
550 */
551static inline uint8_t readb(uint64_t addr)
552{
553 return qtest_readb(global_qtest, addr);
554}
555
556/**
557 * readw:
558 * @addr: Guest address to read from.
559 *
560 * Reads a 16-bit value from guest memory.
561 *
562 * Returns: Value read.
563 */
564static inline uint16_t readw(uint64_t addr)
565{
566 return qtest_readw(global_qtest, addr);
567}
568
569/**
570 * readl:
571 * @addr: Guest address to read from.
572 *
573 * Reads a 32-bit value from guest memory.
574 *
575 * Returns: Value read.
576 */
577static inline uint32_t readl(uint64_t addr)
578{
579 return qtest_readl(global_qtest, addr);
580}
581
582/**
583 * readq:
584 * @addr: Guest address to read from.
585 *
586 * Reads a 64-bit value from guest memory.
587 *
588 * Returns: Value read.
589 */
590static inline uint64_t readq(uint64_t addr)
591{
592 return qtest_readq(global_qtest, addr);
593}
594
595/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200596 * memread:
597 * @addr: Guest address to read from.
598 * @data: Pointer to where memory contents will be stored.
599 * @size: Number of bytes to read.
600 *
601 * Read guest memory into a buffer.
602 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100603static inline void memread(uint64_t addr, void *data, size_t size)
604{
605 qtest_memread(global_qtest, addr, data, size);
606}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200607
608/**
609 * memwrite:
610 * @addr: Guest address to write to.
611 * @data: Pointer to the bytes that will be written to guest memory.
612 * @size: Number of bytes to write.
613 *
614 * Write a buffer to guest memory.
615 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100616static inline void memwrite(uint64_t addr, const void *data, size_t size)
617{
618 qtest_memwrite(global_qtest, addr, data, size);
619}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200620
621/**
622 * clock_step_next:
623 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100624 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
Andreas Färber6acf8012013-02-16 22:44:01 +0100625 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100626 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200627 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100628static inline int64_t clock_step_next(void)
629{
630 return qtest_clock_step_next(global_qtest);
631}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200632
633/**
634 * clock_step:
635 * @step: Number of nanoseconds to advance the clock by.
636 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100637 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
Andreas Färber6acf8012013-02-16 22:44:01 +0100638 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100639 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200640 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100641static inline int64_t clock_step(int64_t step)
642{
643 return qtest_clock_step(global_qtest, step);
644}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200645
646/**
647 * clock_set:
648 * @val: Nanoseconds value to advance the clock to.
649 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100650 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
Andreas Färber6acf8012013-02-16 22:44:01 +0100651 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100652 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200653 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100654static inline int64_t clock_set(int64_t val)
655{
656 return qtest_clock_set(global_qtest, val);
657}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200658
659#endif