tests/qtest: failover: check the feature is correctly provided

Check QEMU provides the VIRTIO_NET_F_STANDBY if failover is on,
and doesn't if failover is off

Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Message-Id: <20220203141537.972317-4-lvivier@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Laurent Vivier 2022-02-03 15:15:33 +01:00 committed by Thomas Huth
parent 1a800870c5
commit 93262464d2

View File

@ -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
@ -246,62 +248,6 @@ do { \
qobject_unref(bus); \
} while (0)
static void test_on(void)
{
QTestState *qts;
qts = machine_start(BASE_MACHINE
"-netdev user,id=hs0 "
"-device virtio-net,bus=root0,id=standby0,"
"failover=on,netdev=hs0,mac="MAC_STANDBY0" "
"-device virtio-net,bus=root1,id=primary0,"
"failover_pair_id=standby0,netdev=hs1,mac="MAC_PRIMARY0,
2);
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
machine_stop(qts);
}
static void test_on_mismatch(void)
{
QTestState *qts;
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=standby1,netdev=hs1,mac="MAC_PRIMARY0,
2);
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
machine_stop(qts);
}
static void test_off(void)
{
QTestState *qts;
qts = machine_start(BASE_MACHINE
"-netdev user,id=hs0 "
"-device virtio-net,bus=root0,id=standby0,"
"failover=off,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);
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
machine_stop(qts);
}
static QDict *get_failover_negociated_event(QTestState *qts)
{
QDict *resp;
@ -318,33 +264,120 @@ static QDict *get_failover_negociated_event(QTestState *qts)
return data;
}
static QVirtioPCIDevice *start_virtio_net(QTestState *qts, int bus, int slot,
const char *id)
static QVirtioPCIDevice *start_virtio_net_internal(QTestState *qts,
int bus, int slot,
uint64_t *features)
{
QVirtioPCIDevice *dev;
uint64_t features;
QPCIAddress addr;
QDict *resp;
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);
*features &= qvirtio_get_features(&dev->vdev);
qvirtio_set_features(&dev->vdev, *features);
qvirtio_set_driver_ok(&dev->vdev);
return dev;
}
resp = get_failover_negociated_event(qts);
g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, id);
qobject_unref(resp);
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);
}
return dev;
}
static void test_on(void)
{
QTestState *qts;
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);
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, false, "primary0", MAC_PRIMARY0);
machine_stop(qts);
}
static void test_on_mismatch(void)
{
QTestState *qts;
QVirtioPCIDevice *vdev;
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=standby1,netdev=hs1,mac="MAC_PRIMARY0,
2);
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 "
"-device virtio-net,bus=root0,id=standby0,"
"failover=off,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);
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 void test_enabled(void)
{
QTestState *qts;
@ -362,7 +395,7 @@ 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");
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);
@ -385,7 +418,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);
@ -427,7 +460,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);
@ -458,7 +491,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);
@ -514,7 +547,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);
@ -579,7 +612,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);
@ -775,7 +808,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);
@ -865,7 +898,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);
@ -959,7 +992,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);
@ -1070,7 +1103,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);
@ -1101,7 +1134,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);