From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Huth <thuth@redhat.com>
Subject: [PATCH 3/7] tests/qtest: failover: check the feature is correctly provided
Date: Thu, 3 Feb 2022 15:15:33 +0100 [thread overview]
Message-ID: <20220203141537.972317-4-lvivier@redhat.com> (raw)
In-Reply-To: <20220203141537.972317-1-lvivier@redhat.com>
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>
---
tests/qtest/virtio-net-failover.c | 139 ++++++++++++++++++------------
1 file changed, 86 insertions(+), 53 deletions(-)
diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index 070e53de1292..42367963685c 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);
--
2.34.1
next prev parent reply other threads:[~2022-02-03 14:28 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 14:15 [PATCH 0/7] tests/qtest: add some tests for virtio-net failover (part 2) Laurent Vivier
2022-02-03 14:15 ` [PATCH 1/7] tests/qtest: failover: clean up pathname of tests Laurent Vivier
2022-02-03 14:15 ` [PATCH 2/7] tests/qtest: failover: use a macro for check_one_card() Laurent Vivier
2022-02-03 14:15 ` Laurent Vivier [this message]
2022-02-03 14:15 ` [PATCH 4/7] tests/qtest: failover: check missing guest feature Laurent Vivier
2022-02-03 14:15 ` [PATCH 5/7] tests/qtest: failover: check migration with failover off Laurent Vivier
2022-02-03 14:15 ` [PATCH 6/7] tests/qtest: failover: test migration if the guest doesn't support failover Laurent Vivier
2022-02-03 14:15 ` [PATCH 7/7] tests/qtest: failover: migration abort test with failover off Laurent Vivier
2022-02-15 9:20 ` [PATCH 0/7] tests/qtest: add some tests for virtio-net failover (part 2) Laurent Vivier
2022-02-21 9:17 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220203141537.972317-4-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).