diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2022-02-22 13:07:32 +0000 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2022-02-22 13:07:32 +0000 |
commit | 5abccc7922ca5291327b0a1e84ace526d97c633b (patch) | |
tree | ab8a35d147f5b5ed55205247e9eda5f5632d2731 /tests | |
parent | 922268067fe4181d6edcfccd689e908e4d1243ad (diff) | |
parent | 975592f5523fdf8708e4b53da937cf4805b1b79a (diff) | |
download | qemu-5abccc7922ca5291327b0a1e84ace526d97c633b.zip qemu-5abccc7922ca5291327b0a1e84ace526d97c633b.tar.gz qemu-5abccc7922ca5291327b0a1e84ace526d97c633b.tar.bz2 |
Merge remote-tracking branch 'remotes/thuth-gitlab/tags/pull-request-2022-02-21' into staging
* Improve virtio-net failover test
* Some small fixes for the qtests
* Misc header cleanups by Philippe
# gpg: Signature made Mon 21 Feb 2022 11:40:37 GMT
# gpg: using RSA key 27B88847EEE0250118F3EAB92ED9D774FE702DB5
# gpg: issuer "thuth@redhat.com"
# gpg: Good signature from "Thomas Huth <th.huth@gmx.de>" [full]
# gpg: aka "Thomas Huth <thuth@redhat.com>" [full]
# gpg: aka "Thomas Huth <huth@tuxfamily.org>" [full]
# gpg: aka "Thomas Huth <th.huth@posteo.de>" [unknown]
# Primary key fingerprint: 27B8 8847 EEE0 2501 18F3 EAB9 2ED9 D774 FE70 2DB5
* remotes/thuth-gitlab/tags/pull-request-2022-02-21: (25 commits)
hw/tricore: Remove unused and incorrect header
hw/m68k/mcf: Add missing 'exec/hwaddr.h' header
exec/exec-all: Move 'qemu/log.h' include in units requiring it
softmmu/runstate: Clean headers
linux-user: Add missing "qemu/timer.h" include
target: Add missing "qemu/timer.h" include
core/ptimers: Remove unnecessary 'sysemu/cpus.h' include
exec/ramblock: Add missing includes
qtest: Add missing 'hw/qdev-core.h' include
hw/acpi/memory_hotplug: Remove unused 'hw/acpi/pc-hotplug.h' header
hw/remote: Add missing include
hw/tpm: Clean includes
scripts: Remove the old switch-timer-api script
tests/qtest: failover: migration abort test with failover off
tests/qtest: failover: test migration if the guest doesn't support failover
tests/qtest: failover: check migration with failover off
tests/qtest: failover: check missing guest feature
tests/qtest: failover: check the feature is correctly provided
tests/qtest: failover: use a macro for check_one_card()
tests/qtest: failover: clean up pathname of tests
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/qtest/device-plug-test.c | 20 | ||||
-rw-r--r-- | tests/qtest/drive_del-test.c | 35 | ||||
-rw-r--r-- | tests/qtest/erst-test.c | 2 | ||||
-rw-r--r-- | tests/qtest/fdc-test.c | 2 | ||||
-rw-r--r-- | tests/qtest/hd-geo-test.c | 16 | ||||
-rw-r--r-- | tests/qtest/i440fx-test.c | 2 | ||||
-rw-r--r-- | tests/qtest/ide-test.c | 16 | ||||
-rw-r--r-- | tests/qtest/ivshmem-test.c | 7 | ||||
-rw-r--r-- | tests/qtest/vhost-user-test.c | 2 | ||||
-rw-r--r-- | tests/qtest/virtio-net-failover.c | 671 |
10 files changed, 668 insertions, 105 deletions
diff --git a/tests/qtest/device-plug-test.c b/tests/qtest/device-plug-test.c index ad79bd4..404a92e 100644 --- a/tests/qtest/device-plug-test.c +++ b/tests/qtest/device-plug-test.c @@ -63,7 +63,15 @@ static void wait_device_deleted_event(QTestState *qtest, const char *id) static void test_pci_unplug_request(void) { - QTestState *qtest = qtest_initf("-device virtio-mouse-pci,id=dev0"); + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } + + QTestState *qtest = qtest_initf("%s -device virtio-mouse-pci,id=dev0", + machine_addition); /* * Request device removal. As the guest is not running, the request won't @@ -79,8 +87,16 @@ static void test_pci_unplug_request(void) static void test_pci_unplug_json_request(void) { + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } + QTestState *qtest = qtest_initf( - "-device '{\"driver\": \"virtio-mouse-pci\", \"id\": \"dev0\"}'"); + "%s -device '{\"driver\": \"virtio-mouse-pci\", \"id\": \"dev0\"}'", + machine_addition); /* * Request device removal. As the guest is not running, the request won't diff --git a/tests/qtest/drive_del-test.c b/tests/qtest/drive_del-test.c index 8d08ee9..0cc18df 100644 --- a/tests/qtest/drive_del-test.c +++ b/tests/qtest/drive_del-test.c @@ -235,14 +235,21 @@ static void test_drive_del_device_del(void) static void test_cli_device_del(void) { QTestState *qts; + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } /* * -drive/-device and device_del. Start with a drive used by a * device that unplugs after reset. */ - qts = qtest_initf("-drive if=none,id=drive0,file=null-co://," + qts = qtest_initf("%s -drive if=none,id=drive0,file=null-co://," "file.read-zeroes=on,format=raw" " -device virtio-blk-%s,drive=drive0,id=dev0", + machine_addition, qvirtio_get_dev_type()); device_del(qts, true); @@ -266,13 +273,19 @@ static void test_empty_device_del(void) static void test_device_add_and_del(void) { QTestState *qts; + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } /* * -drive/device_add and device_del. Start with a drive used by a * device that unplugs after reset. */ - qts = qtest_init("-drive if=none,id=drive0,file=null-co://," - "file.read-zeroes=on,format=raw"); + qts = qtest_initf("%s -drive if=none,id=drive0,file=null-co://," + "file.read-zeroes=on,format=raw", machine_addition); device_add(qts); device_del(qts, true); @@ -284,8 +297,14 @@ static void test_device_add_and_del(void) static void test_drive_add_device_add_and_del(void) { QTestState *qts; + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } - qts = qtest_init(""); + qts = qtest_init(machine_addition); /* * drive_add/device_add and device_del. The drive is used by a @@ -302,8 +321,14 @@ static void test_drive_add_device_add_and_del(void) static void test_blockdev_add_device_add_and_del(void) { QTestState *qts; + const char *arch = qtest_get_arch(); + const char *machine_addition = ""; + + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + machine_addition = "-machine pc"; + } - qts = qtest_init(""); + qts = qtest_init(machine_addition); /* * blockdev_add/device_add and device_del. The it drive is used by a diff --git a/tests/qtest/erst-test.c b/tests/qtest/erst-test.c index c6a0ae4..f94cd8d 100644 --- a/tests/qtest/erst-test.c +++ b/tests/qtest/erst-test.c @@ -75,7 +75,7 @@ static inline uint64_t in_reg64(ERSTState *s, unsigned reg) uint64_t res; res = qpci_io_readq(s->dev, s->reg_bar, reg); - g_test_message("*%s -> %016llx", name, (unsigned long long)res); + g_test_message("*%s -> %016" PRIx64, name, res); return res; } diff --git a/tests/qtest/fdc-test.c b/tests/qtest/fdc-test.c index 8f6eee8..b0d4001 100644 --- a/tests/qtest/fdc-test.c +++ b/tests/qtest/fdc-test.c @@ -598,7 +598,7 @@ int main(int argc, char **argv) /* Run the tests */ g_test_init(&argc, &argv, NULL); - qtest_start("-device floppy,id=floppy0"); + qtest_start("-machine pc -device floppy,id=floppy0"); qtest_irq_intercept_in(global_qtest, "ioapic"); qtest_add_func("/fdc/cmos", test_cmos); qtest_add_func("/fdc/no_media_on_start", test_no_media_on_start); diff --git a/tests/qtest/hd-geo-test.c b/tests/qtest/hd-geo-test.c index 771eaa7..64023c0 100644 --- a/tests/qtest/hd-geo-test.c +++ b/tests/qtest/hd-geo-test.c @@ -178,9 +178,15 @@ static int append_arg(int argc, char *argv[], int argv_sz, char *arg) static int setup_common(char *argv[], int argv_sz) { + int new_argc; memset(cur_ide, 0, sizeof(cur_ide)); - return append_arg(0, argv, argv_sz, - g_strdup("-nodefaults")); + new_argc = append_arg(0, argv, argv_sz, + g_strdup("-nodefaults")); + new_argc = append_arg(new_argc, argv, argv_sz, + g_strdup("-machine")); + new_argc = append_arg(new_argc, argv, argv_sz, + g_strdup("pc")); + return new_argc; } static void setup_mbr(int img_idx, MBRcontents mbr) @@ -697,7 +703,7 @@ static void test_override(TestArgs *args, CHSResult expected[]) joined_args = g_strjoinv(" ", args->argv); - qts = qtest_init(joined_args); + qts = qtest_initf("-machine pc %s", joined_args); fw_cfg = pc_fw_cfg_init(qts); read_bootdevices(fw_cfg, expected); @@ -833,7 +839,7 @@ static void test_override_scsi_hot_unplug(void) joined_args = g_strjoinv(" ", args->argv); - qts = qtest_init(joined_args); + qts = qtest_initf("-machine pc %s", joined_args); fw_cfg = pc_fw_cfg_init(qts); read_bootdevices(fw_cfg, expected); @@ -893,7 +899,7 @@ static void test_override_virtio_hot_unplug(void) joined_args = g_strjoinv(" ", args->argv); - qts = qtest_init(joined_args); + qts = qtest_initf("-machine pc %s", joined_args); fw_cfg = pc_fw_cfg_init(qts); read_bootdevices(fw_cfg, expected); diff --git a/tests/qtest/i440fx-test.c b/tests/qtest/i440fx-test.c index 1f57d96..6d7d4d8 100644 --- a/tests/qtest/i440fx-test.c +++ b/tests/qtest/i440fx-test.c @@ -35,7 +35,7 @@ static QPCIBus *test_start_get_bus(const TestData *s) { char *cmdline; - cmdline = g_strdup_printf("-smp %d", s->num_cpus); + cmdline = g_strdup_printf("-machine pc -smp %d", s->num_cpus); qtest_start(cmdline); g_free(cmdline); return qpci_new_pc(global_qtest, NULL); diff --git a/tests/qtest/ide-test.c b/tests/qtest/ide-test.c index 3f8081e..19de3b4 100644 --- a/tests/qtest/ide-test.c +++ b/tests/qtest/ide-test.c @@ -128,10 +128,11 @@ static char debug_path[] = "/tmp/qtest-blkdebug.XXXXXX"; static QTestState *ide_test_start(const char *cmdline_fmt, ...) { QTestState *qts; + g_autofree char *full_fmt = g_strdup_printf("-machine pc %s", cmdline_fmt); va_list ap; va_start(ap, cmdline_fmt); - qts = qtest_vinitf(cmdline_fmt, ap); + qts = qtest_vinitf(full_fmt, ap); va_end(ap); pc_alloc_init(&guest_malloc, qts, 0); @@ -701,7 +702,7 @@ static void test_flush(void) free_pci_device(dev); } -static void test_retry_flush(const char *machine) +static void test_pci_retry_flush(void) { QTestState *qts; QPCIDevice *dev; @@ -790,16 +791,6 @@ static void test_flush_empty_drive(void) ide_test_quit(qts); } -static void test_pci_retry_flush(void) -{ - test_retry_flush("pc"); -} - -static void test_isa_retry_flush(void) -{ - test_retry_flush("isapc"); -} - typedef struct Read10CDB { uint8_t opcode; uint8_t flags; @@ -1050,7 +1041,6 @@ int main(int argc, char **argv) qtest_add_func("/ide/flush/nodev", test_flush_nodev); qtest_add_func("/ide/flush/empty_drive", test_flush_empty_drive); qtest_add_func("/ide/flush/retry_pci", test_pci_retry_flush); - qtest_add_func("/ide/flush/retry_isa", test_isa_retry_flush); qtest_add_func("/ide/cdrom/pio", test_cdrom_pio); qtest_add_func("/ide/cdrom/pio_large", test_cdrom_pio_large); diff --git a/tests/qtest/ivshmem-test.c b/tests/qtest/ivshmem-test.c index fe94dd3..4e8af42 100644 --- a/tests/qtest/ivshmem-test.c +++ b/tests/qtest/ivshmem-test.c @@ -385,7 +385,12 @@ static void test_ivshmem_hotplug(void) QTestState *qts; const char *arch = qtest_get_arch(); - qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1"); + if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) { + qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1" + " -machine pc"); + } else { + qts = qtest_init("-object memory-backend-ram,size=1M,id=mb1"); + } qtest_qmp_device_add(qts, "ivshmem-plain", "iv1", "{'addr': %s, 'memdev': 'mb1'}", diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 2a4568c..ee30f54 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -42,7 +42,7 @@ #define QEMU_CMD_MEMFD " -m %d -object memory-backend-memfd,id=mem,size=%dM," \ " -numa node,memdev=mem" #define QEMU_CMD_CHR " -chardev socket,id=%s,path=%s%s" -#define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce" +#define QEMU_CMD_NETDEV " -netdev vhost-user,id=hs0,chardev=%s,vhostforce=on" #define HUGETLBFS_MAGIC 0x958458f6 diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c index 22ad54b..80292ee 100644 --- a/tests/qtest/virtio-net-failover.c +++ b/tests/qtest/virtio-net-failover.c @@ -18,6 +18,8 @@ #include "libqos/virtio-pci.h" #include "hw/pci/pci.h" +#define VIRTIO_NET_F_STANDBY 62 + #define ACPI_PCIHP_ADDR_ICH9 0x0cc0 #define PCI_EJ_BASE 0x0008 #define PCI_SEL_BASE 0x0010 @@ -224,31 +226,85 @@ static char *get_mac(QTestState *qts, const char *name) return mac; } -static void check_one_card(QTestState *qts, bool present, - const char *id, const char *mac) +#define check_one_card(qts, present, id, mac) \ +do { \ + QDict *device; \ + QDict *bus; \ + char *addr; \ + bus = get_bus(qts, 0); \ + device = find_device(bus, id); \ + if (present) { \ + char *path; \ + g_assert_nonnull(device); \ + qobject_unref(device); \ + path = g_strdup_printf("/machine/peripheral/%s", id); \ + addr = get_mac(qts, path); \ + g_free(path); \ + g_assert_cmpstr(mac, ==, addr); \ + g_free(addr); \ + } else { \ + g_assert_null(device); \ + } \ + qobject_unref(bus); \ +} while (0) + +static QDict *get_failover_negociated_event(QTestState *qts) { - QDict *device; - QDict *bus; - char *addr; + QDict *resp; + QDict *data; - bus = get_bus(qts, 0); - device = find_device(bus, id); - if (present) { - char *path; + resp = qtest_qmp_eventwait_ref(qts, "FAILOVER_NEGOTIATED"); + g_assert(qdict_haskey(resp, "data")); - g_assert_nonnull(device); - qobject_unref(device); + data = qdict_get_qdict(resp, "data"); + g_assert(qdict_haskey(data, "device-id")); + qobject_ref(data); + qobject_unref(resp); - path = g_strdup_printf("/machine/peripheral/%s", id); - addr = get_mac(qts, path); - g_free(path); - g_assert_cmpstr(mac, ==, addr); - g_free(addr); - } else { - g_assert_null(device); + return data; +} + +static QVirtioPCIDevice *start_virtio_net_internal(QTestState *qts, + int bus, int slot, + uint64_t *features) +{ + QVirtioPCIDevice *dev; + QPCIAddress addr; + + addr.devfn = QPCI_DEVFN((bus << 5) + slot, 0); + dev = virtio_pci_new(pcibus, &addr); + g_assert_nonnull(dev); + qvirtio_pci_device_enable(dev); + qvirtio_start_device(&dev->vdev); + *features &= qvirtio_get_features(&dev->vdev); + qvirtio_set_features(&dev->vdev, *features); + qvirtio_set_driver_ok(&dev->vdev); + return dev; +} + +static QVirtioPCIDevice *start_virtio_net(QTestState *qts, int bus, int slot, + const char *id, bool failover) +{ + QVirtioPCIDevice *dev; + uint64_t features; + + features = ~(QVIRTIO_F_BAD_FEATURE | + (1ull << VIRTIO_RING_F_INDIRECT_DESC) | + (1ull << VIRTIO_RING_F_EVENT_IDX)); + + dev = start_virtio_net_internal(qts, bus, slot, &features); + + g_assert(!!(features & (1ull << VIRTIO_NET_F_STANDBY)) == failover); + + if (failover) { + QDict *resp; + + resp = get_failover_negociated_event(qts); + g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, id); + qobject_unref(resp); } - qobject_unref(bus); + return dev; } static void test_on(void) @@ -259,6 +315,7 @@ static void test_on(void) "-netdev user,id=hs0 " "-device virtio-net,bus=root0,id=standby0," "failover=on,netdev=hs0,mac="MAC_STANDBY0" " + "-netdev user,id=hs1 " "-device virtio-net,bus=root1,id=primary0," "failover_pair_id=standby0,netdev=hs1,mac="MAC_PRIMARY0, 2); @@ -272,6 +329,7 @@ static void test_on(void) static void test_on_mismatch(void) { QTestState *qts; + QVirtioPCIDevice *vdev; qts = machine_start(BASE_MACHINE "-netdev user,id=hs0 " @@ -285,12 +343,19 @@ static void test_on_mismatch(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + qos_object_destroy((QOSGraphObject *)vdev); machine_stop(qts); } static void test_off(void) { QTestState *qts; + QVirtioPCIDevice *vdev; qts = machine_start(BASE_MACHINE "-netdev user,id=hs0 " @@ -304,56 +369,46 @@ static void test_off(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); + vdev = start_virtio_net(qts, 1, 0, "standby0", false); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + qos_object_destroy((QOSGraphObject *)vdev); machine_stop(qts); } -static QDict *get_failover_negociated_event(QTestState *qts) +static void test_enabled(void) { - QDict *resp; - QDict *data; - - resp = qtest_qmp_eventwait_ref(qts, "FAILOVER_NEGOTIATED"); - g_assert(qdict_haskey(resp, "data")); - - data = qdict_get_qdict(resp, "data"); - g_assert(qdict_haskey(data, "device-id")); - qobject_ref(data); - qobject_unref(resp); + QTestState *qts; + QVirtioPCIDevice *vdev; - return data; -} + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-device virtio-net,bus=root0,id=standby0," + "failover=on,netdev=hs0,mac="MAC_STANDBY0" " + "-netdev user,id=hs1 " + "-device virtio-net,bus=root1,id=primary0," + "failover_pair_id=standby0,netdev=hs1,mac="MAC_PRIMARY0" ", + 2); -static QVirtioPCIDevice *start_virtio_net(QTestState *qts, int bus, int slot, - const char *id) -{ - QVirtioPCIDevice *dev; - uint64_t features; - QPCIAddress addr; - QDict *resp; + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); - addr.devfn = QPCI_DEVFN((bus << 5) + slot, 0); - dev = virtio_pci_new(pcibus, &addr); - g_assert_nonnull(dev); - qvirtio_pci_device_enable(dev); - qvirtio_start_device(&dev->vdev); - features = qvirtio_get_features(&dev->vdev); - features = features & ~(QVIRTIO_F_BAD_FEATURE | - (1ull << VIRTIO_RING_F_INDIRECT_DESC) | - (1ull << VIRTIO_RING_F_EVENT_IDX)); - qvirtio_set_features(&dev->vdev, features); - qvirtio_set_driver_ok(&dev->vdev); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); - resp = get_failover_negociated_event(qts); - g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, id); - qobject_unref(resp); + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); - return dev; + qos_object_destroy((QOSGraphObject *)vdev); + machine_stop(qts); } -static void test_enabled(void) +static void test_guest_off(void) { QTestState *qts; QVirtioPCIDevice *vdev; + uint64_t features; qts = machine_start(BASE_MACHINE "-netdev user,id=hs0 " @@ -367,10 +422,15 @@ static void test_enabled(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + features = ~(QVIRTIO_F_BAD_FEATURE | + (1ull << VIRTIO_RING_F_INDIRECT_DESC) | + (1ull << VIRTIO_RING_F_EVENT_IDX) | + (1ull << VIRTIO_NET_F_STANDBY)); + + vdev = start_virtio_net_internal(qts, 1, 0, &features); check_one_card(qts, true, "standby0", MAC_STANDBY0); - check_one_card(qts, true, "primary0", MAC_PRIMARY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); qos_object_destroy((QOSGraphObject *)vdev); machine_stop(qts); @@ -390,7 +450,7 @@ static void test_hotplug_1(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -432,7 +492,7 @@ static void test_hotplug_1_reverse(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); @@ -463,7 +523,7 @@ static void test_hotplug_2(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -519,7 +579,7 @@ static void test_hotplug_2_reverse(void) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); @@ -584,7 +644,7 @@ static void test_migrate_out(gconstpointer opaque) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -755,6 +815,364 @@ static void test_migrate_in(gconstpointer opaque) machine_stop(qts); } +static void test_off_migrate_out(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque); + const gchar *status; + QVirtioPCIDevice *vdev; + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'off'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + vdev = start_virtio_net(qts, 1, 0, "standby0", false); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "completed") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "cancelling"); + g_assert_cmpstr(status, !=, "cancelled"); + qobject_unref(ret); + } + + qtest_qmp_eventwait(qts, "STOP"); + + qos_object_destroy((QOSGraphObject *)vdev); + machine_stop(qts); +} + +static void test_off_migrate_in(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque); + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 " + "-incoming defer ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'off'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}", + args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + resp = get_migration_event(qts); + g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup"); + qobject_unref(resp); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + qtest_qmp_eventwait(qts, "RESUME"); + + ret = migrate_status(qts); + g_assert_cmpstr(qdict_get_str(ret, "status"), ==, "completed"); + qobject_unref(ret); + + machine_stop(qts); +} + +static void test_guest_off_migrate_out(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque); + const gchar *status; + QVirtioPCIDevice *vdev; + uint64_t features; + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'on'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + features = ~(QVIRTIO_F_BAD_FEATURE | + (1ull << VIRTIO_RING_F_INDIRECT_DESC) | + (1ull << VIRTIO_RING_F_EVENT_IDX) | + (1ull << VIRTIO_NET_F_STANDBY)); + + vdev = start_virtio_net_internal(qts, 1, 0, &features); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "completed") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "cancelling"); + g_assert_cmpstr(status, !=, "cancelled"); + qobject_unref(ret); + } + + qtest_qmp_eventwait(qts, "STOP"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qos_object_destroy((QOSGraphObject *)vdev); + machine_stop(qts); +} + +static void test_guest_off_migrate_in(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat %s", (gchar *)opaque); + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 " + "-incoming defer ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'on'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate-incoming', 'arguments': %p}", + args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + resp = get_migration_event(qts); + g_assert_cmpstr(qdict_get_str(resp, "status"), ==, "setup"); + qobject_unref(resp); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_eventwait(qts, "RESUME"); + + ret = migrate_status(qts); + g_assert_cmpstr(qdict_get_str(ret, "status"), ==, "completed"); + qobject_unref(ret); + + machine_stop(qts); +} + +static void test_migrate_guest_off_abort(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque); + const gchar *status; + QVirtioPCIDevice *vdev; + uint64_t features; + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'on'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + features = ~(QVIRTIO_F_BAD_FEATURE | + (1ull << VIRTIO_RING_F_INDIRECT_DESC) | + (1ull << VIRTIO_RING_F_EVENT_IDX) | + (1ull << VIRTIO_NET_F_STANDBY)); + + vdev = start_virtio_net_internal(qts, 1, 0, &features); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "active") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + qobject_unref(ret); + } + + resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "cancelled") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "active"); + qobject_unref(ret); + } + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qos_object_destroy((QOSGraphObject *)vdev); + machine_stop(qts); +} + static void test_migrate_abort_wait_unplug(gconstpointer opaque) { QTestState *qts; @@ -780,7 +1198,7 @@ static void test_migrate_abort_wait_unplug(gconstpointer opaque) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -870,7 +1288,7 @@ static void test_migrate_abort_active(gconstpointer opaque) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -938,6 +1356,91 @@ static void test_migrate_abort_active(gconstpointer opaque) machine_stop(qts); } +static void test_migrate_off_abort(gconstpointer opaque) +{ + QTestState *qts; + QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque); + const gchar *status; + QVirtioPCIDevice *vdev; + + qts = machine_start(BASE_MACHINE + "-netdev user,id=hs0 " + "-netdev user,id=hs1 ", + 2); + + check_one_card(qts, false, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "standby0", + "{'bus': 'root0'," + "'failover': 'off'," + "'netdev': 'hs0'," + "'mac': '"MAC_STANDBY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + vdev = start_virtio_net(qts, 1, 0, "standby0", false); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, false, "primary0", MAC_PRIMARY0); + + qtest_qmp_device_add(qts, "virtio-net", "primary0", + "{'bus': 'root1'," + "'failover_pair_id': 'standby0'," + "'netdev': 'hs1'," + "'rombar': 0," + "'romfile': ''," + "'mac': '"MAC_PRIMARY0"'}"); + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + args = qdict_from_jsonf_nofail("{}"); + g_assert_nonnull(args); + qdict_put_str(args, "uri", uri); + + resp = qtest_qmp(qts, "{ 'execute': 'migrate', 'arguments': %p}", args); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "active") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + qobject_unref(ret); + } + + resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }"); + g_assert(qdict_haskey(resp, "return")); + qobject_unref(resp); + + while (true) { + ret = migrate_status(qts); + + status = qdict_get_str(ret, "status"); + if (strcmp(status, "cancelled") == 0) { + qobject_unref(ret); + break; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "active"); + qobject_unref(ret); + } + + check_one_card(qts, true, "standby0", MAC_STANDBY0); + check_one_card(qts, true, "primary0", MAC_PRIMARY0); + + qos_object_destroy((QOSGraphObject *)vdev); + machine_stop(qts); +} + static void test_migrate_abort_timeout(gconstpointer opaque) { QTestState *qts; @@ -964,7 +1467,7 @@ static void test_migrate_abort_timeout(gconstpointer opaque) check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); - vdev = start_virtio_net(qts, 1, 0, "standby0"); + vdev = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, false, "primary0", MAC_PRIMARY0); @@ -1075,7 +1578,7 @@ static void test_multi_out(gconstpointer opaque) check_one_card(qts, false, "standby1", MAC_STANDBY1); check_one_card(qts, false, "primary1", MAC_PRIMARY1); - vdev0 = start_virtio_net(qts, 1, 0, "standby0"); + vdev0 = start_virtio_net(qts, 1, 0, "standby0", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); @@ -1106,7 +1609,7 @@ static void test_multi_out(gconstpointer opaque) check_one_card(qts, true, "standby1", MAC_STANDBY1); check_one_card(qts, false, "primary1", MAC_PRIMARY1); - vdev1 = start_virtio_net(qts, 3, 0, "standby1"); + vdev1 = start_virtio_net(qts, 3, 0, "standby1", true); check_one_card(qts, true, "standby0", MAC_STANDBY0); check_one_card(qts, true, "primary0", MAC_PRIMARY0); @@ -1315,6 +1818,7 @@ int main(int argc, char **argv) g_assert_true(ret >= 0); close(ret); + /* parameters tests */ qtest_add_func("failover-virtio-net/params/error/id", test_error_id); qtest_add_func("failover-virtio-net/params/error/pcie", test_error_pcie); qtest_add_func("failover-virtio-net/params/on", test_on); @@ -1322,16 +1826,33 @@ int main(int argc, char **argv) test_on_mismatch); qtest_add_func("failover-virtio-net/params/off", test_off); qtest_add_func("failover-virtio-net/params/enabled", test_enabled); - qtest_add_func("failover-virtio-net/hotplug_1", test_hotplug_1); - qtest_add_func("failover-virtio-net/hotplug_1_reverse", + qtest_add_func("failover-virtio-net/params/guest_off", test_guest_off); + + /* hotplug tests */ + qtest_add_func("failover-virtio-net/hotplug/1", test_hotplug_1); + qtest_add_func("failover-virtio-net/hotplug/1_reverse", test_hotplug_1_reverse); - qtest_add_func("failover-virtio-net/hotplug_2", test_hotplug_2); - qtest_add_func("failover-virtio-net/hotplug_2_reverse", + qtest_add_func("failover-virtio-net/hotplug/2", test_hotplug_2); + qtest_add_func("failover-virtio-net/hotplug/2_reverse", test_hotplug_2_reverse); - qtest_add_data_func("failover-virtio-net/migrate/out", tmpfile, + + /* migration tests */ + qtest_add_data_func("failover-virtio-net/migrate/on/out", tmpfile, test_migrate_out); - qtest_add_data_func("failover-virtio-net/migrate/in", tmpfile, + qtest_add_data_func("failover-virtio-net/migrate/on/in", tmpfile, test_migrate_in); + qtest_add_data_func("failover-virtio-net/migrate/off/out", tmpfile, + test_off_migrate_out); + qtest_add_data_func("failover-virtio-net/migrate/off/in", tmpfile, + test_off_migrate_in); + qtest_add_data_func("failover-virtio-net/migrate/off/abort", tmpfile, + test_migrate_off_abort); + qtest_add_data_func("failover-virtio-net/migrate/guest_off/out", tmpfile, + test_guest_off_migrate_out); + qtest_add_data_func("failover-virtio-net/migrate/guest_off/in", tmpfile, + test_guest_off_migrate_in); + qtest_add_data_func("failover-virtio-net/migrate/guest_off/abort", tmpfile, + test_migrate_guest_off_abort); qtest_add_data_func("failover-virtio-net/migrate/abort/wait-unplug", tmpfile, test_migrate_abort_wait_unplug); qtest_add_data_func("failover-virtio-net/migrate/abort/active", tmpfile, @@ -1340,9 +1861,9 @@ int main(int argc, char **argv) qtest_add_data_func("failover-virtio-net/migrate/abort/timeout", tmpfile, test_migrate_abort_timeout); } - qtest_add_data_func("failover-virtio-net/multi/out", + qtest_add_data_func("failover-virtio-net/migrate/multi/out", tmpfile, test_multi_out); - qtest_add_data_func("failover-virtio-net/multi/in", + qtest_add_data_func("failover-virtio-net/migrate/multi/in", tmpfile, test_multi_in); ret = g_test_run(); |