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