tests/qtest: add some tests for virtio-net failover
v7 cover tests/qtest: add some tests for virtio-net failover
This series adds a qtest entry to test virtio-net failover feature.
We check following error cases:
- check missing id on device with failover_pair_id triggers an error
- check a primary device plugged on a bus that doesn't support hotplug triggers an error
We check the status of the machine before and after hotplugging cards and feature negotiation:
- check we don't see the primary device at boot if failover is on
- check we see the primary device at boot if failover is off
- check we don't see the primary device if failover is on
but failover_pair_id is not the one with on (I think this should be changed)
- check the primary device is plugged after the feature negotiation
- check the result if the primary device is plugged before standby device and vice-versa
- check the if the primary device is coldplugged and the standy device hotplugged and vice-versa
- check the migration triggers the unplug and the hotplug
There is one preliminary patch in the series:
- PATCH 1 introduces a function to enable PCI bridge. Failover needs to be plugged on a pcie-root-port and while the root port is not configured the cards behind it are not available
v7:
- merge patch 3 and 4 as the fix for ACPI unplug has been merged
- address Thomas' comments
- add a dependency on slirp in meson.build
- check FAILOVER_NEGOCIATED device-id and MIGRATION status on destination, update UNPLUG_PRIMARY event checking
- fix an object_unref() in test_migrate_abort_active()
- fix typo s/whan/when/
v6:
- manage more than 2 root ports
- add a function to check if a card is available or not
- check migration state
- add cancelled migration test cases
- rename tests
v5:
- re-add the wait-unplug test that has been removed from v4 by mistake.
v4:
- rely on query-migrate status to know the migration state rather than to wait the STOP event.
- remove the patch to add time out to qtest_qmp_eventwait()
v3:
- fix a bug with ACPI unplug and add the related test
v2:
- remove PATCH 1 that introduced a function that can be replaced by qobject_to_json_pretty() (Markus)
- Add migration to a file and from the file to check the card is correctly unplugged on the source, and hotplugged on the dest
- Add an ACPI call to eject the card as the kernel would do
Laurent Vivier (4):
qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover test/libqtest: add some virtio-net failover migration cancelling tests tests/libqtest: add a migration test with two couples of failover
devices
include/hw/pci/pci_bridge.h | 8 + tests/qtest/libqos/pci.c | 118 +++ tests/qtest/libqos/pci.h | 1 + tests/qtest/meson.build | 4 + tests/qtest/virtio-net-failover.c | 1324 +++++++++++++++++++++++++++++ 5 files changed, 1455 insertions(+) create mode 100644 tests/qtest/virtio-net-failover.c
Signature · 1 line
2.33.1
PATCH v7 1/4 qtest/libqos: add a function to initialize secondary PCI buses
Scan the PCI devices to find bridge and set PCI_SECONDARY_BUS and PCI_SUBORDINATE_BUS (algorithm from seabios)
--- include/hw/pci/pci_bridge.h | 8 +++ tests/qtest/libqos/pci.c | 118 ++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/pci.h | 1 + 3 files changed, 127 insertions(+)
include/hw/pci/pci_bridge.h +8 -0
@@ -138,6 +138,7 @@ typedef struct PCIBridgeQemuCap {uint64_t mem_pref_64;/* Prefetchable memory to reserve (64-bit MMIO) */ } PCIBridgeQemuCap; +#define REDHAT_PCI_CAP_TYPE_OFFSET 3#define REDHAT_PCI_CAP_RESOURCE_RESERVE 1/*
@@ -152,6 +153,13 @@ typedef struct PCIResReserve {uint64_t mem_pref_64; } PCIResReserve; +#define REDHAT_PCI_CAP_RES_RESERVE_BUS_RES 4 +#define REDHAT_PCI_CAP_RES_RESERVE_IO 8 +#define REDHAT_PCI_CAP_RES_RESERVE_MEM 16 +#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_32 20 +#define REDHAT_PCI_CAP_RES_RESERVE_PREF_MEM_64 24 +#define REDHAT_PCI_CAP_RES_RESERVE_CAP_SIZE 32 +int pci_bridge_qemu_reserve_cap_init (PCIDevice *dev,int cap_offset,PCIResReserve res_reserve,Error **errp);
tests/qtest/libqos/pci.c +118 -0
130 lines not on this page · raw message
tests/qtest/libqos/pci.h +1 -0
@@ -81,6 +81,7 @@ void qpci_device_foreach(QPCIBus *bus, int vendor_id, int device_id, void *data);QPCIDevice *qpci_device_find (QPCIBus *bus,int devfn);void qpci_device_init (QPCIDevice *dev,QPCIBus *bus,QPCIAddress *addr); +int qpci_secondary_buses_init (QPCIBus *bus);bool qpci_has_buggy_msi (QPCIDevice *dev);bool qpci_check_buggy_msi (QPCIDevice *dev);
Signature · 1 line
2.33.1
PATCH v7 2/4 tests/qtest: add some tests for virtio-net failover
In reply to Laurent VivierAdd test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
--- tests/qtest/meson.build | 4 + tests/qtest/virtio-net-failover.c | 771 ++++++++++++++++++++++++++++++ 2 files changed, 775 insertions(+) create mode 100644 tests/qtest/virtio-net-failover.c
tests/qtest/meson.build +4 -0
@@ -68,6 +68,10 @@ qtests_i386 = \ (config_all_devices.has_key('CONFIG_RTL8139_PCI') ? ['rtl8139-test'] : []) + \ (config_all_devices.has_key('CONFIG_E1000E_PCI_EXPRESS') ? ['fuzz-e1000e-test'] : []) + \ (config_all_devices.has_key('CONFIG_ESP_PCI') ? ['am53c974-test'] : []) + \ + (config_all_devices.has_key('CONFIG_VIRTIO_NET') and \ + config_all_devices.has_key('CONFIG_Q35') and \ + config_all_devices.has_key('CONFIG_VIRTIO_PCI') and \ + slirp.found() ? ['virtio-net-failover'] : []) + \ (unpack_edk2_blobs ? ['bios-tables-test'] : []) + \ qtests_pci + \ ['fdc-test',
tests/qtest/virtio-net-failover.c new file +771 -0
771 lines not on this page · raw message
Signature · 1 line
2.33.1
Quoted 7 lines · Laurent Vivier
Add test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
Quoted 6 lines
Signed-off-by Laurent Vivier <[email protected]>--- tests/qtest/meson.build | 4 + tests/qtest/virtio-net-failover.c | 771 ++++++++++++++++++++++++++++++ 2 files changed, 775 insertions(+)create mode 100644
tests/qtest/virtio-net-failover.c
I'll take this series through my "testing" branch (unless someone speaks up that it should go through some virtio/network branch instead).
Quoted 15 lines · Thomas Huth
Quoted 7 lines · Laurent Vivier
Add test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
Quoted 6 lines
Signed-off-by Laurent Vivier <[email protected]>--- tests/qtest/meson.build | 4 + tests/qtest/virtio-net-failover.c | 771 ++++++++++++++++++++++++++++++ 2 files changed, 775 insertions(+)create mode 100644
tests/qtest/virtio-net-failover.c
Quoted 4 lines
Acked-by Thomas Huth <[email protected]>I'll take this series through my "testing" branch (unless someone speaks up that it should go through some virtio/network branch instead).
Pls do.
Signature · 1 line
MST
Quoted 9 lines · Laurent Vivier
Add test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
Signed-off-by Laurent Vivier <[email protected]>---
[...]
Quoted 5 lines
tests/qtest/virtio-net-failover.c new file +0
-0
[...]
tests/qtest/virtio-net-failover.c line 214
Quoted 13 lines
tests/qtest/virtio-net-failover.c new file +13
-0+static char *get_mac (QTestState *qts,const char *name) +{ +QDict *resp; +char *mac; + + resp =qtest_qmp (qts,"{ 'execute': 'qom-get', " +"'arguments': { " +"'path': %s, " +"'property': 'mac' } }" , name); + +g_assert (qdict_haskey (resp,"return" )); + + mac =g_strdup (qdict_get_str (resp,"return" ));
FYI, check_patch.pl complains about the space after the "(" here.
I'll fix it up locally, no need to resend just because of this.
tests/qtest/virtio-net-failover.c line 219
Quoted 4 lines
tests/qtest/virtio-net-failover.c new file +4
-0+qobject_unref (resp); + +return mac; +}
Thomas
Quoted 33 lines · Thomas Huth
Quoted 9 lines · Laurent Vivier
Add test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
Signed-off-by Laurent Vivier <[email protected]>---
[...]
Quoted 5 lines
tests/qtest/virtio-net-failover.c new file +0
-0[...]
tests/qtest/virtio-net-failover.c line 214
Quoted 13 lines
tests/qtest/virtio-net-failover.c new file +13
-0+static char *get_mac (QTestState *qts,const char *name) +{ + QDict *resp; + char *mac; + + resp = qtest_qmp(qts, "{ 'execute': 'qom-get', " + "'arguments': { " + "'path': %s, " + "'property': 'mac' } }", name); + + g_assert(qdict_haskey(resp, "return")); + + mac = g_strdup( qdict_get_str(resp, "return"));FYI, check_patch.pl complains about the space after the "(" here.
Quoted 2 lines
I'll fix it up locally, no need to resend just because of this.
I don't know how I missed that as I have pre-commit git hook to run checkpatch.pl
Thank you.
Laurent
Quoted 34 lines · Laurent Vivier
Quoted 33 lines · Thomas Huth
Quoted 9 lines · Laurent Vivier
Add test cases to test several error cases that must be generated by invalid failover configuration.
Add a combination of coldplug and hotplug test cases to be sure the primary is correctly managed according the presence or not of the STANDBY feature.
Signed-off-by Laurent Vivier <[email protected]>---
[...]
Quoted 5 lines
tests/qtest/virtio-net-failover.c new file +0
-0[...]
tests/qtest/virtio-net-failover.c line 214
Quoted 13 lines
tests/qtest/virtio-net-failover.c new file +13
-0+static char *get_mac (QTestState *qts,const char *name) +{ + QDict *resp; + char *mac; + + resp = qtest_qmp(qts, "{ 'execute': 'qom-get', " + "'arguments': { " + "'path': %s, " + "'property': 'mac' } }", name); + + g_assert(qdict_haskey(resp, "return")); + + mac = g_strdup( qdict_get_str(resp, "return"));FYI, check_patch.pl complains about the space after the "(" here.
Quoted 4 lines
Quoted 2 lines
I'll fix it up locally, no need to resend just because of this.
I don't know how I missed that as I have pre-commit git hook to run checkpatch.pl
... but now I ran into another problem: Your new test fails the build with the sanitizer enabled:
https://gitlab.com/thuth/qemu/-/jobs/1861286254
Could you please have a look and resend after fixing it?
Thanks,
Thomas
PATCH v7 3/4 test/libqtest: add some virtio-net failover migration cancelling tests
In reply to Laurent VivierAdd some tests to check the state of the machine if the migration is cancelled while we are using virtio-net failover.
--- tests/qtest/virtio-net-failover.c | 276 ++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+)
tests/qtest/virtio-net-failover.c +276 -0
@@ -735,6 +735,274 @@ 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; + + 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 ); + +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 ) { +break ; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "active"); +qobject_unref (ret); + } +qobject_unref (ret); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); + +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; + + 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 ); + +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 ) { +break ; + } + g_assert_cmpstr(status, !=, "failed"); +qobject_unref (ret); + } +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 ) { +break ; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "active"); +qobject_unref (ret); + } +qobject_unref (ret); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); + +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; + + 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 ); + +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 ) { +break ; + } + g_assert_cmpstr(status, ==, "cancelling"); +g_assert (qdict_haskey (ret,"total-time" )); + total =qdict_get_int (ret,"total-time" ); +qobject_unref (ret); + } +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 ); + +machine_stop (qts); +} +int main (int argc,char **argv) {const gchar *tmpdir =g_get_tmp_dir ();
@@ -761,6 +1029,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 ();
Signature · 1 line
2.33.1
PATCH v7 4/4 tests/libqtest: add a migration test with two couples of failover devices
In reply to Laurent Vivier--- tests/qtest/virtio-net-failover.c | 277 ++++++++++++++++++++++++++++++ 1 file changed, 277 insertions(+)
tests/qtest/virtio-net-failover.c +277 -0
@@ -20,6 +20,7 @@#define ACPI_PCIHP_ADDR_ICH9 0x0cc0#define PCI_EJ_BASE 0x0008 +#define PCI_SEL_BASE 0x0010#define BASE_MACHINE "-M q35 -nodefaults " \ "-device pcie-root-port,id=root0,addr=0x1,bus=pcie.0,chassis=1 " \
@@ -27,6 +28,8 @@#define MAC_PRIMARY0 "52:54:00:11:11:11"#define MAC_STANDBY0 "52:54:00:22:22:22" +#define MAC_PRIMARY1 "52:54:00:33:33:33" +#define MAC_STANDBY1 "52:54:00:44:44:44"static QGuestAllocator guest_malloc;static QPCIBus *pcibus;
@@ -1003,6 +1006,276 @@ static void test_migrate_abort_timeout(gconstpointer opaque)machine_stop (qts); } +static void test_multi_out (gconstpointer opaque) +{ +QTestState *qts; +QDict *resp, *args, *ret; + g_autofree gchar *uri = g_strdup_printf("exec: cat > %s", (gchar *)opaque); +const gchar *status, *expected; + + qts =machine_start (BASE_MACHINE +"-device pcie-root-port,id=root2,addr=0x3,bus=pcie.0,chassis=3 " +"-device pcie-root-port,id=root3,addr=0x4,bus=pcie.0,chassis=4 " +"-netdev user,id=hs0 " +"-netdev user,id=hs1 " +"-netdev user,id=hs2 " +"-netdev user,id=hs3 " , +4 ); + +check_one_card (qts, false,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, false,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +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 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +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 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +start_virtio_net (qts,1 ,0 ,"standby0" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +qtest_qmp_device_add (qts,"virtio-net" ,"standby1" , +"{'bus': 'root2'," +"'failover': 'on'," +"'netdev': 'hs2'," +"'mac': '" MAC_STANDBY1 "'}" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +qtest_qmp_device_add (qts,"virtio-net" ,"primary1" , +"{'bus': 'root3'," +"'failover_pair_id': 'standby1'," +"'netdev': 'hs3'," +"'rombar': 0," +"'romfile': ''," +"'mac': '" MAC_PRIMARY1 "'}" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +start_virtio_net (qts,3 ,0 ,"standby1" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, true,"primary1" ,MAC_PRIMARY1 ); + + 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); +if (strcmp (qdict_get_str (resp,"device-id" ),"primary0" ) ==0 ) { + expected ="primary1" ; + }else if (strcmp (qdict_get_str (resp,"device-id" ),"primary1" ) ==0 ) { + expected ="primary0" ; + }else { +g_assert_not_reached (); + } +qobject_unref (resp); + + resp =get_unplug_primary_event (qts); + g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, expected); +qobject_unref (resp); + +/* wait the end of the migration setup phase */ +while (true) { + ret =migrate_status (qts); + + status =qdict_get_str (ret,"status" ); +if (strcmp (status,"wait-unplug" ) ==0 ) { +break ; + } + +/* The migration must not start if the card is not ejected */ + g_assert_cmpstr(status, !=, "active"); + g_assert_cmpstr(status, !=, "completed"); + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "cancelling"); + g_assert_cmpstr(status, !=, "cancelled"); + +qobject_unref (ret); + } +qobject_unref (ret); + +/* OS unplugs primary1, but we must wait the second */ +qtest_outl (qts,ACPI_PCIHP_ADDR_ICH9 +PCI_EJ_BASE ,1 ); + + ret =migrate_status (qts); + status =qdict_get_str (ret,"status" ); + g_assert_cmpstr(status, ==, "wait-unplug"); +qobject_unref (ret); + +if (g_test_slow ()) { +/* check we stay in wait-unplug while the card is not ejected */ +for (int i =0 ; i <5 ; i++) { +sleep (1 ); + ret =migrate_status (qts); + status =qdict_get_str (ret,"status" ); + g_assert_cmpstr(status, ==, "wait-unplug"); +qobject_unref (ret); + } + } + +/* OS unplugs primary0, QEMU can move from wait-unplug state */ +qtest_outl (qts,ACPI_PCIHP_ADDR_ICH9 +PCI_SEL_BASE ,2 ); +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,"completed" ) ==0 ) { +break ; + } + g_assert_cmpstr(status, !=, "failed"); + g_assert_cmpstr(status, !=, "cancelling"); + g_assert_cmpstr(status, !=, "cancelled"); + } + +qtest_qmp_eventwait (qts,"STOP" ); + +machine_stop (qts); +} + +static void test_multi_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 +"-device pcie-root-port,id=root2,addr=0x3,bus=pcie.0,chassis=3 " +"-device pcie-root-port,id=root3,addr=0x4,bus=pcie.0,chassis=4 " +"-netdev user,id=hs0 " +"-netdev user,id=hs1 " +"-netdev user,id=hs2 " +"-netdev user,id=hs3 " +"-incoming defer " , +4 ); + +check_one_card (qts, false,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, false,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +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 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +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 ); +check_one_card (qts, false,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +qtest_qmp_device_add (qts,"virtio-net" ,"standby1" , +"{'bus': 'root2'," +"'failover': 'on'," +"'netdev': 'hs2'," +"'mac': '" MAC_STANDBY1 "'}" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, false,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + +qtest_qmp_device_add (qts,"virtio-net" ,"primary1" , +"{'bus': 'root3'," +"'failover_pair_id': 'standby1'," +"'netdev': 'hs3'," +"'rombar': 0," +"'romfile': ''," +"'mac': '" MAC_PRIMARY1 "'}" ); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, false,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, false,"primary1" ,MAC_PRIMARY1 ); + + 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); + + resp =get_failover_negociated_event (qts); + g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby0"); +qobject_unref (resp); + + resp =get_failover_negociated_event (qts); + g_assert_cmpstr(qdict_get_str(resp, "device-id"), ==, "standby1"); +qobject_unref (resp); + +check_one_card (qts, true,"standby0" ,MAC_STANDBY0 ); +check_one_card (qts, true,"primary0" ,MAC_PRIMARY0 ); +check_one_card (qts, true,"standby1" ,MAC_STANDBY1 ); +check_one_card (qts, true,"primary1" ,MAC_PRIMARY1 ); + +qtest_qmp_eventwait (qts,"RESUME" ); + + ret =migrate_status (qts); + g_assert_cmpstr(qdict_get_str(ret, "status"), ==, "completed"); +qobject_unref (ret); + +machine_stop (qts); +} +int main (int argc,char **argv) {const gchar *tmpdir =g_get_tmp_dir ();
@@ -1037,6 +1310,10 @@ 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" , + tmpfile, test_multi_out); +qtest_add_data_func ("failover-virtio-net/multi/in" , + tmpfile, test_multi_in); ret =g_test_run ();
Signature · 1 line
2.33.1