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