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