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