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