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