libqtest.h 20 KB

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