aboutsummaryrefslogtreecommitdiff
path: root/tests/qtest
diff options
context:
space:
mode:
Diffstat (limited to 'tests/qtest')
-rw-r--r--tests/qtest/virtio-net-failover.c139
1 files changed, 86 insertions, 53 deletions
diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 070e53de12..4236796368 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
@@ -246,6 +248,65 @@ do { \
qobject_unref(bus); \
} while (0)
+static QDict *get_failover_negociated_event(QTestState *qts)
+{
+ 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);
+
+ 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);
+ }
+
+ return dev;
+}
+
static void test_on(void)
{
QTestState *qts;
@@ -254,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);
@@ -267,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 "
@@ -280,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 "
@@ -299,50 +369,13 @@ static void test_off(void)
check_one_card(qts, true, "standby0", MAC_STANDBY0);
check_one_card(qts, true, "primary0", MAC_PRIMARY0);
- machine_stop(qts);
-}
+ vdev = start_virtio_net(qts, 1, 0, "standby0", false);
-static QDict *get_failover_negociated_event(QTestState *qts)
-{
- 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);
-
- return data;
-}
-
-static QVirtioPCIDevice *start_virtio_net(QTestState *qts, int bus, int slot,
- const char *id)
-{
- 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);
- qvirtio_set_driver_ok(&dev->vdev);
-
- 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)
@@ -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);