]>
Commit | Line | Data |
---|---|---|
49ee3590 AL |
1 | /* |
2 | * QTest | |
3 | * | |
4 | * Copyright IBM, Corp. 2012 | |
5 | * Copyright Red Hat, Inc. 2012 | |
872536bf | 6 | * Copyright SUSE LINUX Products GmbH 2013 |
49ee3590 AL |
7 | * |
8 | * Authors: | |
9 | * Anthony Liguori <[email protected]> | |
10 | * Paolo Bonzini <[email protected]> | |
872536bf | 11 | * Andreas Färber <[email protected]> |
49ee3590 AL |
12 | * |
13 | * This work is licensed under the terms of the GNU GPL, version 2 or later. | |
14 | * See the COPYING file in the top-level directory. | |
15 | * | |
16 | */ | |
17 | #ifndef LIBQTEST_H | |
18 | #define LIBQTEST_H | |
19 | ||
5cb8f0db PB |
20 | #include "qapi/qmp/qobject.h" |
21 | #include "qapi/qmp/qdict.h" | |
22 | ||
49ee3590 AL |
23 | typedef struct QTestState QTestState; |
24 | ||
78b27bad | 25 | /** |
88b988c8 | 26 | * qtest_initf: |
78b27bad EB |
27 | * @fmt...: Format for creating other arguments to pass to QEMU, formatted |
28 | * like sprintf(). | |
29 | * | |
00825d96 | 30 | * Convenience wrapper around qtest_init(). |
78b27bad EB |
31 | * |
32 | * Returns: #QTestState instance. | |
33 | */ | |
88b988c8 | 34 | QTestState *qtest_initf(const char *fmt, ...) GCC_FMT_ATTR(1, 2); |
78b27bad EB |
35 | |
36 | /** | |
88b988c8 | 37 | * qtest_vinitf: |
78b27bad EB |
38 | * @fmt: Format for creating other arguments to pass to QEMU, formatted |
39 | * like vsprintf(). | |
40 | * @ap: Format arguments. | |
41 | * | |
00825d96 | 42 | * Convenience wrapper around qtest_init(). |
78b27bad EB |
43 | * |
44 | * Returns: #QTestState instance. | |
45 | */ | |
88b988c8 | 46 | QTestState *qtest_vinitf(const char *fmt, va_list ap) GCC_FMT_ATTR(1, 0); |
78b27bad | 47 | |
49ee3590 AL |
48 | /** |
49 | * qtest_init: | |
88b988c8 MA |
50 | * @extra_args: other arguments to pass to QEMU. CAUTION: these |
51 | * arguments are subject to word splitting and shell evaluation. | |
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 | * @extra_args: other arguments to pass to QEMU. CAUTION: these |
60 | * arguments are subject to word splitting and shell evaluation. | |
f66e7ac8 MA |
61 | * |
62 | * Returns: #QTestState instance. | |
63 | */ | |
192f26a7 | 64 | QTestState *qtest_init_without_qmp_handshake(const char *extra_args); |
f66e7ac8 | 65 | |
6c90a82c JS |
66 | /** |
67 | * qtest_init_with_serial: | |
68 | * @extra_args: other arguments to pass to QEMU. CAUTION: these | |
69 | * arguments are subject to word splitting and shell evaluation. | |
70 | * @sock_fd: pointer to store the socket file descriptor for | |
71 | * connection with serial. | |
72 | * | |
73 | * Returns: #QTestState instance. | |
74 | */ | |
75 | QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd); | |
76 | ||
49ee3590 AL |
77 | /** |
78 | * qtest_quit: | |
6acf801d | 79 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
80 | * |
81 | * Shut down the QEMU process associated to @s. | |
82 | */ | |
83 | void qtest_quit(QTestState *s); | |
84 | ||
24d5588c YK |
85 | /** |
86 | * qtest_qmp_fds: | |
87 | * @s: #QTestState instance to operate on. | |
88 | * @fds: array of file descriptors | |
89 | * @fds_num: number of elements in @fds | |
90 | * @fmt...: QMP message to send to qemu, formatted like | |
91 | * qobject_from_jsonf_nofail(). See parse_escape() for what's | |
92 | * supported after '%'. | |
93 | * | |
94 | * Sends a QMP message to QEMU with fds and returns the response. | |
95 | */ | |
96 | QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num, | |
97 | const char *fmt, ...) | |
98 | GCC_FMT_ATTR(4, 5); | |
99 | ||
0c460dac SH |
100 | /** |
101 | * qtest_qmp: | |
102 | * @s: #QTestState instance to operate on. | |
bb340eb2 | 103 | * @fmt...: QMP message to send to qemu, formatted like |
6ce80fd8 MA |
104 | * qobject_from_jsonf_nofail(). See parse_escape() for what's |
105 | * supported after '%'. | |
0c460dac SH |
106 | * |
107 | * Sends a QMP message to QEMU and returns the response. | |
108 | */ | |
e3dc93be MA |
109 | QDict *qtest_qmp(QTestState *s, const char *fmt, ...) |
110 | GCC_FMT_ATTR(2, 3); | |
0c460dac | 111 | |
ba4ed393 | 112 | /** |
4277f1eb | 113 | * qtest_qmp_send: |
ba4ed393 | 114 | * @s: #QTestState instance to operate on. |
bb340eb2 | 115 | * @fmt...: QMP message to send to qemu, formatted like |
6ce80fd8 MA |
116 | * qobject_from_jsonf_nofail(). See parse_escape() for what's |
117 | * supported after '%'. | |
ba4ed393 JS |
118 | * |
119 | * Sends a QMP message to QEMU and leaves the response in the stream. | |
120 | */ | |
e3dc93be MA |
121 | void qtest_qmp_send(QTestState *s, const char *fmt, ...) |
122 | GCC_FMT_ATTR(2, 3); | |
ba4ed393 | 123 | |
aed877c5 MA |
124 | /** |
125 | * qtest_qmp_send_raw: | |
126 | * @s: #QTestState instance to operate on. | |
127 | * @fmt...: text to send, formatted like sprintf() | |
128 | * | |
129 | * Sends text to the QMP monitor verbatim. Need not be valid JSON; | |
130 | * this is useful for negative tests. | |
131 | */ | |
132 | void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...) | |
133 | GCC_FMT_ATTR(2, 3); | |
134 | ||
0c460dac | 135 | /** |
24d5588c YK |
136 | * qtest_vqmp_fds: |
137 | * @s: #QTestState instance to operate on. | |
138 | * @fds: array of file descriptors | |
139 | * @fds_num: number of elements in @fds | |
140 | * @fmt: QMP message to send to QEMU, formatted like | |
141 | * qobject_from_jsonf_nofail(). See parse_escape() for what's | |
142 | * supported after '%'. | |
143 | * @ap: QMP message arguments | |
144 | * | |
145 | * Sends a QMP message to QEMU with fds and returns the response. | |
146 | */ | |
147 | QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num, | |
148 | const char *fmt, va_list ap) | |
149 | GCC_FMT_ATTR(4, 0); | |
150 | ||
151 | /** | |
152 | * qtest_vqmp: | |
0c460dac | 153 | * @s: #QTestState instance to operate on. |
bb340eb2 | 154 | * @fmt: QMP message to send to QEMU, formatted like |
6ce80fd8 MA |
155 | * qobject_from_jsonf_nofail(). See parse_escape() for what's |
156 | * supported after '%'. | |
0c460dac SH |
157 | * @ap: QMP message arguments |
158 | * | |
159 | * Sends a QMP message to QEMU and returns the response. | |
160 | */ | |
248eef02 | 161 | QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap) |
e3dc93be | 162 | GCC_FMT_ATTR(2, 0); |
0c460dac | 163 | |
24d5588c YK |
164 | /** |
165 | * qtest_qmp_vsend_fds: | |
166 | * @s: #QTestState instance to operate on. | |
167 | * @fds: array of file descriptors | |
168 | * @fds_num: number of elements in @fds | |
169 | * @fmt: QMP message to send to QEMU, formatted like | |
170 | * qobject_from_jsonf_nofail(). See parse_escape() for what's | |
171 | * supported after '%'. | |
172 | * @ap: QMP message arguments | |
173 | * | |
174 | * Sends a QMP message to QEMU and leaves the response in the stream. | |
175 | */ | |
176 | void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num, | |
177 | const char *fmt, va_list ap) | |
178 | GCC_FMT_ATTR(4, 0); | |
179 | ||
ba4ed393 | 180 | /** |
4277f1eb | 181 | * qtest_qmp_vsend: |
ba4ed393 | 182 | * @s: #QTestState instance to operate on. |
bb340eb2 | 183 | * @fmt: QMP message to send to QEMU, formatted like |
6ce80fd8 MA |
184 | * qobject_from_jsonf_nofail(). See parse_escape() for what's |
185 | * supported after '%'. | |
ba4ed393 JS |
186 | * @ap: QMP message arguments |
187 | * | |
188 | * Sends a QMP message to QEMU and leaves the response in the stream. | |
189 | */ | |
e3dc93be MA |
190 | void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap) |
191 | GCC_FMT_ATTR(2, 0); | |
ba4ed393 | 192 | |
66e0c7b1 AF |
193 | /** |
194 | * qtest_receive: | |
195 | * @s: #QTestState instance to operate on. | |
196 | * | |
197 | * Reads a QMP message from QEMU and returns the response. | |
198 | */ | |
199 | QDict *qtest_qmp_receive(QTestState *s); | |
200 | ||
8fe941f7 JS |
201 | /** |
202 | * qtest_qmp_eventwait: | |
203 | * @s: #QTestState instance to operate on. | |
204 | * @s: #event event to wait for. | |
205 | * | |
e8ec0117 | 206 | * Continuously polls for QMP responses until it receives the desired event. |
8fe941f7 JS |
207 | */ |
208 | void qtest_qmp_eventwait(QTestState *s, const char *event); | |
209 | ||
7ffe3124 JS |
210 | /** |
211 | * qtest_qmp_eventwait_ref: | |
212 | * @s: #QTestState instance to operate on. | |
213 | * @s: #event event to wait for. | |
214 | * | |
e8ec0117 | 215 | * Continuously polls for QMP responses until it receives the desired event. |
7ffe3124 JS |
216 | * Returns a copy of the event for further investigation. |
217 | */ | |
218 | QDict *qtest_qmp_eventwait_ref(QTestState *s, const char *event); | |
219 | ||
3cd46d42 MA |
220 | /** |
221 | * qtest_qmp_receive_success: | |
222 | * @s: #QTestState instance to operate on | |
223 | * @event_cb: Event callback | |
224 | * @opaque: Argument for @event_cb | |
225 | * | |
226 | * Poll QMP messages until a command success response is received. | |
227 | * If @event_cb, call it for each event received, passing @opaque, | |
228 | * the event's name and data. | |
229 | * Return the success response's "return" member. | |
230 | */ | |
231 | QDict *qtest_qmp_receive_success(QTestState *s, | |
232 | void (*event_cb)(void *opaque, | |
233 | const char *name, | |
234 | QDict *data), | |
235 | void *opaque); | |
236 | ||
5fb48d96 | 237 | /** |
6bb87be8 | 238 | * qtest_hmp: |
5fb48d96 | 239 | * @s: #QTestState instance to operate on. |
7b899f4d | 240 | * @fmt...: HMP command to send to QEMU, formats arguments like sprintf(). |
5fb48d96 MA |
241 | * |
242 | * Send HMP command to QEMU via QMP's human-monitor-command. | |
6bb87be8 | 243 | * QMP events are discarded. |
5fb48d96 MA |
244 | * |
245 | * Returns: the command's output. The caller should g_free() it. | |
246 | */ | |
7b899f4d | 247 | char *qtest_hmp(QTestState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); |
5fb48d96 MA |
248 | |
249 | /** | |
250 | * qtest_hmpv: | |
251 | * @s: #QTestState instance to operate on. | |
bb340eb2 | 252 | * @fmt: HMP command to send to QEMU, formats arguments like vsprintf(). |
5fb48d96 MA |
253 | * @ap: HMP command arguments |
254 | * | |
255 | * Send HMP command to QEMU via QMP's human-monitor-command. | |
6bb87be8 | 256 | * QMP events are discarded. |
5fb48d96 MA |
257 | * |
258 | * Returns: the command's output. The caller should g_free() it. | |
259 | */ | |
248eef02 | 260 | char *qtest_vhmp(QTestState *s, const char *fmt, va_list ap) |
bb340eb2 | 261 | GCC_FMT_ATTR(2, 0); |
5fb48d96 | 262 | |
eb062cfa MAL |
263 | void qtest_module_load(QTestState *s, const char *prefix, const char *libname); |
264 | ||
49ee3590 AL |
265 | /** |
266 | * qtest_get_irq: | |
6acf801d | 267 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
268 | * @num: Interrupt to observe. |
269 | * | |
6acf801d | 270 | * Returns: The level of the @num interrupt. |
49ee3590 AL |
271 | */ |
272 | bool qtest_get_irq(QTestState *s, int num); | |
273 | ||
274 | /** | |
275 | * qtest_irq_intercept_in: | |
6acf801d | 276 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
277 | * @string: QOM path of a device. |
278 | * | |
279 | * Associate qtest irqs with the GPIO-in pins of the device | |
280 | * whose path is specified by @string. | |
281 | */ | |
282 | void qtest_irq_intercept_in(QTestState *s, const char *string); | |
283 | ||
284 | /** | |
285 | * qtest_irq_intercept_out: | |
6acf801d | 286 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
287 | * @string: QOM path of a device. |
288 | * | |
289 | * Associate qtest irqs with the GPIO-out pins of the device | |
290 | * whose path is specified by @string. | |
291 | */ | |
292 | void qtest_irq_intercept_out(QTestState *s, const char *string); | |
293 | ||
9813dc6a SG |
294 | /** |
295 | * qtest_set_irq_in: | |
296 | * @s: QTestState instance to operate on. | |
297 | * @string: QOM path of a device | |
298 | * @name: IRQ name | |
299 | * @irq: IRQ number | |
300 | * @level: IRQ level | |
301 | * | |
302 | * Force given device/irq GPIO-in pin to the given level. | |
303 | */ | |
304 | void qtest_set_irq_in(QTestState *s, const char *string, const char *name, | |
305 | int irq, int level); | |
306 | ||
49ee3590 AL |
307 | /** |
308 | * qtest_outb: | |
6acf801d | 309 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
310 | * @addr: I/O port to write to. |
311 | * @value: Value being written. | |
312 | * | |
313 | * Write an 8-bit value to an I/O port. | |
314 | */ | |
315 | void qtest_outb(QTestState *s, uint16_t addr, uint8_t value); | |
316 | ||
317 | /** | |
318 | * qtest_outw: | |
6acf801d | 319 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
320 | * @addr: I/O port to write to. |
321 | * @value: Value being written. | |
322 | * | |
323 | * Write a 16-bit value to an I/O port. | |
324 | */ | |
325 | void qtest_outw(QTestState *s, uint16_t addr, uint16_t value); | |
326 | ||
327 | /** | |
328 | * qtest_outl: | |
6acf801d | 329 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
330 | * @addr: I/O port to write to. |
331 | * @value: Value being written. | |
332 | * | |
333 | * Write a 32-bit value to an I/O port. | |
334 | */ | |
335 | void qtest_outl(QTestState *s, uint16_t addr, uint32_t value); | |
336 | ||
337 | /** | |
338 | * qtest_inb: | |
6acf801d | 339 | * @s: #QTestState instance to operate on. |
49ee3590 | 340 | * @addr: I/O port to read from. |
49ee3590 AL |
341 | * |
342 | * Returns an 8-bit value from an I/O port. | |
343 | */ | |
344 | uint8_t qtest_inb(QTestState *s, uint16_t addr); | |
345 | ||
346 | /** | |
347 | * qtest_inw: | |
6acf801d | 348 | * @s: #QTestState instance to operate on. |
49ee3590 | 349 | * @addr: I/O port to read from. |
49ee3590 AL |
350 | * |
351 | * Returns a 16-bit value from an I/O port. | |
352 | */ | |
353 | uint16_t qtest_inw(QTestState *s, uint16_t addr); | |
354 | ||
355 | /** | |
356 | * qtest_inl: | |
6acf801d | 357 | * @s: #QTestState instance to operate on. |
49ee3590 | 358 | * @addr: I/O port to read from. |
49ee3590 AL |
359 | * |
360 | * Returns a 32-bit value from an I/O port. | |
361 | */ | |
362 | uint32_t qtest_inl(QTestState *s, uint16_t addr); | |
363 | ||
872536bf AF |
364 | /** |
365 | * qtest_writeb: | |
366 | * @s: #QTestState instance to operate on. | |
367 | * @addr: Guest address to write to. | |
368 | * @value: Value being written. | |
369 | * | |
370 | * Writes an 8-bit value to memory. | |
371 | */ | |
372 | void qtest_writeb(QTestState *s, uint64_t addr, uint8_t value); | |
373 | ||
374 | /** | |
375 | * qtest_writew: | |
376 | * @s: #QTestState instance to operate on. | |
377 | * @addr: Guest address to write to. | |
378 | * @value: Value being written. | |
379 | * | |
380 | * Writes a 16-bit value to memory. | |
381 | */ | |
382 | void qtest_writew(QTestState *s, uint64_t addr, uint16_t value); | |
383 | ||
384 | /** | |
385 | * qtest_writel: | |
386 | * @s: #QTestState instance to operate on. | |
387 | * @addr: Guest address to write to. | |
388 | * @value: Value being written. | |
389 | * | |
390 | * Writes a 32-bit value to memory. | |
391 | */ | |
392 | void qtest_writel(QTestState *s, uint64_t addr, uint32_t value); | |
393 | ||
394 | /** | |
395 | * qtest_writeq: | |
396 | * @s: #QTestState instance to operate on. | |
397 | * @addr: Guest address to write to. | |
398 | * @value: Value being written. | |
399 | * | |
400 | * Writes a 64-bit value to memory. | |
401 | */ | |
402 | void qtest_writeq(QTestState *s, uint64_t addr, uint64_t value); | |
403 | ||
404 | /** | |
405 | * qtest_readb: | |
406 | * @s: #QTestState instance to operate on. | |
407 | * @addr: Guest address to read from. | |
408 | * | |
409 | * Reads an 8-bit value from memory. | |
410 | * | |
411 | * Returns: Value read. | |
412 | */ | |
413 | uint8_t qtest_readb(QTestState *s, uint64_t addr); | |
414 | ||
415 | /** | |
416 | * qtest_readw: | |
417 | * @s: #QTestState instance to operate on. | |
418 | * @addr: Guest address to read from. | |
419 | * | |
420 | * Reads a 16-bit value from memory. | |
421 | * | |
422 | * Returns: Value read. | |
423 | */ | |
424 | uint16_t qtest_readw(QTestState *s, uint64_t addr); | |
425 | ||
426 | /** | |
427 | * qtest_readl: | |
428 | * @s: #QTestState instance to operate on. | |
429 | * @addr: Guest address to read from. | |
430 | * | |
431 | * Reads a 32-bit value from memory. | |
432 | * | |
433 | * Returns: Value read. | |
434 | */ | |
435 | uint32_t qtest_readl(QTestState *s, uint64_t addr); | |
436 | ||
437 | /** | |
438 | * qtest_readq: | |
439 | * @s: #QTestState instance to operate on. | |
440 | * @addr: Guest address to read from. | |
441 | * | |
442 | * Reads a 64-bit value from memory. | |
443 | * | |
444 | * Returns: Value read. | |
445 | */ | |
446 | uint64_t qtest_readq(QTestState *s, uint64_t addr); | |
447 | ||
49ee3590 AL |
448 | /** |
449 | * qtest_memread: | |
6acf801d | 450 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
451 | * @addr: Guest address to read from. |
452 | * @data: Pointer to where memory contents will be stored. | |
453 | * @size: Number of bytes to read. | |
454 | * | |
455 | * Read guest memory into a buffer. | |
456 | */ | |
457 | void qtest_memread(QTestState *s, uint64_t addr, void *data, size_t size); | |
458 | ||
eeddd59f LV |
459 | /** |
460 | * qtest_rtas_call: | |
461 | * @s: #QTestState instance to operate on. | |
462 | * @name: name of the command to call. | |
463 | * @nargs: Number of args. | |
464 | * @args: Guest address to read args from. | |
465 | * @nret: Number of return value. | |
466 | * @ret: Guest address to write return values to. | |
467 | * | |
468 | * Call an RTAS function | |
469 | */ | |
470 | uint64_t qtest_rtas_call(QTestState *s, const char *name, | |
471 | uint32_t nargs, uint64_t args, | |
472 | uint32_t nret, uint64_t ret); | |
473 | ||
7a6a740d JS |
474 | /** |
475 | * qtest_bufread: | |
476 | * @s: #QTestState instance to operate on. | |
477 | * @addr: Guest address to read from. | |
478 | * @data: Pointer to where memory contents will be stored. | |
479 | * @size: Number of bytes to read. | |
480 | * | |
481 | * Read guest memory into a buffer and receive using a base64 encoding. | |
482 | */ | |
483 | void qtest_bufread(QTestState *s, uint64_t addr, void *data, size_t size); | |
484 | ||
49ee3590 AL |
485 | /** |
486 | * qtest_memwrite: | |
6acf801d | 487 | * @s: #QTestState instance to operate on. |
49ee3590 AL |
488 | * @addr: Guest address to write to. |
489 | * @data: Pointer to the bytes that will be written to guest memory. | |
490 | * @size: Number of bytes to write. | |
491 | * | |
492 | * Write a buffer to guest memory. | |
493 | */ | |
494 | void qtest_memwrite(QTestState *s, uint64_t addr, const void *data, size_t size); | |
495 | ||
7a6a740d JS |
496 | /** |
497 | * qtest_bufwrite: | |
498 | * @s: #QTestState instance to operate on. | |
499 | * @addr: Guest address to write to. | |
500 | * @data: Pointer to the bytes that will be written to guest memory. | |
501 | * @size: Number of bytes to write. | |
502 | * | |
503 | * Write a buffer to guest memory and transmit using a base64 encoding. | |
504 | */ | |
505 | void qtest_bufwrite(QTestState *s, uint64_t addr, | |
506 | const void *data, size_t size); | |
507 | ||
86298845 JS |
508 | /** |
509 | * qtest_memset: | |
510 | * @s: #QTestState instance to operate on. | |
511 | * @addr: Guest address to write to. | |
512 | * @patt: Byte pattern to fill the guest memory region with. | |
513 | * @size: Number of bytes to write. | |
514 | * | |
515 | * Write a pattern to guest memory. | |
516 | */ | |
517 | void qtest_memset(QTestState *s, uint64_t addr, uint8_t patt, size_t size); | |
518 | ||
49ee3590 AL |
519 | /** |
520 | * qtest_clock_step_next: | |
6acf801d AF |
521 | * @s: #QTestState instance to operate on. |
522 | * | |
bc72ad67 | 523 | * Advance the QEMU_CLOCK_VIRTUAL to the next deadline. |
49ee3590 | 524 | * |
bc72ad67 | 525 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
526 | */ |
527 | int64_t qtest_clock_step_next(QTestState *s); | |
528 | ||
529 | /** | |
530 | * qtest_clock_step: | |
531 | * @s: QTestState instance to operate on. | |
532 | * @step: Number of nanoseconds to advance the clock by. | |
533 | * | |
bc72ad67 | 534 | * Advance the QEMU_CLOCK_VIRTUAL by @step nanoseconds. |
6acf801d | 535 | * |
bc72ad67 | 536 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
537 | */ |
538 | int64_t qtest_clock_step(QTestState *s, int64_t step); | |
539 | ||
540 | /** | |
541 | * qtest_clock_set: | |
542 | * @s: QTestState instance to operate on. | |
543 | * @val: Nanoseconds value to advance the clock to. | |
544 | * | |
bc72ad67 | 545 | * Advance the QEMU_CLOCK_VIRTUAL to @val nanoseconds since the VM was launched. |
6acf801d | 546 | * |
bc72ad67 | 547 | * Returns: The current value of the QEMU_CLOCK_VIRTUAL in nanoseconds. |
49ee3590 AL |
548 | */ |
549 | int64_t qtest_clock_set(QTestState *s, int64_t val); | |
550 | ||
54ce6f22 LV |
551 | /** |
552 | * qtest_big_endian: | |
553 | * @s: QTestState instance to operate on. | |
554 | * | |
555 | * Returns: True if the architecture under test has a big endian configuration. | |
556 | */ | |
557 | bool qtest_big_endian(QTestState *s); | |
558 | ||
49ee3590 AL |
559 | /** |
560 | * qtest_get_arch: | |
561 | * | |
6acf801d | 562 | * Returns: The architecture for the QEMU executable under test. |
49ee3590 AL |
563 | */ |
564 | const char *qtest_get_arch(void); | |
565 | ||
566 | /** | |
567 | * qtest_add_func: | |
568 | * @str: Test case path. | |
569 | * @fn: Test case function | |
570 | * | |
571 | * Add a GTester testcase with the given name and function. | |
572 | * The path is prefixed with the architecture under test, as | |
6acf801d | 573 | * returned by qtest_get_arch(). |
49ee3590 | 574 | */ |
041088c7 | 575 | void qtest_add_func(const char *str, void (*fn)(void)); |
49ee3590 | 576 | |
7949c0e3 AF |
577 | /** |
578 | * qtest_add_data_func: | |
579 | * @str: Test case path. | |
580 | * @data: Test case data | |
581 | * @fn: Test case function | |
582 | * | |
583 | * Add a GTester testcase with the given name, data and function. | |
584 | * The path is prefixed with the architecture under test, as | |
585 | * returned by qtest_get_arch(). | |
586 | */ | |
041088c7 MA |
587 | void qtest_add_data_func(const char *str, const void *data, |
588 | void (*fn)(const void *)); | |
7949c0e3 | 589 | |
822e36ca MAL |
590 | /** |
591 | * qtest_add_data_func_full: | |
592 | * @str: Test case path. | |
593 | * @data: Test case data | |
594 | * @fn: Test case function | |
595 | * @data_free_func: GDestroyNotify for data | |
596 | * | |
597 | * Add a GTester testcase with the given name, data and function. | |
598 | * The path is prefixed with the architecture under test, as | |
599 | * returned by qtest_get_arch(). | |
600 | * | |
601 | * @data is passed to @data_free_func() on test completion. | |
602 | */ | |
603 | void qtest_add_data_func_full(const char *str, void *data, | |
604 | void (*fn)(const void *), | |
605 | GDestroyNotify data_free_func); | |
606 | ||
45b0f830 AF |
607 | /** |
608 | * qtest_add: | |
609 | * @testpath: Test case path | |
610 | * @Fixture: Fixture type | |
611 | * @tdata: Test case data | |
612 | * @fsetup: Test case setup function | |
613 | * @ftest: Test case function | |
614 | * @fteardown: Test case teardown function | |
615 | * | |
616 | * Add a GTester testcase with the given name, data and functions. | |
617 | * The path is prefixed with the architecture under test, as | |
618 | * returned by qtest_get_arch(). | |
619 | */ | |
620 | #define qtest_add(testpath, Fixture, tdata, fsetup, ftest, fteardown) \ | |
621 | do { \ | |
622 | char *path = g_strdup_printf("/%s/%s", qtest_get_arch(), testpath); \ | |
623 | g_test_add(path, Fixture, tdata, fsetup, ftest, fteardown); \ | |
624 | g_free(path); \ | |
625 | } while (0) | |
626 | ||
041088c7 | 627 | void qtest_add_abrt_handler(GHookFunc fn, const void *data); |
063c23d9 | 628 | |
8fe941f7 | 629 | /** |
6fc9f3d3 TH |
630 | * qtest_qmp_assert_success: |
631 | * @qts: QTestState instance to operate on | |
edbe36ad KW |
632 | * @fmt...: QMP message to send to qemu, formatted like |
633 | * qobject_from_jsonf_nofail(). See parse_escape() for what's | |
634 | * supported after '%'. | |
635 | * | |
636 | * Sends a QMP message to QEMU and asserts that a 'return' key is present in | |
637 | * the response. | |
638 | */ | |
6fc9f3d3 TH |
639 | void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...) |
640 | GCC_FMT_ATTR(2, 3); | |
edbe36ad | 641 | |
dc47995e | 642 | QDict *qmp_fd_receive(int fd); |
24d5588c YK |
643 | void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num, |
644 | const char *fmt, va_list ap) GCC_FMT_ATTR(4, 0); | |
e3dc93be MA |
645 | void qmp_fd_vsend(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); |
646 | void qmp_fd_send(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); | |
e2f64a68 MA |
647 | void qmp_fd_send_raw(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); |
648 | void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); | |
e3dc93be MA |
649 | QDict *qmp_fdv(int fd, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); |
650 | QDict *qmp_fd(int fd, const char *fmt, ...) GCC_FMT_ATTR(2, 3); | |
dc47995e | 651 | |
02ef6e87 TH |
652 | /** |
653 | * qtest_cb_for_every_machine: | |
654 | * @cb: Pointer to the callback function | |
1f4a0d81 | 655 | * @skip_old_versioned: true if versioned old machine types should be skipped |
02ef6e87 TH |
656 | * |
657 | * Call a callback function for every name of all available machines. | |
658 | */ | |
1f4a0d81 TH |
659 | void qtest_cb_for_every_machine(void (*cb)(const char *machine), |
660 | bool skip_old_versioned); | |
02ef6e87 | 661 | |
acd80015 TH |
662 | /** |
663 | * qtest_qmp_device_add: | |
e5758de4 | 664 | * @qts: QTestState instance to operate on |
acd80015 TH |
665 | * @driver: Name of the device that should be added |
666 | * @id: Identification string | |
82cab70b MA |
667 | * @fmt...: QMP message to send to qemu, formatted like |
668 | * qobject_from_jsonf_nofail(). See parse_escape() for what's | |
669 | * supported after '%'. | |
acd80015 TH |
670 | * |
671 | * Generic hot-plugging test via the device_add QMP command. | |
672 | */ | |
e5758de4 TH |
673 | void qtest_qmp_device_add(QTestState *qts, const char *driver, const char *id, |
674 | const char *fmt, ...) GCC_FMT_ATTR(4, 5); | |
acd80015 TH |
675 | |
676 | /** | |
677 | * qtest_qmp_device_del: | |
e5758de4 | 678 | * @qts: QTestState instance to operate on |
acd80015 TH |
679 | * @id: Identification string |
680 | * | |
681 | * Generic hot-unplugging test via the device_del QMP command. | |
682 | */ | |
e5758de4 | 683 | void qtest_qmp_device_del(QTestState *qts, const char *id); |
acd80015 | 684 | |
c35665e1 IM |
685 | /** |
686 | * qmp_rsp_is_err: | |
687 | * @rsp: QMP response to check for error | |
688 | * | |
689 | * Test @rsp for error and discard @rsp. | |
690 | * Returns 'true' if there is error in @rsp and 'false' otherwise. | |
691 | */ | |
692 | bool qmp_rsp_is_err(QDict *rsp); | |
693 | ||
ebb4d82d MAL |
694 | /** |
695 | * qmp_assert_error_class: | |
696 | * @rsp: QMP response to check for error | |
697 | * @class: an error class | |
698 | * | |
699 | * Assert the response has the given error class and discard @rsp. | |
700 | */ | |
701 | void qmp_assert_error_class(QDict *rsp, const char *class); | |
702 | ||
21f80286 RH |
703 | /** |
704 | * qtest_probe_child: | |
705 | * @s: QTestState instance to operate on. | |
706 | * | |
707 | * Returns: true if the child is still alive. | |
708 | */ | |
709 | bool qtest_probe_child(QTestState *s); | |
710 | ||
49ee3590 | 711 | #endif |