From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: Laurent Vivier <lvivier@redhat.com>,
Richard Henderson <richard.henderson@linaro.org>
Subject: [PULL 03/16] tests/libqtest: add some virtio-net failover migration cancelling tests
Date: Wed, 15 Dec 2021 08:33:49 +0100 [thread overview]
Message-ID: <20211215073402.144286-4-thuth@redhat.com> (raw)
In-Reply-To: <20211215073402.144286-1-thuth@redhat.com>
From: Laurent Vivier <lvivier@redhat.com>
Add some tests to check the state of the machine if the migration
is cancelled while we are using virtio-net failover.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20211208130350.10178-4-lvivier@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
tests/qtest/virtio-net-failover.c | 282 ++++++++++++++++++++++++++++++
1 file changed, 282 insertions(+)
diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c
index fd7821deaf..e998a546b0 100644
--- a/tests/qtest/virtio-net-failover.c
+++ b/tests/qtest/virtio-net-failover.c
@@ -752,6 +752,280 @@ static void test_migrate_in(gconstpointer opaque)
machine_stop(qts);
}
+static void test_migrate_abort_wait_unplug(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': 'on',"
+ "'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");
+
+ 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);
+
+ /* the event is sent when QEMU asks the OS to unplug the card */
+ resp = get_unplug_primary_event(qts);
+ g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "primary0");
+ qobject_unref(resp);
+
+ resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }");
+ g_assert(qdict_haskey(resp, "return"));
+ qobject_unref(resp);
+
+ /* migration has been cancelled while the unplug was in progress */
+
+ /* while the card is not ejected, we must be in "cancelling" state */
+ ret = migrate_status(qts);
+
+ status = qdict_get_str(ret, "status");
+ g_assert_cmpstr(status, ==, "cancelling");
+ qobject_unref(ret);
+
+ /* OS unplugs the cards, QEMU can move from wait-unplug state */
+ qtest_outl(qts, ACPI_PCIHP_ADDR_ICH9 + PCI_EJ_BASE, 1);
+
+ 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_active(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': 'on',"
+ "'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");
+
+ 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);
+
+ /* the event is sent when QEMU asks the OS to unplug the card */
+ resp = get_unplug_primary_event(qts);
+ g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "primary0");
+ qobject_unref(resp);
+
+ /* OS unplugs the cards, QEMU can move from wait-unplug state */
+ qtest_outl(qts, ACPI_PCIHP_ADDR_ICH9 + PCI_EJ_BASE, 1);
+
+ while (true) {
+ ret = migrate_status(qts);
+
+ status = qdict_get_str(ret, "status");
+ if (strcmp(status, "wait-unplug") != 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;
+ QDict *resp, *args, *ret;
+ g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque);
+ const gchar *status;
+ int total;
+ 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': 'on',"
+ "'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");
+
+ 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);
+
+ /* the event is sent when QEMU asks the OS to unplug the card */
+ resp = get_unplug_primary_event(qts);
+ g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "primary0");
+ qobject_unref(resp);
+
+ resp = qtest_qmp(qts, "{ 'execute': 'migrate_cancel' }");
+ g_assert(qdict_haskey(resp, "return"));
+ qobject_unref(resp);
+
+ /* migration has been cancelled while the unplug was in progress */
+
+ /* while the card is not ejected, we must be in "cancelling" state */
+
+ total = 0;
+ 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, ==, "cancelling");
+ g_assert(qdict_haskey(ret, "total-time"));
+ total = qdict_get_int(ret, "total-time");
+ qobject_unref(ret);
+ }
+
+ /*
+ * migration timeout in this case is 30 seconds
+ * check we exit on the timeout (ms)
+ */
+ g_assert_cmpint(total, >, 30000);
+
+ check_one_card(qts, true, "standby0", MAC_STANDBY0);
+ check_one_card(qts, true, "primary0", MAC_PRIMARY0);
+
+ qos_object_destroy((QOSGraphObject *)vdev);
+ machine_stop(qts);
+}
+
int main(int argc, char **argv)
{
const gchar *tmpdir = g_get_tmp_dir();
@@ -778,6 +1052,14 @@ int main(int argc, char **argv)
test_migrate_out);
qtest_add_data_func("failover-virtio-net/migrate/in", tmpfile,
test_migrate_in);
+ 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,
+ test_migrate_abort_active);
+ if (g_test_slow()) {
+ qtest_add_data_func("failover-virtio-net/migrate/abort/timeout",
+ tmpfile, test_migrate_abort_timeout);
+ }
ret = g_test_run();
--
2.27.0
next prev parent reply other threads:[~2021-12-15 7:44 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-15 7:33 [PULL 00/16] qtest and gitlab-CI improvements Thomas Huth
2021-12-15 7:33 ` [PULL 01/16] qtest/libqos: add a function to initialize secondary PCI buses Thomas Huth
2021-12-15 7:33 ` [PULL 02/16] tests/qtest: add some tests for virtio-net failover Thomas Huth
2021-12-15 7:33 ` Thomas Huth [this message]
2021-12-15 7:33 ` [PULL 04/16] tests/libqtest: add a migration test with two couples of failover devices Thomas Huth
2021-12-15 7:33 ` [PULL 05/16] tests/qtest: Run the PPC 32-bit tests with the 64-bit target binary, too Thomas Huth
2021-12-15 7:33 ` [PULL 06/16] tests/qtest: Fence the tests that need xlnx-zcu102 with CONFIG_XLNX_ZYNQMP_ARM Thomas Huth
2021-12-15 7:33 ` [PULL 07/16] tests/qtest: Add a function that gets a list with available machine types Thomas Huth
2021-12-15 7:33 ` [PULL 08/16] tests/qtest: Add a function to check whether a machine is available Thomas Huth
2021-12-15 7:33 ` [PULL 09/16] Move the libssh setup from configure to meson.build Thomas Huth
2021-12-15 7:33 ` [PULL 10/16] gitlab-ci.d/buildtest: Add jobs that run the device-crash-test Thomas Huth
2021-12-15 7:33 ` [PULL 11/16] gitlab-ci: Add cirrus-ci based tests for NetBSD and OpenBSD Thomas Huth
2021-12-15 7:33 ` [PULL 12/16] virtio-iommu: Remove set_config callback Thomas Huth
2021-12-15 7:33 ` [PULL 13/16] virtio-iommu: Fix endianness in get_config Thomas Huth
2021-12-15 7:34 ` [PULL 14/16] virtio-iommu: Fix the domain_range end Thomas Huth
2021-12-15 7:34 ` [PULL 15/16] tests: qtest: Add virtio-iommu test Thomas Huth
2021-12-15 7:34 ` [PULL 16/16] gitlab-ci: Test compilation on Windows with MSYS2 Thomas Huth
2021-12-15 17:14 ` [PULL 00/16] qtest and gitlab-CI improvements Richard Henderson
2021-12-15 20:33 ` Thomas Huth
2021-12-18 16:33 ` Philippe Mathieu-Daudé
2021-12-20 6:52 ` Thomas Huth
2021-12-20 9:24 ` Philippe Mathieu-Daudé
2021-12-20 9:53 ` Thomas Huth
2021-12-20 13:11 ` Philippe Mathieu-Daudé
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=20211215073402.144286-4-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=lvivier@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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).