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