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