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