mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-08 02:03:56 -06:00
Misc cleanups
-----BEGIN PGP SIGNATURE----- iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmJxKjQcHG1hcmNhbmRy ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5ZD5D/9f5CGbNsrl7kB1t6iS 1ABr5AeW0g9sidMCsQAe9xhWl6+R2SO/z0bBue+mv1ltG0RSZ1ZXS4FyJFBAhFfR fZ6J7bvdnawIKOxu5T9NY/UvthdRV0eC8CTo0q6GAJo9MHyIGvo1TOoM2Ld9QpfB 2uup+9fw3Clh0HSHwV9LSL7v2nucFef4A5P1CJ6d1KHnnej0hfug5o+Aiy+wDLA2 5RnTm44dqm9lzTgt/x4MqE6Us7WWQukjlLny8/gyurNTR+6fxLqjsHZG+6woQETu Gg6angsOoAFyciFZ564rjGv80qQuccMVMjtrKvBZz/cmwUUz+Lb4tU3tUPBqomGX wiofVtL4qcXs94OHWX654UX/iXgkRqC3r+aC0xT37cL4svC8N69BhilxI5+gIGxZ ZjaQhHx/0e+Ut3c+xrjYHbywQMd9L9AhRyYSMz5BNeLg9+yUiMR+hvGVR/SubLN1 iiLS07CRgdOKdP6ts7CC7txAgDw4h3cPN5Hz+gqXMJTcnBKpXpnF1lL+Zd/J5++N 8qMVQH5O4REQRISsbKaOPW8PCiPESsUaHb/mWkre7iYLgkEdNMVQvRcnfx14ejbk /KKXolrG1huJXGQGnYvgJArHMBBL+ieIYiT6alKFNRNECLdioL46FuSOlirHVCGe StU22Vsl61M8ifDOPdolK55X5Q== =npwd -----END PGP SIGNATURE----- Merge tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu into staging Misc cleanups # -----BEGIN PGP SIGNATURE----- # # iQJQBAABCAA6FiEEh6m9kz+HxgbSdvYt2ujhCXWWnOUFAmJxKjQcHG1hcmNhbmRy # ZS5sdXJlYXVAcmVkaGF0LmNvbQAKCRDa6OEJdZac5ZD5D/9f5CGbNsrl7kB1t6iS # 1ABr5AeW0g9sidMCsQAe9xhWl6+R2SO/z0bBue+mv1ltG0RSZ1ZXS4FyJFBAhFfR # fZ6J7bvdnawIKOxu5T9NY/UvthdRV0eC8CTo0q6GAJo9MHyIGvo1TOoM2Ld9QpfB # 2uup+9fw3Clh0HSHwV9LSL7v2nucFef4A5P1CJ6d1KHnnej0hfug5o+Aiy+wDLA2 # 5RnTm44dqm9lzTgt/x4MqE6Us7WWQukjlLny8/gyurNTR+6fxLqjsHZG+6woQETu # Gg6angsOoAFyciFZ564rjGv80qQuccMVMjtrKvBZz/cmwUUz+Lb4tU3tUPBqomGX # wiofVtL4qcXs94OHWX654UX/iXgkRqC3r+aC0xT37cL4svC8N69BhilxI5+gIGxZ # ZjaQhHx/0e+Ut3c+xrjYHbywQMd9L9AhRyYSMz5BNeLg9+yUiMR+hvGVR/SubLN1 # iiLS07CRgdOKdP6ts7CC7txAgDw4h3cPN5Hz+gqXMJTcnBKpXpnF1lL+Zd/J5++N # 8qMVQH5O4REQRISsbKaOPW8PCiPESsUaHb/mWkre7iYLgkEdNMVQvRcnfx14ejbk # /KKXolrG1huJXGQGnYvgJArHMBBL+ieIYiT6alKFNRNECLdioL46FuSOlirHVCGe # StU22Vsl61M8ifDOPdolK55X5Q== # =npwd # -----END PGP SIGNATURE----- # gpg: Signature made Tue 03 May 2022 06:12:20 AM PDT # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] * tag 'misc-pull-request' of gitlab.com:marcandre.lureau/qemu: (23 commits) util: rename qemu_*block() socket functions tests: replace qemu_set_nonblock() net: replace qemu_set_nonblock() ui: replace qemu_set_nonblock() hw: replace qemu_set_nonblock() qga: replace qemu_set_nonblock() io: replace qemu_set{_non}block() chardev: replace qemu_set_nonblock() io: make qio_channel_command_new_pid() static Replace fcntl(O_NONBLOCK) with g_unix_set_fd_nonblocking() io: replace pipe() with g_unix_open_pipe(CLOEXEC) virtiofsd: replace pipe() with g_unix_open_pipe(CLOEXEC) os-posix: replace pipe()+cloexec with g_unix_open_pipe(CLOEXEC) tests: replace pipe() with g_unix_open_pipe(CLOEXEC) qga: replace pipe() with g_unix_open_pipe(CLOEXEC) util: replace pipe()+cloexec with g_unix_open_pipe() Replace qemu_pipe() with g_unix_open_pipe() block: move fcntl_setfl() Use g_unix_set_fd_nonblocking() libqtest: split QMP part in libqmp ... Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
2e3408b3cc
192 changed files with 609 additions and 565 deletions
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
#include "libqos/pci.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef TEST_ACPI_UTILS_H
|
||||
#define TEST_ACPI_UTILS_H
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/* DSDT and SSDTs format */
|
||||
typedef struct {
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include <getopt.h>
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/libqos-pc.h"
|
||||
#include "libqos/ahci.h"
|
||||
#include "libqos/pci-pc.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
|
||||
static void test_cmdfifo_underflow_ok(void)
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/bitops.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/bitops.h"
|
||||
|
||||
#define HACE_CMD 0x10
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/fw_cfg.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "boot-sector.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
#define LOW(x) ((x) & 0xff)
|
||||
#define HIGH(x) ((x) >> 8)
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#ifndef TEST_BOOT_SECTOR_H
|
||||
#define TEST_BOOT_SECTOR_H
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/* Create boot disk file. fname must be a suitable string for mkstemp() */
|
||||
int boot_sector_init(char *fname);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/libqos-spapr.h"
|
||||
|
||||
static const uint8_t bios_avr[] = {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "boot-sector.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "qemu/dbus.h"
|
||||
#include <gio/gio.h>
|
||||
#include <gio/gunixfdlist.h>
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "dbus-display1.h"
|
||||
|
||||
static GDBusConnection*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include <glib/gstdio.h>
|
||||
#include <gio/gio.h>
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "dbus-vmstate1.h"
|
||||
#include "migration-helpers.h"
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "qapi/qmp/qstring.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
const char common_args[] = "-nodefaults -machine none";
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/virtio.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/i2c.h"
|
||||
|
||||
#define DS1338_ADDR 0x68
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
#include "libqos/pci.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
#include "libqos/pci.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/bswap.h"
|
||||
|
||||
typedef struct TestCase TestCase;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include <glib/gstdio.h>
|
||||
#include "libqos/libqos-pc.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
#include "hw/pci/pci.h"
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
#include "libqos/pci.h"
|
||||
|
|
|
@ -550,7 +550,7 @@ static void fuzz_registers(void)
|
|||
|
||||
static bool qtest_check_clang_sanitizer(void)
|
||||
{
|
||||
#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer)
|
||||
#ifdef QEMU_SANITIZE_ADDRESS
|
||||
return true;
|
||||
#else
|
||||
g_test_skip("QEMU not configured using --enable-sanitizers");
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* https://bugs.launchpad.net/qemu/+bug/1879531
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* This used to trigger the assert in lsi_do_dma()
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* This used to trigger the assert in scsi_dma_complete
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* This used to trigger the assert in audio_calloc
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* https://gitlab.com/qemu-project/qemu/-/issues/450
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* Here a MemoryRegionCache pointed to an MMIO region but had a
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/*
|
||||
* This used to trigger the out-of-bounds read in xlnx_dp_read
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "sysemu/runstate.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qemu/rcu.h"
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/qgraph.h"
|
||||
#include "fuzz.h"
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "qemu/units.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
|
||||
/**
|
||||
* A libfuzzer fuzzing target
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include <wordexp.h>
|
||||
|
||||
#include "hw/core/cpu.h"
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/pci-pc.h"
|
||||
#include "fuzz.h"
|
||||
#include "fork_fuzz.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qemu/main-loop.h"
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/pci.h"
|
||||
#include "tests/qtest/libqos/pci-pc.h"
|
||||
#include "fuzz.h"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "exec/memory.h"
|
||||
#include "qemu/main-loop.h"
|
||||
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/malloc.h"
|
||||
#include "tests/qtest/libqos/qgraph.h"
|
||||
#include "tests/qtest/libqos/qgraph_internal.h"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/virtio-blk.h"
|
||||
#include "tests/qtest/libqos/virtio.h"
|
||||
#include "tests/qtest/libqos/virtio-pci.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
|
||||
#include "standard-headers/linux/virtio_config.h"
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/virtio-net.h"
|
||||
#include "fuzz.h"
|
||||
#include "fork_fuzz.h"
|
||||
|
@ -151,7 +151,7 @@ static void *virtio_net_test_setup_socket(GString *cmd_line, void *arg)
|
|||
{
|
||||
int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sockfds);
|
||||
g_assert_cmpint(ret, !=, -1);
|
||||
fcntl(sockfds[0], F_SETFL, O_NONBLOCK);
|
||||
g_unix_set_fd_nonblocking(sockfds[0], true, NULL);
|
||||
sockfds_initialized = true;
|
||||
g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ",
|
||||
sockfds[1]);
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "tests/qtest/libqos/libqtest.h"
|
||||
#include "tests/qtest/libqtest.h"
|
||||
#include "tests/qtest/libqos/virtio-scsi.h"
|
||||
#include "tests/qtest/libqos/virtio.h"
|
||||
#include "tests/qtest/libqos/virtio-pci.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||
#include "libqos/fw_cfg.h"
|
||||
#include "qemu/bswap.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/fw_cfg.h"
|
||||
#include "libqos/libqos.h"
|
||||
#include "standard-headers/linux/qemu_fw_cfg.h"
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
/* Load 'test.hex' and verify that the in-memory contents are as expected.
|
||||
* 'test.hex' is a memory test pattern stored in Hexadecimal Object
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqos/libqos.h"
|
||||
#include "libqos/pci-pc.h"
|
||||
#include "libqos/malloc-pc.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "contrib/ivshmem-server/ivshmem-server.h"
|
||||
#include "libqos/libqos-pc.h"
|
||||
#include "libqos/libqos-spapr.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
#define TMPSHMSIZE (1 << 20)
|
||||
static char *tmpshm;
|
||||
|
@ -304,6 +304,7 @@ static void setup_vm_with_server(IVState *s, int nvectors)
|
|||
|
||||
static void test_ivshmem_server(void)
|
||||
{
|
||||
g_autoptr(GError) err = NULL;
|
||||
IVState state1, state2, *s1, *s2;
|
||||
ServerThread thread;
|
||||
IvshmemServer server;
|
||||
|
@ -320,8 +321,8 @@ static void test_ivshmem_server(void)
|
|||
g_assert_cmpint(ret, ==, 0);
|
||||
|
||||
thread.server = &server;
|
||||
ret = pipe(thread.pipe);
|
||||
g_assert_cmpint(ret, ==, 0);
|
||||
g_unix_open_pipe(thread.pipe, FD_CLOEXEC, &err);
|
||||
g_assert_no_error(err);
|
||||
thread.thread = g_thread_new("ivshmem-server", server_thread, &thread);
|
||||
g_assert(thread.thread != NULL);
|
||||
|
||||
|
|
233
tests/qtest/libqmp.c
Normal file
233
tests/qtest/libqmp.c
Normal file
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* QTest
|
||||
*
|
||||
* Copyright IBM, Corp. 2012
|
||||
* Copyright Red Hat, Inc. 2012
|
||||
* Copyright SUSE LINUX Products GmbH 2013
|
||||
*
|
||||
* Authors:
|
||||
* Anthony Liguori <aliguori@us.ibm.com>
|
||||
* Paolo Bonzini <pbonzini@redhat.com>
|
||||
* Andreas Färber <afaerber@suse.de>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqmp.h"
|
||||
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/json-parser.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
|
||||
#define SOCKET_MAX_FDS 16
|
||||
|
||||
typedef struct {
|
||||
JSONMessageParser parser;
|
||||
QDict *response;
|
||||
} QMPResponseParser;
|
||||
|
||||
static void socket_send(int fd, const char *buf, size_t size)
|
||||
{
|
||||
size_t res = qemu_write_full(fd, buf, size);
|
||||
|
||||
assert(res == size);
|
||||
}
|
||||
|
||||
static void qmp_response(void *opaque, QObject *obj, Error *err)
|
||||
{
|
||||
QMPResponseParser *qmp = opaque;
|
||||
|
||||
assert(!obj != !err);
|
||||
|
||||
if (err) {
|
||||
error_prepend(&err, "QMP JSON response parsing failed: ");
|
||||
error_report_err(err);
|
||||
abort();
|
||||
}
|
||||
|
||||
g_assert(!qmp->response);
|
||||
qmp->response = qobject_to(QDict, obj);
|
||||
g_assert(qmp->response);
|
||||
}
|
||||
|
||||
QDict *qmp_fd_receive(int fd)
|
||||
{
|
||||
QMPResponseParser qmp;
|
||||
bool log = getenv("QTEST_LOG") != NULL;
|
||||
|
||||
qmp.response = NULL;
|
||||
json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL);
|
||||
while (!qmp.response) {
|
||||
ssize_t len;
|
||||
char c;
|
||||
|
||||
len = read(fd, &c, 1);
|
||||
if (len == -1 && errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len == -1 || len == 0) {
|
||||
fprintf(stderr, "Broken pipe\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (log) {
|
||||
g_assert(write(2, &c, 1) == 1);
|
||||
}
|
||||
json_message_parser_feed(&qmp.parser, &c, 1);
|
||||
}
|
||||
if (log) {
|
||||
g_assert(write(2, "\n", 1) == 1);
|
||||
}
|
||||
json_message_parser_destroy(&qmp.parser);
|
||||
|
||||
return qmp.response;
|
||||
}
|
||||
|
||||
/* Sends a message and file descriptors to the socket.
|
||||
* It's needed for qmp-commands like getfd/add-fd */
|
||||
static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
|
||||
const char *buf, size_t buf_size)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct msghdr msg = { 0 };
|
||||
char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
|
||||
size_t fdsize = sizeof(int) * fds_num;
|
||||
struct cmsghdr *cmsg;
|
||||
struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size };
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
if (fds && fds_num > 0) {
|
||||
g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS);
|
||||
|
||||
msg.msg_control = control;
|
||||
msg.msg_controllen = CMSG_SPACE(fdsize);
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(fdsize);
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_RIGHTS;
|
||||
memcpy(CMSG_DATA(cmsg), fds, fdsize);
|
||||
}
|
||||
|
||||
do {
|
||||
ret = sendmsg(socket_fd, &msg, 0);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
g_assert_cmpint(ret, >, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow users to send a message without waiting for the reply,
|
||||
* in the case that they choose to discard all replies up until
|
||||
* a particular EVENT is received.
|
||||
*/
|
||||
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
QObject *qobj;
|
||||
|
||||
/* Going through qobject ensures we escape strings properly */
|
||||
qobj = qobject_from_vjsonf_nofail(fmt, ap);
|
||||
|
||||
/* No need to send anything for an empty QObject. */
|
||||
if (qobj) {
|
||||
int log = getenv("QTEST_LOG") != NULL;
|
||||
GString *str = qobject_to_json(qobj);
|
||||
|
||||
/*
|
||||
* BUG: QMP doesn't react to input until it sees a newline, an
|
||||
* object, or an array. Work-around: give it a newline.
|
||||
*/
|
||||
g_string_append_c(str, '\n');
|
||||
|
||||
if (log) {
|
||||
fprintf(stderr, "%s", str->str);
|
||||
}
|
||||
/* Send QMP request */
|
||||
if (fds && fds_num > 0) {
|
||||
socket_send_fds(fd, fds, fds_num, str->str, str->len);
|
||||
} else {
|
||||
socket_send(fd, str->str, str->len);
|
||||
}
|
||||
|
||||
g_string_free(str, true);
|
||||
qobject_unref(qobj);
|
||||
}
|
||||
}
|
||||
|
||||
void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||
}
|
||||
|
||||
|
||||
QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||
|
||||
return qmp_fd_receive(fd);
|
||||
}
|
||||
|
||||
QDict *qmp_fd(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
QDict *response;
|
||||
|
||||
va_start(ap, fmt);
|
||||
response = qmp_fdv(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
return response;
|
||||
}
|
||||
|
||||
void qmp_fd_send(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
qmp_fd_vsend(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
bool log = getenv("QTEST_LOG") != NULL;
|
||||
char *str = g_strdup_vprintf(fmt, ap);
|
||||
|
||||
if (log) {
|
||||
fprintf(stderr, "%s", str);
|
||||
}
|
||||
socket_send(fd, str, strlen(str));
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void qmp_fd_send_raw(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
qmp_fd_vsend_raw(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
bool qmp_rsp_is_err(QDict *rsp)
|
||||
{
|
||||
QDict *error = qdict_get_qdict(rsp, "error");
|
||||
qobject_unref(rsp);
|
||||
return !!error;
|
||||
}
|
||||
|
||||
void qmp_expect_error_and_unref(QDict *rsp, const char *class)
|
||||
{
|
||||
QDict *error = qdict_get_qdict(rsp, "error");
|
||||
|
||||
g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class);
|
||||
g_assert_nonnull(qdict_get_try_str(error, "desc"));
|
||||
g_assert(!qdict_haskey(rsp, "return"));
|
||||
|
||||
qobject_unref(rsp);
|
||||
}
|
50
tests/qtest/libqmp.h
Normal file
50
tests/qtest/libqmp.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* libqmp test unit
|
||||
*
|
||||
* Copyright IBM, Corp. 2012
|
||||
* Copyright Red Hat, Inc. 2012
|
||||
* Copyright SUSE LINUX Products GmbH 2013
|
||||
*
|
||||
* Authors:
|
||||
* Anthony Liguori <aliguori@us.ibm.com>
|
||||
* Paolo Bonzini <pbonzini@redhat.com>
|
||||
* Andreas Färber <afaerber@suse.de>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
#ifndef LIBQMP_H_
|
||||
#define LIBQMP_H_
|
||||
|
||||
#include "qapi/qmp/qdict.h"
|
||||
|
||||
QDict *qmp_fd_receive(int fd);
|
||||
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0);
|
||||
void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
QDict *qmp_fdv(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
QDict *qmp_fd(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
|
||||
/**
|
||||
* qmp_rsp_is_err:
|
||||
* @rsp: QMP response to check for error
|
||||
*
|
||||
* Test @rsp for error and discard @rsp.
|
||||
* Returns 'true' if there is error in @rsp and 'false' otherwise.
|
||||
*/
|
||||
bool qmp_rsp_is_err(QDict *rsp);
|
||||
|
||||
/**
|
||||
* qmp_expect_error_and_unref:
|
||||
* @rsp: QMP response to check for error
|
||||
* @class: an error class
|
||||
*
|
||||
* Assert the response has the given error class and discard @rsp.
|
||||
*/
|
||||
void qmp_expect_error_and_unref(QDict *rsp, const char *class);
|
||||
|
||||
#endif /* LIBQMP_H_ */
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "ahci.h"
|
||||
#include "pci-pc.h"
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
#include "i2c.h"
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
#include "i2c.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "malloc.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "pci-pc.h"
|
||||
#include "qemu/sockets.h"
|
||||
#include "qemu/iov.h"
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "fw_cfg.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "hw/nvram/fw_cfg.h"
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef LIBQOS_FW_CFG_H
|
||||
#define LIBQOS_FW_CFG_H
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
typedef struct QFWCFG QFWCFG;
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
#include "i2c.h"
|
||||
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
#include "hw/i2c/imx_i2c.h"
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
|
||||
#include "qemu/bswap.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
enum OMAPI2CRegisters {
|
||||
OMAP_I2C_REV = 0x00,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "i2c.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len)
|
||||
{
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#ifndef LIBQOS_I2C_H
|
||||
#define LIBQOS_I2C_H
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qgraph.h"
|
||||
|
||||
typedef struct I2CAdapter I2CAdapter;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "libqos.h"
|
||||
#include "pci.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef LIBQOS_H
|
||||
#define LIBQOS_H
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "pci.h"
|
||||
#include "malloc.h"
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#define LIBQOS_MALLOC_H
|
||||
|
||||
#include "qemu/queue.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
typedef enum {
|
||||
ALLOC_NO_FLAGS = 0x00,
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
libqos_srcs = files('../libqtest.c',
|
||||
libqos_srcs = files(
|
||||
'../libqtest.c',
|
||||
'../libqmp.c',
|
||||
|
||||
'qgraph.c',
|
||||
'qos_external.c',
|
||||
'pci.c',
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "pci-pc.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "hw/pci/pci_regs.h"
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "pci-spapr.h"
|
||||
#include "rtas.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#ifndef LIBQOS_PCI_H
|
||||
#define LIBQOS_PCI_H
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qgraph.h"
|
||||
|
||||
#define QPCI_PIO_LIMIT 0x10000
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qgraph.h"
|
||||
#include "pci-spapr.h"
|
||||
#include "qemu/module.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/queue.h"
|
||||
#include "qgraph_internal.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include <getopt.h>
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qbool.h"
|
||||
#include "qapi/qmp/qstring.h"
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "rtas.h"
|
||||
|
||||
static void qrtas_copy_args(QTestState *qts, uint64_t target_args,
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "sdhci-cmd.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
static ssize_t read_fifo(QTestState *qts, uint64_t reg, char *msg, size_t count)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* for more details.
|
||||
*/
|
||||
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
|
||||
/* more details at hw/sd/sdhci-internal.h */
|
||||
#define SDHC_BLKSIZE 0x04
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qgraph.h"
|
||||
#include "pci.h"
|
||||
#include "qemu/module.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "pci.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
* See the COPYING file in the top-level directory.
|
||||
*/
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "hw/usb/uhci-regs.h"
|
||||
#include "usb.h"
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "standard-headers/linux/virtio_blk.h"
|
||||
#include "vhost-user-blk.h"
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "standard-headers/linux/virtio_ids.h"
|
||||
#include "virtio-9p.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "virtio-balloon.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "standard-headers/linux/virtio_blk.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "virtio-iommu.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "virtio.h"
|
||||
#include "virtio-mmio.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "virtio-net.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "virtio.h"
|
||||
#include "virtio-pci.h"
|
||||
#include "pci.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "virtio-rng.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "standard-headers/linux/virtio_ids.h"
|
||||
#include "qgraph.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qemu/module.h"
|
||||
#include "qgraph.h"
|
||||
#include "virtio-serial.h"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "virtio.h"
|
||||
#include "standard-headers/linux/virtio_config.h"
|
||||
#include "standard-headers/linux/virtio_ring.h"
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqtest.h"
|
||||
#include "../libqtest.h"
|
||||
#include "qgraph.h"
|
||||
#include "pci-pc.h"
|
||||
#include "qemu/module.h"
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#ifndef LIBQTEST_SINGLE_H
|
||||
#define LIBQTEST_SINGLE_H
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
QTestState *global_qtest __attribute__((common, weak));
|
||||
|
||||
|
|
|
@ -20,11 +20,10 @@
|
|||
#include <sys/wait.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "libqmp.h"
|
||||
#include "qemu/ctype.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/json-parser.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qjson.h"
|
||||
#include "qapi/qmp/qlist.h"
|
||||
|
@ -32,8 +31,6 @@
|
|||
|
||||
#define MAX_IRQ 256
|
||||
#define SOCKET_TIMEOUT 50
|
||||
#define SOCKET_MAX_FDS 16
|
||||
|
||||
|
||||
typedef void (*QTestSendFn)(QTestState *s, const char *buf);
|
||||
typedef void (*ExternalSendFn)(void *s, const char *buf);
|
||||
|
@ -440,40 +437,6 @@ static void G_GNUC_PRINTF(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...)
|
|||
g_free(str);
|
||||
}
|
||||
|
||||
/* Sends a message and file descriptors to the socket.
|
||||
* It's needed for qmp-commands like getfd/add-fd */
|
||||
static void socket_send_fds(int socket_fd, int *fds, size_t fds_num,
|
||||
const char *buf, size_t buf_size)
|
||||
{
|
||||
ssize_t ret;
|
||||
struct msghdr msg = { 0 };
|
||||
char control[CMSG_SPACE(sizeof(int) * SOCKET_MAX_FDS)] = { 0 };
|
||||
size_t fdsize = sizeof(int) * fds_num;
|
||||
struct cmsghdr *cmsg;
|
||||
struct iovec iov = { .iov_base = (char *)buf, .iov_len = buf_size };
|
||||
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
if (fds && fds_num > 0) {
|
||||
g_assert_cmpuint(fds_num, <, SOCKET_MAX_FDS);
|
||||
|
||||
msg.msg_control = control;
|
||||
msg.msg_controllen = CMSG_SPACE(fdsize);
|
||||
|
||||
cmsg = CMSG_FIRSTHDR(&msg);
|
||||
cmsg->cmsg_len = CMSG_LEN(fdsize);
|
||||
cmsg->cmsg_level = SOL_SOCKET;
|
||||
cmsg->cmsg_type = SCM_RIGHTS;
|
||||
memcpy(CMSG_DATA(cmsg), fds, fdsize);
|
||||
}
|
||||
|
||||
do {
|
||||
ret = sendmsg(socket_fd, &msg, 0);
|
||||
} while (ret < 0 && errno == EINTR);
|
||||
g_assert_cmpint(ret, >, 0);
|
||||
}
|
||||
|
||||
static GString *qtest_client_socket_recv_line(QTestState *s)
|
||||
{
|
||||
GString *line;
|
||||
|
@ -568,62 +531,6 @@ static int qtest_query_target_endianness(QTestState *s)
|
|||
return big_endian;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
JSONMessageParser parser;
|
||||
QDict *response;
|
||||
} QMPResponseParser;
|
||||
|
||||
static void qmp_response(void *opaque, QObject *obj, Error *err)
|
||||
{
|
||||
QMPResponseParser *qmp = opaque;
|
||||
|
||||
assert(!obj != !err);
|
||||
|
||||
if (err) {
|
||||
error_prepend(&err, "QMP JSON response parsing failed: ");
|
||||
error_report_err(err);
|
||||
abort();
|
||||
}
|
||||
|
||||
g_assert(!qmp->response);
|
||||
qmp->response = qobject_to(QDict, obj);
|
||||
g_assert(qmp->response);
|
||||
}
|
||||
|
||||
QDict *qmp_fd_receive(int fd)
|
||||
{
|
||||
QMPResponseParser qmp;
|
||||
bool log = getenv("QTEST_LOG") != NULL;
|
||||
|
||||
qmp.response = NULL;
|
||||
json_message_parser_init(&qmp.parser, qmp_response, &qmp, NULL);
|
||||
while (!qmp.response) {
|
||||
ssize_t len;
|
||||
char c;
|
||||
|
||||
len = read(fd, &c, 1);
|
||||
if (len == -1 && errno == EINTR) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len == -1 || len == 0) {
|
||||
fprintf(stderr, "Broken pipe\n");
|
||||
abort();
|
||||
}
|
||||
|
||||
if (log) {
|
||||
g_assert(write(2, &c, 1) == 1);
|
||||
}
|
||||
json_message_parser_feed(&qmp.parser, &c, 1);
|
||||
}
|
||||
if (log) {
|
||||
g_assert(write(2, "\n", 1) == 1);
|
||||
}
|
||||
json_message_parser_destroy(&qmp.parser);
|
||||
|
||||
return qmp.response;
|
||||
}
|
||||
|
||||
QDict *qtest_qmp_receive(QTestState *s)
|
||||
{
|
||||
while (true) {
|
||||
|
@ -664,50 +571,6 @@ int qtest_socket_server(const char *socket_path)
|
|||
return sock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow users to send a message without waiting for the reply,
|
||||
* in the case that they choose to discard all replies up until
|
||||
* a particular EVENT is received.
|
||||
*/
|
||||
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
QObject *qobj;
|
||||
|
||||
/* Going through qobject ensures we escape strings properly */
|
||||
qobj = qobject_from_vjsonf_nofail(fmt, ap);
|
||||
|
||||
/* No need to send anything for an empty QObject. */
|
||||
if (qobj) {
|
||||
int log = getenv("QTEST_LOG") != NULL;
|
||||
GString *str = qobject_to_json(qobj);
|
||||
|
||||
/*
|
||||
* BUG: QMP doesn't react to input until it sees a newline, an
|
||||
* object, or an array. Work-around: give it a newline.
|
||||
*/
|
||||
g_string_append_c(str, '\n');
|
||||
|
||||
if (log) {
|
||||
fprintf(stderr, "%s", str->str);
|
||||
}
|
||||
/* Send QMP request */
|
||||
if (fds && fds_num > 0) {
|
||||
socket_send_fds(fd, fds, fds_num, str->str, str->len);
|
||||
} else {
|
||||
socket_send(fd, str->str, str->len);
|
||||
}
|
||||
|
||||
g_string_free(str, true);
|
||||
qobject_unref(qobj);
|
||||
}
|
||||
}
|
||||
|
||||
void qmp_fd_vsend(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||
}
|
||||
|
||||
void qtest_qmp_vsend_fds(QTestState *s, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
|
@ -719,13 +582,6 @@ void qtest_qmp_vsend(QTestState *s, const char *fmt, va_list ap)
|
|||
qmp_fd_vsend_fds(s->qmp_fd, NULL, 0, fmt, ap);
|
||||
}
|
||||
|
||||
QDict *qmp_fdv(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
qmp_fd_vsend_fds(fd, NULL, 0, fmt, ap);
|
||||
|
||||
return qmp_fd_receive(fd);
|
||||
}
|
||||
|
||||
QDict *qtest_vqmp_fds(QTestState *s, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
|
@ -743,26 +599,6 @@ QDict *qtest_vqmp(QTestState *s, const char *fmt, va_list ap)
|
|||
return qtest_qmp_receive(s);
|
||||
}
|
||||
|
||||
QDict *qmp_fd(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
QDict *response;
|
||||
|
||||
va_start(ap, fmt);
|
||||
response = qmp_fdv(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
return response;
|
||||
}
|
||||
|
||||
void qmp_fd_send(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
qmp_fd_vsend(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
QDict *qtest_qmp_fds(QTestState *s, int *fds, size_t fds_num,
|
||||
const char *fmt, ...)
|
||||
{
|
||||
|
@ -795,27 +631,6 @@ void qtest_qmp_send(QTestState *s, const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap)
|
||||
{
|
||||
bool log = getenv("QTEST_LOG") != NULL;
|
||||
char *str = g_strdup_vprintf(fmt, ap);
|
||||
|
||||
if (log) {
|
||||
fprintf(stderr, "%s", str);
|
||||
}
|
||||
socket_send(fd, str, strlen(str));
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
void qmp_fd_send_raw(int fd, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
qmp_fd_vsend_raw(fd, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void qtest_qmp_send_raw(QTestState *s, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -1539,24 +1354,6 @@ void qtest_qmp_device_del(QTestState *qts, const char *id)
|
|||
qtest_qmp_eventwait(qts, "DEVICE_DELETED");
|
||||
}
|
||||
|
||||
bool qmp_rsp_is_err(QDict *rsp)
|
||||
{
|
||||
QDict *error = qdict_get_qdict(rsp, "error");
|
||||
qobject_unref(rsp);
|
||||
return !!error;
|
||||
}
|
||||
|
||||
void qmp_expect_error_and_unref(QDict *rsp, const char *class)
|
||||
{
|
||||
QDict *error = qdict_get_qdict(rsp, "error");
|
||||
|
||||
g_assert_cmpstr(qdict_get_try_str(error, "class"), ==, class);
|
||||
g_assert_nonnull(qdict_get_try_str(error, "desc"));
|
||||
g_assert(!qdict_haskey(rsp, "return"));
|
||||
|
||||
qobject_unref(rsp);
|
||||
}
|
||||
|
||||
static void qtest_client_set_tx_handler(QTestState *s,
|
||||
QTestSendFn send)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#include "qapi/qmp/qobject.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "libqmp.h"
|
||||
|
||||
typedef struct QTestState QTestState;
|
||||
|
||||
|
@ -690,16 +691,6 @@ void qtest_remove_abrt_handler(void *data);
|
|||
void qtest_qmp_assert_success(QTestState *qts, const char *fmt, ...)
|
||||
G_GNUC_PRINTF(2, 3);
|
||||
|
||||
QDict *qmp_fd_receive(int fd);
|
||||
void qmp_fd_vsend_fds(int fd, int *fds, size_t fds_num,
|
||||
const char *fmt, va_list ap) G_GNUC_PRINTF(4, 0);
|
||||
void qmp_fd_vsend(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
void qmp_fd_send(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
void qmp_fd_send_raw(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
void qmp_fd_vsend_raw(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
QDict *qmp_fdv(int fd, const char *fmt, va_list ap) G_GNUC_PRINTF(2, 0);
|
||||
QDict *qmp_fd(int fd, const char *fmt, ...) G_GNUC_PRINTF(2, 3);
|
||||
|
||||
/**
|
||||
* qtest_cb_for_every_machine:
|
||||
* @cb: Pointer to the callback function
|
||||
|
@ -771,24 +762,6 @@ void qtest_qmp_add_client(QTestState *qts, const char *protocol, int fd);
|
|||
*/
|
||||
void qtest_qmp_device_del(QTestState *qts, const char *id);
|
||||
|
||||
/**
|
||||
* qmp_rsp_is_err:
|
||||
* @rsp: QMP response to check for error
|
||||
*
|
||||
* Test @rsp for error and discard @rsp.
|
||||
* Returns 'true' if there is error in @rsp and 'false' otherwise.
|
||||
*/
|
||||
bool qmp_rsp_is_err(QDict *rsp);
|
||||
|
||||
/**
|
||||
* qmp_expect_error_and_unref:
|
||||
* @rsp: QMP response to check for error
|
||||
* @class: an error class
|
||||
*
|
||||
* Assert the response has the given error class and discard @rsp.
|
||||
*/
|
||||
void qmp_expect_error_and_unref(QDict *rsp, const char *class);
|
||||
|
||||
/**
|
||||
* qtest_probe_child:
|
||||
* @s: QTestState instance to operate on.
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
static void test_lp1878642_pci_bus_get_irq_level_assert(void)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
#define RTC_SECONDS 0x9
|
||||
#define RTC_MINUTES 0xa
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "qemu/osdep.h"
|
||||
|
||||
#include "qemu/cutils.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
#include "qemu/bswap.h"
|
||||
#include "qemu/module.h"
|
||||
#include "libqos/qgraph.h"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
#include "qemu/osdep.h"
|
||||
#include "exec/hwaddr.h"
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
#include "hw/arm/nrf51.h"
|
||||
#include "hw/char/nrf51_uart.h"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#ifndef MIGRATION_HELPERS_H_
|
||||
#define MIGRATION_HELPERS_H_
|
||||
|
||||
#include "libqos/libqtest.h"
|
||||
#include "libqtest.h"
|
||||
|
||||
extern bool got_stop;
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue