blob: e7413d52dcb87813f826bbfa0da1c904cf29a670 [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"
Stefan Hajnoczi89b516d2014-10-15 14:29:30 +020026#include "glib-compat.h"
Anthony Liguori49ee3592012-03-28 15:42:05 +020027
28typedef struct QTestState QTestState;
29
30extern QTestState *global_qtest;
31
32/**
33 * qtest_init:
34 * @extra_args: other arguments to pass to QEMU.
Andreas Färber6acf8012013-02-16 22:44:01 +010035 *
36 * Returns: #QTestState instance.
Anthony Liguori49ee3592012-03-28 15:42:05 +020037 */
38QTestState *qtest_init(const char *extra_args);
39
40/**
41 * qtest_quit:
Andreas Färber6acf8012013-02-16 22:44:01 +010042 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +020043 *
44 * Shut down the QEMU process associated to @s.
45 */
46void qtest_quit(QTestState *s);
47
48/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010049 * qtest_qmp_discard_response:
Andreas Färber6acf8012013-02-16 22:44:01 +010050 * @s: #QTestState instance to operate on.
Kevin Wolfa3ca1632012-04-26 19:07:55 +020051 * @fmt...: QMP message to send to qemu
52 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010053 * Sends a QMP message to QEMU and consumes the response.
Kevin Wolfa3ca1632012-04-26 19:07:55 +020054 */
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010055void qtest_qmp_discard_response(QTestState *s, const char *fmt, ...);
Kevin Wolfa3ca1632012-04-26 19:07:55 +020056
57/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +010058 * qtest_qmp:
59 * @s: #QTestState instance to operate on.
60 * @fmt...: QMP message to send to qemu
61 *
62 * Sends a QMP message to QEMU and returns the response.
63 */
64QDict *qtest_qmp(QTestState *s, const char *fmt, ...);
65
66/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010067 * qtest_qmpv_discard_response:
Andreas Färberb73cf9e2013-02-16 22:44:02 +010068 * @s: #QTestState instance to operate on.
69 * @fmt: QMP message to send to QEMU
70 * @ap: QMP message arguments
71 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010072 * Sends a QMP message to QEMU and consumes the response.
Andreas Färberb73cf9e2013-02-16 22:44:02 +010073 */
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +010074void qtest_qmpv_discard_response(QTestState *s, const char *fmt, va_list ap);
Andreas Färberb73cf9e2013-02-16 22:44:02 +010075
76/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +010077 * qtest_qmpv:
78 * @s: #QTestState instance to operate on.
79 * @fmt: QMP message to send to QEMU
80 * @ap: QMP message arguments
81 *
82 * Sends a QMP message to QEMU and returns the response.
83 */
84QDict *qtest_qmpv(QTestState *s, const char *fmt, va_list ap);
85
86/**
Andreas Färber66e0c7b2014-02-21 20:55:30 +010087 * qtest_receive:
88 * @s: #QTestState instance to operate on.
89 *
90 * Reads a QMP message from QEMU and returns the response.
91 */
92QDict *qtest_qmp_receive(QTestState *s);
93
94/**
Anthony Liguori49ee3592012-03-28 15:42:05 +020095 * qtest_get_irq:
Andreas Färber6acf8012013-02-16 22:44:01 +010096 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +020097 * @num: Interrupt to observe.
98 *
Andreas Färber6acf8012013-02-16 22:44:01 +010099 * Returns: The level of the @num interrupt.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200100 */
101bool qtest_get_irq(QTestState *s, int num);
102
103/**
104 * qtest_irq_intercept_in:
Andreas Färber6acf8012013-02-16 22:44:01 +0100105 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200106 * @string: QOM path of a device.
107 *
108 * Associate qtest irqs with the GPIO-in pins of the device
109 * whose path is specified by @string.
110 */
111void qtest_irq_intercept_in(QTestState *s, const char *string);
112
113/**
114 * qtest_irq_intercept_out:
Andreas Färber6acf8012013-02-16 22:44:01 +0100115 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200116 * @string: QOM path of a device.
117 *
118 * Associate qtest irqs with the GPIO-out pins of the device
119 * whose path is specified by @string.
120 */
121void qtest_irq_intercept_out(QTestState *s, const char *string);
122
123/**
124 * qtest_outb:
Andreas Färber6acf8012013-02-16 22:44:01 +0100125 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200126 * @addr: I/O port to write to.
127 * @value: Value being written.
128 *
129 * Write an 8-bit value to an I/O port.
130 */
131void qtest_outb(QTestState *s, uint16_t addr, uint8_t value);
132
133/**
134 * qtest_outw:
Andreas Färber6acf8012013-02-16 22:44:01 +0100135 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200136 * @addr: I/O port to write to.
137 * @value: Value being written.
138 *
139 * Write a 16-bit value to an I/O port.
140 */
141void qtest_outw(QTestState *s, uint16_t addr, uint16_t value);
142
143/**
144 * qtest_outl:
Andreas Färber6acf8012013-02-16 22:44:01 +0100145 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200146 * @addr: I/O port to write to.
147 * @value: Value being written.
148 *
149 * Write a 32-bit value to an I/O port.
150 */
151void qtest_outl(QTestState *s, uint16_t addr, uint32_t value);
152
153/**
154 * qtest_inb:
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 an 8-bit value from an I/O port.
159 */
160uint8_t qtest_inb(QTestState *s, uint16_t addr);
161
162/**
163 * qtest_inw:
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 16-bit value from an I/O port.
168 */
169uint16_t qtest_inw(QTestState *s, uint16_t addr);
170
171/**
172 * qtest_inl:
Andreas Färber6acf8012013-02-16 22:44:01 +0100173 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200174 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200175 *
176 * Returns a 32-bit value from an I/O port.
177 */
178uint32_t qtest_inl(QTestState *s, uint16_t addr);
179
180/**
Andreas Färber872536b2013-02-16 22:44:03 +0100181 * qtest_writeb:
182 * @s: #QTestState instance to operate on.
183 * @addr: Guest address to write to.
184 * @value: Value being written.
185 *
186 * Writes an 8-bit value to memory.
187 */
188void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value);
189
190/**
191 * qtest_writew:
192 * @s: #QTestState instance to operate on.
193 * @addr: Guest address to write to.
194 * @value: Value being written.
195 *
196 * Writes a 16-bit value to memory.
197 */
198void qtest_writew(QTestState *s, uint64_t addr, uint16_t value);
199
200/**
201 * qtest_writel:
202 * @s: #QTestState instance to operate on.
203 * @addr: Guest address to write to.
204 * @value: Value being written.
205 *
206 * Writes a 32-bit value to memory.
207 */
208void qtest_writel(QTestState *s, uint64_t addr, uint32_t value);
209
210/**
211 * qtest_writeq:
212 * @s: #QTestState instance to operate on.
213 * @addr: Guest address to write to.
214 * @value: Value being written.
215 *
216 * Writes a 64-bit value to memory.
217 */
218void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value);
219
220/**
221 * qtest_readb:
222 * @s: #QTestState instance to operate on.
223 * @addr: Guest address to read from.
224 *
225 * Reads an 8-bit value from memory.
226 *
227 * Returns: Value read.
228 */
229uint8_t qtest_readb(QTestState *s, uint64_t addr);
230
231/**
232 * qtest_readw:
233 * @s: #QTestState instance to operate on.
234 * @addr: Guest address to read from.
235 *
236 * Reads a 16-bit value from memory.
237 *
238 * Returns: Value read.
239 */
240uint16_t qtest_readw(QTestState *s, uint64_t addr);
241
242/**
243 * qtest_readl:
244 * @s: #QTestState instance to operate on.
245 * @addr: Guest address to read from.
246 *
247 * Reads a 32-bit value from memory.
248 *
249 * Returns: Value read.
250 */
251uint32_t qtest_readl(QTestState *s, uint64_t addr);
252
253/**
254 * qtest_readq:
255 * @s: #QTestState instance to operate on.
256 * @addr: Guest address to read from.
257 *
258 * Reads a 64-bit value from memory.
259 *
260 * Returns: Value read.
261 */
262uint64_t qtest_readq(QTestState *s, uint64_t addr);
263
264/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200265 * qtest_memread:
Andreas Färber6acf8012013-02-16 22:44:01 +0100266 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200267 * @addr: Guest address to read from.
268 * @data: Pointer to where memory contents will be stored.
269 * @size: Number of bytes to read.
270 *
271 * Read guest memory into a buffer.
272 */
273void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size);
274
275/**
276 * qtest_memwrite:
Andreas Färber6acf8012013-02-16 22:44:01 +0100277 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200278 * @addr: Guest address to write to.
279 * @data: Pointer to the bytes that will be written to guest memory.
280 * @size: Number of bytes to write.
281 *
282 * Write a buffer to guest memory.
283 */
284void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size);
285
286/**
John Snow86298842014-08-04 17:11:20 -0400287 * qtest_memset:
288 * @s: #QTestState instance to operate on.
289 * @addr: Guest address to write to.
290 * @patt: Byte pattern to fill the guest memory region with.
291 * @size: Number of bytes to write.
292 *
293 * Write a pattern to guest memory.
294 */
295void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size);
296
297/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200298 * qtest_clock_step_next:
Andreas Färber6acf8012013-02-16 22:44:01 +0100299 * @s: #QTestState instance to operate on.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200300 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100301 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
Andreas Färber6acf8012013-02-16 22:44:01 +0100302 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100303 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200304 */
305int64_t qtest_clock_step_next(QTestState *s);
306
307/**
308 * qtest_clock_step:
309 * @s: QTestState instance to operate on.
310 * @step: Number of nanoseconds to advance the clock by.
311 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100312 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
Andreas Färber6acf8012013-02-16 22:44:01 +0100313 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100314 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200315 */
316int64_t qtest_clock_step(QTestState *s, int64_t step);
317
318/**
319 * qtest_clock_set:
320 * @s: QTestState instance to operate on.
321 * @val: Nanoseconds value to advance the clock to.
322 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100323 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
Andreas Färber6acf8012013-02-16 22:44:01 +0100324 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100325 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200326 */
327int64_t qtest_clock_set(QTestState *s, int64_t val);
328
329/**
330 * qtest_get_arch:
331 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100332 * Returns: The architecture for the QEMU executable under test.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200333 */
334const char *qtest_get_arch(void);
335
336/**
337 * qtest_add_func:
338 * @str: Test case path.
339 * @fn: Test case function
340 *
341 * Add a GTester testcase with the given name and function.
342 * The path is prefixed with the architecture under test, as
Andreas Färber6acf8012013-02-16 22:44:01 +0100343 * returned by qtest_get_arch().
Anthony Liguori49ee3592012-03-28 15:42:05 +0200344 */
345void qtest_add_func(const char *str, void (*fn));
346
347/**
348 * qtest_start:
349 * @args: other arguments to pass to QEMU
350 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100351 * Start QEMU and assign the resulting #QTestState to a global variable.
352 * The global variable is used by "shortcut" functions documented below.
353 *
354 * Returns: #QTestState instance.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200355 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100356static inline QTestState *qtest_start(const char *args)
357{
Stefan Hajnoczi96b8ca42014-03-27 15:09:49 +0100358 global_qtest = qtest_init(args);
359 return global_qtest;
Andreas Färber6acf8012013-02-16 22:44:01 +0100360}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200361
362/**
Markus Armbruster1d9358e2013-06-20 08:55:29 +0200363 * qtest_end:
364 *
365 * Shut down the QEMU process started by qtest_start().
366 */
367static inline void qtest_end(void)
368{
369 qtest_quit(global_qtest);
Stefan Hajnoczi96b8ca42014-03-27 15:09:49 +0100370 global_qtest = NULL;
Markus Armbruster1d9358e2013-06-20 08:55:29 +0200371}
372
373/**
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +0100374 * qmp:
375 * @fmt...: QMP message to send to qemu
376 *
377 * Sends a QMP message to QEMU and returns the response.
378 */
Peter Maydell0100f422014-03-13 11:24:15 +0000379QDict *qmp(const char *fmt, ...);
Stefan Hajnoczi0c460da2013-10-30 14:54:33 +0100380
381/**
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100382 * qmp_discard_response:
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200383 * @fmt...: QMP message to send to qemu
384 *
Stefan Hajnoczi0d1aa052013-10-30 14:54:32 +0100385 * Sends a QMP message to QEMU and consumes the response.
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200386 */
Peter Maydell0100f422014-03-13 11:24:15 +0000387void qmp_discard_response(const char *fmt, ...);
Kevin Wolfa3ca1632012-04-26 19:07:55 +0200388
389/**
Andreas Färber66e0c7b2014-02-21 20:55:30 +0100390 * qmp_receive:
391 *
392 * Reads a QMP message from QEMU and returns the response.
393 */
394static inline QDict *qmp_receive(void)
395{
396 return qtest_qmp_receive(global_qtest);
397}
398
399/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200400 * get_irq:
401 * @num: Interrupt to observe.
402 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100403 * Returns: The level of the @num interrupt.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200404 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100405static inline bool get_irq(int num)
406{
407 return qtest_get_irq(global_qtest, num);
408}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200409
410/**
411 * irq_intercept_in:
412 * @string: QOM path of a device.
413 *
414 * Associate qtest irqs with the GPIO-in pins of the device
415 * whose path is specified by @string.
416 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100417static inline void irq_intercept_in(const char *string)
418{
419 qtest_irq_intercept_in(global_qtest, string);
420}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200421
422/**
423 * qtest_irq_intercept_out:
424 * @string: QOM path of a device.
425 *
426 * Associate qtest irqs with the GPIO-out pins of the device
427 * whose path is specified by @string.
428 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100429static inline void irq_intercept_out(const char *string)
430{
431 qtest_irq_intercept_out(global_qtest, string);
432}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200433
434/**
435 * outb:
436 * @addr: I/O port to write to.
437 * @value: Value being written.
438 *
439 * Write an 8-bit value to an I/O port.
440 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100441static inline void outb(uint16_t addr, uint8_t value)
442{
443 qtest_outb(global_qtest, addr, value);
444}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200445
446/**
447 * outw:
448 * @addr: I/O port to write to.
449 * @value: Value being written.
450 *
451 * Write a 16-bit value to an I/O port.
452 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100453static inline void outw(uint16_t addr, uint16_t value)
454{
455 qtest_outw(global_qtest, addr, value);
456}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200457
458/**
459 * outl:
460 * @addr: I/O port to write to.
461 * @value: Value being written.
462 *
463 * Write a 32-bit value to an I/O port.
464 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100465static inline void outl(uint16_t addr, uint32_t value)
466{
467 qtest_outl(global_qtest, addr, value);
468}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200469
470/**
471 * inb:
472 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200473 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100474 * Reads an 8-bit value from an I/O port.
475 *
476 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200477 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100478static inline uint8_t inb(uint16_t addr)
479{
480 return qtest_inb(global_qtest, addr);
481}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200482
483/**
484 * inw:
485 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200486 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100487 * Reads a 16-bit value from an I/O port.
488 *
489 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200490 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100491static inline uint16_t inw(uint16_t addr)
492{
493 return qtest_inw(global_qtest, addr);
494}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200495
496/**
497 * inl:
498 * @addr: I/O port to read from.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200499 *
Andreas Färber6acf8012013-02-16 22:44:01 +0100500 * Reads a 32-bit value from an I/O port.
501 *
502 * Returns: Value read.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200503 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100504static inline uint32_t inl(uint16_t addr)
505{
506 return qtest_inl(global_qtest, addr);
507}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200508
509/**
Andreas Färber872536b2013-02-16 22:44:03 +0100510 * writeb:
511 * @addr: Guest address to write to.
512 * @value: Value being written.
513 *
514 * Writes an 8-bit value to guest memory.
515 */
516static inline void writeb(uint64_t addr, uint8_t value)
517{
518 qtest_writeb(global_qtest, addr, value);
519}
520
521/**
522 * writew:
523 * @addr: Guest address to write to.
524 * @value: Value being written.
525 *
526 * Writes a 16-bit value to guest memory.
527 */
528static inline void writew(uint64_t addr, uint16_t value)
529{
530 qtest_writew(global_qtest, addr, value);
531}
532
533/**
534 * writel:
535 * @addr: Guest address to write to.
536 * @value: Value being written.
537 *
538 * Writes a 32-bit value to guest memory.
539 */
540static inline void writel(uint64_t addr, uint32_t value)
541{
542 qtest_writel(global_qtest, addr, value);
543}
544
545/**
546 * writeq:
547 * @addr: Guest address to write to.
548 * @value: Value being written.
549 *
550 * Writes a 64-bit value to guest memory.
551 */
552static inline void writeq(uint64_t addr, uint64_t value)
553{
554 qtest_writeq(global_qtest, addr, value);
555}
556
557/**
558 * readb:
559 * @addr: Guest address to read from.
560 *
561 * Reads an 8-bit value from guest memory.
562 *
563 * Returns: Value read.
564 */
565static inline uint8_t readb(uint64_t addr)
566{
567 return qtest_readb(global_qtest, addr);
568}
569
570/**
571 * readw:
572 * @addr: Guest address to read from.
573 *
574 * Reads a 16-bit value from guest memory.
575 *
576 * Returns: Value read.
577 */
578static inline uint16_t readw(uint64_t addr)
579{
580 return qtest_readw(global_qtest, addr);
581}
582
583/**
584 * readl:
585 * @addr: Guest address to read from.
586 *
587 * Reads a 32-bit value from guest memory.
588 *
589 * Returns: Value read.
590 */
591static inline uint32_t readl(uint64_t addr)
592{
593 return qtest_readl(global_qtest, addr);
594}
595
596/**
597 * readq:
598 * @addr: Guest address to read from.
599 *
600 * Reads a 64-bit value from guest memory.
601 *
602 * Returns: Value read.
603 */
604static inline uint64_t readq(uint64_t addr)
605{
606 return qtest_readq(global_qtest, addr);
607}
608
609/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200610 * memread:
611 * @addr: Guest address to read from.
612 * @data: Pointer to where memory contents will be stored.
613 * @size: Number of bytes to read.
614 *
615 * Read guest memory into a buffer.
616 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100617static inline void memread(uint64_t addr, void *data, size_t size)
618{
619 qtest_memread(global_qtest, addr, data, size);
620}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200621
622/**
623 * memwrite:
624 * @addr: Guest address to write to.
625 * @data: Pointer to the bytes that will be written to guest memory.
626 * @size: Number of bytes to write.
627 *
628 * Write a buffer to guest memory.
629 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100630static inline void memwrite(uint64_t addr, const void *data, size_t size)
631{
632 qtest_memwrite(global_qtest, addr, data, size);
633}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200634
635/**
John Snow86298842014-08-04 17:11:20 -0400636 * qmemset:
637 * @addr: Guest address to write to.
638 * @patt: Byte pattern to fill the guest memory region with.
639 * @size: Number of bytes to write.
640 *
641 * Write a pattern to guest memory.
642 */
643static inline void qmemset(uint64_t addr, uint8_t patt, size_t size)
644{
645 qtest_memset(global_qtest, addr, patt, size);
646}
647
648/**
Anthony Liguori49ee3592012-03-28 15:42:05 +0200649 * clock_step_next:
650 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100651 * Advance the QEMU_CLOCK_VIRTUAL to the next deadline.
Andreas Färber6acf8012013-02-16 22:44:01 +0100652 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100653 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200654 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100655static inline int64_t clock_step_next(void)
656{
657 return qtest_clock_step_next(global_qtest);
658}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200659
660/**
661 * clock_step:
662 * @step: Number of nanoseconds to advance the clock by.
663 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100664 * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds.
Andreas Färber6acf8012013-02-16 22:44:01 +0100665 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100666 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200667 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100668static inline int64_t clock_step(int64_t step)
669{
670 return qtest_clock_step(global_qtest, step);
671}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200672
673/**
674 * clock_set:
675 * @val: Nanoseconds value to advance the clock to.
676 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100677 * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched.
Andreas Färber6acf8012013-02-16 22:44:01 +0100678 *
Alex Blighbc72ad62013-08-21 16:03:08 +0100679 * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds.
Anthony Liguori49ee3592012-03-28 15:42:05 +0200680 */
Andreas Färber6acf8012013-02-16 22:44:01 +0100681static inline int64_t clock_set(int64_t val)
682{
683 return qtest_clock_set(global_qtest, val);
684}
Anthony Liguori49ee3592012-03-28 15:42:05 +0200685
Marc Marí46e0cf72014-09-01 12:07:55 +0200686/**
687 * qtest_big_endian:
688 *
689 * Returns: True if the architecture under test has a big endian configuration.
690 */
691bool qtest_big_endian(void);
692
Anthony Liguori49ee3592012-03-28 15:42:05 +0200693#endif