]>
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 <aliguori@us.ibm.com> | |
10 | * Paolo Bonzini <pbonzini@redhat.com> | |
872536bf | 11 | * Andreas Färber <afaerber@suse.de> |
49ee3590 AL |
12 | * |
13 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
14 | * See the COPYING file in the top-level directory. | |
15 | * | |
16 | */ | |
17 | #ifndef LIBQTEST_H | |
18 | #define LIBQTEST_H | |
19 | ||
0c460dac | 20 | #include "qapi/qmp/qdict.h" |
49ee3590 AL |
21 | |
22 | typedef struct QTestState QTestState; | |
23 | ||
24 | extern 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 | */ |
32 | QTestState *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 | */ | |
40 | void 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 | 49 | void 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 | */ | |
58 | QDict *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 | */ | |
67 | void 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 | 77 | void 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 | */ | |
87 | QDict *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 | */ | |
97 | void 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 | */ | |
105 | QDict *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 | */ | |
114 | void 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 | */ | |
125 | char *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 | */ | |
137 | char *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 | */ |
146 | bool 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 | */ | |
156 | void 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 | */ | |
166 | void 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 | */ | |
176 | void 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 | */ | |
186 | void 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 | */ | |
196 | void 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 | */ | |
205 | uint8_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 | */ | |
214 | uint16_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 | */ | |
223 | uint32_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 | */ | |
233 | void 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 | */ | |
243 | void 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 | */ | |
253 | void 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 | */ | |
263 | void 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 | */ | |
274 | uint8_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 | */ | |
285 | uint16_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 | */ | |
296 | uint32_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 | */ | |
307 | uint64_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 | */ | |
318 | void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); | |
319 | ||
7a6a740d JS |
320 | /** |
321 | * qtest_bufread: | |
322 | * @s: #QTestState instance to operate on. | |
323 | * @addr: Guest address to read from. | |
324 | * @data: Pointer to where memory contents will be stored. | |
325 | * @size: Number of bytes to read. | |
326 | * | |
327 | * Read guest memory into a buffer and receive using a base64 encoding. | |
328 | */ | |
329 | void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size); | |
330 | ||
49ee3590 AL |
331 | /** |
332 | * qtest_memwrite: | |
6acf801d | 333 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
334 | * @addr: Guest address to write to. |
335 | * @data: Pointer to the bytes that will be written to guest memory. | |
336 | * @size: Number of bytes to write. | |
337 | * | |
338 | * Write a buffer to guest memory. | |
339 | */ | |
340 | void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size); | |
341 | ||
7a6a740d JS |
342 | /** |
343 | * qtest_bufwrite: | |
344 | * @s: #QTestState instance to operate on. | |
345 | * @addr: Guest address to write to. | |
346 | * @data: Pointer to the bytes that will be written to guest memory. | |
347 | * @size: Number of bytes to write. | |
348 | * | |
349 | * Write a buffer to guest memory and transmit using a base64 encoding. | |
350 | */ | |
351 | void qtest_bufwrite(QTestState *s, uint64_t addr, | |
352 | const void *data, size_t size); | |
353 | ||
86298845 JS |
354 | /** |
355 | * qtest_memset: | |
356 | * @s: #QTestState instance to operate on. | |
357 | * @addr: Guest address to write to. | |
358 | * @patt: Byte pattern to fill the guest memory region with. | |
359 | * @size: Number of bytes to write. | |
360 | * | |
361 | * Write a pattern to guest memory. | |
362 | */ | |
363 | void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size); | |
364 | ||
49ee3590 AL |
365 | /** |
366 | * qtest_clock_step_next: | |
6acf801d AF |
367 | * @s: #QTestState instance to operate on. |
368 | * | |
bc72ad67 | 369 | * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. |
49ee3590 | 370 | * |
bc72ad67 | 371 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
372 | */ |
373 | int64_t qtest_clock_step_next(QTestState *s); | |
374 | ||
375 | /** | |
376 | * qtest_clock_step: | |
377 | * @s: QTestState instance to operate on. | |
378 | * @step: Number of nanoseconds to advance the clock by. | |
379 | * | |
bc72ad67 | 380 | * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. |
6acf801d | 381 | * |
bc72ad67 | 382 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
383 | */ |
384 | int64_t qtest_clock_step(QTestState *s, int64_t step); | |
385 | ||
386 | /** | |
387 | * qtest_clock_set: | |
388 | * @s: QTestState instance to operate on. | |
389 | * @val: Nanoseconds value to advance the clock to. | |
390 | * | |
bc72ad67 | 391 | * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched. |
6acf801d | 392 | * |
bc72ad67 | 393 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
394 | */ |
395 | int64_t qtest_clock_set(QTestState *s, int64_t val); | |
396 | ||
397 | /** | |
398 | * qtest_get_arch: | |
399 | * | |
6acf801d | 400 | * Returns: The architecture for the QEMU executable under test. |
49ee3590 AL |
401 | */ |
402 | const char *qtest_get_arch(void); | |
403 | ||
404 | /** | |
405 | * qtest_add_func: | |
406 | * @str: Test case path. | |
407 | * @fn: Test case function | |
408 | * | |
409 | * Add a GTester testcase with the given name and function. | |
410 | * The path is prefixed with the architecture under test, as | |
6acf801d | 411 | * returned by qtest_get_arch(). |
49ee3590 | 412 | */ |
041088c7 | 413 | void qtest_add_func(const char *str, void (*fn)(void)); |
49ee3590 | 414 | |
7949c0e3 AF |
415 | /** |
416 | * qtest_add_data_func: | |
417 | * @str: Test case path. | |
418 | * @data: Test case data | |
419 | * @fn: Test case function | |
420 | * | |
421 | * Add a GTester testcase with the given name, data and function. | |
422 | * The path is prefixed with the architecture under test, as | |
423 | * returned by qtest_get_arch(). | |
424 | */ | |
041088c7 MA |
425 | void qtest_add_data_func(const char *str, const void *data, |
426 | void (*fn)(const void *)); | |
7949c0e3 | 427 | |
822e36ca MAL |
428 | /** |
429 | * qtest_add_data_func_full: | |
430 | * @str: Test case path. | |
431 | * @data: Test case data | |
432 | * @fn: Test case function | |
433 | * @data_free_func: GDestroyNotify for data | |
434 | * | |
435 | * Add a GTester testcase with the given name, data and function. | |
436 | * The path is prefixed with the architecture under test, as | |
437 | * returned by qtest_get_arch(). | |
438 | * | |
439 | * @data is passed to @data_free_func() on test completion. | |
440 | */ | |
441 | void qtest_add_data_func_full(const char *str, void *data, | |
442 | void (*fn)(const void *), | |
443 | GDestroyNotify data_free_func); | |
444 | ||
45b0f830 AF |
445 | /** |
446 | * qtest_add: | |
447 | * @testpath: Test case path | |
448 | * @Fixture: Fixture type | |
449 | * @tdata: Test case data | |
450 | * @fsetup: Test case setup function | |
451 | * @ftest: Test case function | |
452 | * @fteardown: Test case teardown function | |
453 | * | |
454 | * Add a GTester testcase with the given name, data and functions. | |
455 | * The path is prefixed with the architecture under test, as | |
456 | * returned by qtest_get_arch(). | |
457 | */ | |
458 | #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \ | |
459 | do { \ | |
460 | char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \ | |
461 | g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \ | |
462 | g_free(path); \ | |
463 | } while (0) | |
464 | ||
041088c7 | 465 | void qtest_add_abrt_handler(GHookFunc fn, const void *data); |
063c23d9 | 466 | |
49ee3590 AL |
467 | /** |
468 | * qtest_start: | |
469 | * @args: other arguments to pass to QEMU | |
470 | * | |
6acf801d AF |
471 | * Start QEMU and assign the resulting #QTestState to a global variable. |
472 | * The global variable is used by "shortcut" functions documented below. | |
473 | * | |
474 | * Returns: #QTestState instance. | |
49ee3590 | 475 | */ |
6acf801d AF |
476 | static inline QTestState *qtest_start(const char *args) |
477 | { | |
96b8ca47 SH |
478 | global_qtest = qtest_init(args); |
479 | return global_qtest; | |
6acf801d | 480 | } |
49ee3590 | 481 | |
1d9358e6 MA |
482 | /** |
483 | * qtest_end: | |
484 | * | |
485 | * Shut down the QEMU process started by qtest_start(). | |
486 | */ | |
487 | static inline void qtest_end(void) | |
488 | { | |
489 | qtest_quit(global_qtest); | |
96b8ca47 | 490 | global_qtest = NULL; |
1d9358e6 MA |
491 | } |
492 | ||
0c460dac SH |
493 | /** |
494 | * qmp: | |
495 | * @fmt...: QMP message to send to qemu | |
496 | * | |
497 | * Sends a QMP message to QEMU and returns the response. | |
498 | */ | |
0100f425 | 499 | QDict *qmp(const char *fmt, ...); |
0c460dac | 500 | |
ba4ed393 JS |
501 | /** |
502 | * qmp_async: | |
503 | * @fmt...: QMP message to send to qemu | |
504 | * | |
505 | * Sends a QMP message to QEMU and leaves the response in the stream. | |
506 | */ | |
507 | void qmp_async(const char *fmt, ...); | |
508 | ||
a3ca163c | 509 | /** |
0d1aa05e | 510 | * qmp_discard_response: |
a3ca163c KW |
511 | * @fmt...: QMP message to send to qemu |
512 | * | |
0d1aa05e | 513 | * Sends a QMP message to QEMU and consumes the response. |
a3ca163c | 514 | */ |
0100f425 | 515 | void qmp_discard_response(const char *fmt, ...); |
a3ca163c | 516 | |
66e0c7b1 AF |
517 | /** |
518 | * qmp_receive: | |
519 | * | |
520 | * Reads a QMP message from QEMU and returns the response. | |
521 | */ | |
522 | static inline QDict *qmp_receive(void) | |
523 | { | |
524 | return qtest_qmp_receive(global_qtest); | |
525 | } | |
526 | ||
8fe941f7 JS |
527 | /** |
528 | * qmp_eventwait: | |
529 | * @s: #event event to wait for. | |
530 | * | |
531 | * Continuosly polls for QMP responses until it receives the desired event. | |
532 | */ | |
533 | static inline void qmp_eventwait(const char *event) | |
534 | { | |
535 | return qtest_qmp_eventwait(global_qtest, event); | |
536 | } | |
537 | ||
5fb48d96 MA |
538 | /** |
539 | * hmp: | |
540 | * @fmt...: HMP command to send to QEMU | |
541 | * | |
542 | * Send HMP command to QEMU via QMP's human-monitor-command. | |
543 | * | |
544 | * Returns: the command's output. The caller should g_free() it. | |
545 | */ | |
546 | char *hmp(const char *fmt, ...); | |
547 | ||
49ee3590 AL |
548 | /** |
549 | * get_irq: | |
550 | * @num: Interrupt to observe. | |
551 | * | |
6acf801d | 552 | * Returns: The level of the @num interrupt. |
49ee3590 | 553 | */ |
6acf801d AF |
554 | static inline bool get_irq(int num) |
555 | { | |
556 | return qtest_get_irq(global_qtest, num); | |
557 | } | |
49ee3590 AL |
558 | |
559 | /** | |
560 | * irq_intercept_in: | |
561 | * @string: QOM path of a device. | |
562 | * | |
563 | * Associate qtest irqs with the GPIO-in pins of the device | |
564 | * whose path is specified by @string. | |
565 | */ | |
6acf801d AF |
566 | static inline void irq_intercept_in(const char *string) |
567 | { | |
568 | qtest_irq_intercept_in(global_qtest, string); | |
569 | } | |
49ee3590 AL |
570 | |
571 | /** | |
572 | * qtest_irq_intercept_out: | |
573 | * @string: QOM path of a device. | |
574 | * | |
575 | * Associate qtest irqs with the GPIO-out pins of the device | |
576 | * whose path is specified by @string. | |
577 | */ | |
6acf801d AF |
578 | static inline void irq_intercept_out(const char *string) |
579 | { | |
580 | qtest_irq_intercept_out(global_qtest, string); | |
581 | } | |
49ee3590 AL |
582 | |
583 | /** | |
584 | * outb: | |
585 | * @addr: I/O port to write to. | |
586 | * @value: Value being written. | |
587 | * | |
588 | * Write an 8-bit value to an I/O port. | |
589 | */ | |
6acf801d AF |
590 | static inline void outb(uint16_t addr, uint8_t value) |
591 | { | |
592 | qtest_outb(global_qtest, addr, value); | |
593 | } | |
49ee3590 AL |
594 | |
595 | /** | |
596 | * outw: | |
597 | * @addr: I/O port to write to. | |
598 | * @value: Value being written. | |
599 | * | |
600 | * Write a 16-bit value to an I/O port. | |
601 | */ | |
6acf801d AF |
602 | static inline void outw(uint16_t addr, uint16_t value) |
603 | { | |
604 | qtest_outw(global_qtest, addr, value); | |
605 | } | |
49ee3590 AL |
606 | |
607 | /** | |
608 | * outl: | |
609 | * @addr: I/O port to write to. | |
610 | * @value: Value being written. | |
611 | * | |
612 | * Write a 32-bit value to an I/O port. | |
613 | */ | |
6acf801d AF |
614 | static inline void outl(uint16_t addr, uint32_t value) |
615 | { | |
616 | qtest_outl(global_qtest, addr, value); | |
617 | } | |
49ee3590 AL |
618 | |
619 | /** | |
620 | * inb: | |
621 | * @addr: I/O port to read from. | |
49ee3590 | 622 | * |
6acf801d AF |
623 | * Reads an 8-bit value from an I/O port. |
624 | * | |
625 | * Returns: Value read. | |
49ee3590 | 626 | */ |
6acf801d AF |
627 | static inline uint8_t inb(uint16_t addr) |
628 | { | |
629 | return qtest_inb(global_qtest, addr); | |
630 | } | |
49ee3590 AL |
631 | |
632 | /** | |
633 | * inw: | |
634 | * @addr: I/O port to read from. | |
49ee3590 | 635 | * |
6acf801d AF |
636 | * Reads a 16-bit value from an I/O port. |
637 | * | |
638 | * Returns: Value read. | |
49ee3590 | 639 | */ |
6acf801d AF |
640 | static inline uint16_t inw(uint16_t addr) |
641 | { | |
642 | return qtest_inw(global_qtest, addr); | |
643 | } | |
49ee3590 AL |
644 | |
645 | /** | |
646 | * inl: | |
647 | * @addr: I/O port to read from. | |
49ee3590 | 648 | * |
6acf801d AF |
649 | * Reads a 32-bit value from an I/O port. |
650 | * | |
651 | * Returns: Value read. | |
49ee3590 | 652 | */ |
6acf801d AF |
653 | static inline uint32_t inl(uint16_t addr) |
654 | { | |
655 | return qtest_inl(global_qtest, addr); | |
656 | } | |
49ee3590 | 657 | |
872536bf AF |
658 | /** |
659 | * writeb: | |
660 | * @addr: Guest address to write to. | |
661 | * @value: Value being written. | |
662 | * | |
663 | * Writes an 8-bit value to guest memory. | |
664 | */ | |
665 | static inline void writeb(uint64_t addr, uint8_t value) | |
666 | { | |
667 | qtest_writeb(global_qtest, addr, value); | |
668 | } | |
669 | ||
670 | /** | |
671 | * writew: | |
672 | * @addr: Guest address to write to. | |
673 | * @value: Value being written. | |
674 | * | |
675 | * Writes a 16-bit value to guest memory. | |
676 | */ | |
677 | static inline void writew(uint64_t addr, uint16_t value) | |
678 | { | |
679 | qtest_writew(global_qtest, addr, value); | |
680 | } | |
681 | ||
682 | /** | |
683 | * writel: | |
684 | * @addr: Guest address to write to. | |
685 | * @value: Value being written. | |
686 | * | |
687 | * Writes a 32-bit value to guest memory. | |
688 | */ | |
689 | static inline void writel(uint64_t addr, uint32_t value) | |
690 | { | |
691 | qtest_writel(global_qtest, addr, value); | |
692 | } | |
693 | ||
694 | /** | |
695 | * writeq: | |
696 | * @addr: Guest address to write to. | |
697 | * @value: Value being written. | |
698 | * | |
699 | * Writes a 64-bit value to guest memory. | |
700 | */ | |
701 | static inline void writeq(uint64_t addr, uint64_t value) | |
702 | { | |
703 | qtest_writeq(global_qtest, addr, value); | |
704 | } | |
705 | ||
706 | /** | |
707 | * readb: | |
708 | * @addr: Guest address to read from. | |
709 | * | |
710 | * Reads an 8-bit value from guest memory. | |
711 | * | |
712 | * Returns: Value read. | |
713 | */ | |
714 | static inline uint8_t readb(uint64_t addr) | |
715 | { | |
716 | return qtest_readb(global_qtest, addr); | |
717 | } | |
718 | ||
719 | /** | |
720 | * readw: | |
721 | * @addr: Guest address to read from. | |
722 | * | |
723 | * Reads a 16-bit value from guest memory. | |
724 | * | |
725 | * Returns: Value read. | |
726 | */ | |
727 | static inline uint16_t readw(uint64_t addr) | |
728 | { | |
729 | return qtest_readw(global_qtest, addr); | |
730 | } | |
731 | ||
732 | /** | |
733 | * readl: | |
734 | * @addr: Guest address to read from. | |
735 | * | |
736 | * Reads a 32-bit value from guest memory. | |
737 | * | |
738 | * Returns: Value read. | |
739 | */ | |
740 | static inline uint32_t readl(uint64_t addr) | |
741 | { | |
742 | return qtest_readl(global_qtest, addr); | |
743 | } | |
744 | ||
745 | /** | |
746 | * readq: | |
747 | * @addr: Guest address to read from. | |
748 | * | |
749 | * Reads a 64-bit value from guest memory. | |
750 | * | |
751 | * Returns: Value read. | |
752 | */ | |
753 | static inline uint64_t readq(uint64_t addr) | |
754 | { | |
755 | return qtest_readq(global_qtest, addr); | |
756 | } | |
757 | ||
49ee3590 AL |
758 | /** |
759 | * memread: | |
760 | * @addr: Guest address to read from. | |
761 | * @data: Pointer to where memory contents will be stored. | |
762 | * @size: Number of bytes to read. | |
763 | * | |
764 | * Read guest memory into a buffer. | |
765 | */ | |
6acf801d AF |
766 | static inline void memread(uint64_t addr, void *data, size_t size) |
767 | { | |
768 | qtest_memread(global_qtest, addr, data, size); | |
769 | } | |
49ee3590 | 770 | |
7a6a740d JS |
771 | /** |
772 | * bufread: | |
773 | * @addr: Guest address to read from. | |
774 | * @data: Pointer to where memory contents will be stored. | |
775 | * @size: Number of bytes to read. | |
776 | * | |
777 | * Read guest memory into a buffer, receive using a base64 encoding. | |
778 | */ | |
779 | static inline void bufread(uint64_t addr, void *data, size_t size) | |
780 | { | |
781 | qtest_bufread(global_qtest, addr, data, size); | |
782 | } | |
783 | ||
49ee3590 AL |
784 | /** |
785 | * memwrite: | |
786 | * @addr: Guest address to write to. | |
787 | * @data: Pointer to the bytes that will be written to guest memory. | |
788 | * @size: Number of bytes to write. | |
789 | * | |
790 | * Write a buffer to guest memory. | |
791 | */ | |
6acf801d AF |
792 | static inline void memwrite(uint64_t addr, const void *data, size_t size) |
793 | { | |
794 | qtest_memwrite(global_qtest, addr, data, size); | |
795 | } | |
49ee3590 | 796 | |
7a6a740d JS |
797 | /** |
798 | * bufwrite: | |
799 | * @addr: Guest address to write to. | |
800 | * @data: Pointer to the bytes that will be written to guest memory. | |
801 | * @size: Number of bytes to write. | |
802 | * | |
803 | * Write a buffer to guest memory, transmit using a base64 encoding. | |
804 | */ | |
805 | static inline void bufwrite(uint64_t addr, const void *data, size_t size) | |
806 | { | |
807 | qtest_bufwrite(global_qtest, addr, data, size); | |
808 | } | |
809 | ||
86298845 JS |
810 | /** |
811 | * qmemset: | |
812 | * @addr: Guest address to write to. | |
813 | * @patt: Byte pattern to fill the guest memory region with. | |
814 | * @size: Number of bytes to write. | |
815 | * | |
816 | * Write a pattern to guest memory. | |
817 | */ | |
818 | static inline void qmemset(uint64_t addr, uint8_t patt, size_t size) | |
819 | { | |
820 | qtest_memset(global_qtest, addr, patt, size); | |
821 | } | |
822 | ||
49ee3590 AL |
823 | /** |
824 | * clock_step_next: | |
825 | * | |
bc72ad67 | 826 | * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. |
6acf801d | 827 | * |
bc72ad67 | 828 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 | 829 | */ |
6acf801d AF |
830 | static inline int64_t clock_step_next(void) |
831 | { | |
832 | return qtest_clock_step_next(global_qtest); | |
833 | } | |
49ee3590 AL |
834 | |
835 | /** | |
836 | * clock_step: | |
837 | * @step: Number of nanoseconds to advance the clock by. | |
838 | * | |
bc72ad67 | 839 | * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. |
6acf801d | 840 | * |
bc72ad67 | 841 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 | 842 | */ |
6acf801d AF |
843 | static inline int64_t clock_step(int64_t step) |
844 | { | |
845 | return qtest_clock_step(global_qtest, step); | |
846 | } | |
49ee3590 AL |
847 | |
848 | /** | |
849 | * clock_set: | |
850 | * @val: Nanoseconds value to advance the clock to. | |
851 | * | |
bc72ad67 | 852 | * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched. |
6acf801d | 853 | * |
bc72ad67 | 854 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 | 855 | */ |
6acf801d AF |
856 | static inline int64_t clock_set(int64_t val) |
857 | { | |
858 | return qtest_clock_set(global_qtest, val); | |
859 | } | |
49ee3590 | 860 | |
46e0cf76 MM |
861 | /** |
862 | * qtest_big_endian: | |
863 | * | |
864 | * Returns: True if the architecture under test has a big endian configuration. | |
865 | */ | |
866 | bool qtest_big_endian(void); | |
867 | ||
dc47995e MAL |
868 | |
869 | QDict *qmp_fd_receive(int fd); | |
870 | void qmp_fd_sendv(int fd, const char *fmt, va_list ap); | |
871 | void qmp_fd_send(int fd, const char *fmt, ...); | |
872 | QDict *qmp_fdv(int fd, const char *fmt, va_list ap); | |
873 | QDict *qmp_fd(int fd, const char *fmt, ...); | |
874 | ||
49ee3590 | 875 | #endif |