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