tests/qtest: add some tests for virtio-net failover
Subsystems (2)
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
-> this one needs to be improved as we can't actualy unplug the
card as the qtest framework doesn't allow to really do
the OS level unplug. So we receive the UNPLUG_PRIMARY
event but nothing more.
There are two preliminary patches in the series:
- PATCH 1 makes available functions that helped me to debug the qmp command result. I think it's a good point to have them available widely
- PATCH 2 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
Laurent Vivier (3):
qdict: make available dump_qobject(), dump_qdict(), dump_qlist() qtest/libqos: add a function to initialize secondary PCI buses tests/qtest: add some tests for virtio-net failover
block/qapi.c | 82 +---- include/hw/pci/pci_bridge.h | 8 + include/qapi/qmp/qdict.h | 2 + include/qapi/qmp/qlist.h | 1 + include/qapi/qmp/qobject.h | 1 + qobject/qdict.c | 25 ++ qobject/qlist.c | 17 + qobject/qobject.c | 35 ++ tests/qtest/libqos/pci.c | 118 +++++++ tests/qtest/libqos/pci.h | 1 + tests/qtest/meson.build | 3 + tests/qtest/virtio-net-failover.c | 567 ++++++++++++++++++++++++++++++ 12 files changed, 779 insertions(+), 81 deletions(-) create mode 100644 tests/qtest/virtio-net-failover.c
Signature · 1 line
2.31.1
PATCH 1/3 qdict: make available dump_qobject(), dump_qdict(), dump_qlist()
move them from block/qapi.c to qobject/qdict.c, qobject/qlist.c, qobject/qobject.c
This is useful to debug qobjects
--- block/qapi.c | 82 +------------------------------------- include/qapi/qmp/qdict.h | 2 + include/qapi/qmp/qlist.h | 1 + include/qapi/qmp/qobject.h | 1 + qobject/qdict.c | 25 ++++++++++++ qobject/qlist.c | 17 ++++++++ qobject/qobject.c | 35 ++++++++++++++++ 7 files changed, 82 insertions(+), 81 deletions(-)
block/qapi.c +1 -81
@@ -697,86 +697,6 @@ void bdrv_snapshot_dump(QEMUSnapshotInfo *sn)g_free (sizing); } -static void dump_qdict (int indentation,QDict *dict); -static void dump_qlist (int indentation,QList *list); - -static void dump_qobject (int comp_indent,QObject *obj) -{ -switch (qobject_type (obj)) { -case QTYPE_QNUM : { -QNum *value =qobject_to (QNum, obj); -char *tmp =qnum_to_string (value); -qemu_printf ("%s" , tmp); -g_free (tmp); -break ; - } -case QTYPE_QSTRING : { -QString *value =qobject_to (QString, obj); -qemu_printf ("%s" ,qstring_get_str (value)); -break ; - } -case QTYPE_QDICT : { -QDict *value =qobject_to (QDict, obj); -dump_qdict (comp_indent, value); -break ; - } -case QTYPE_QLIST : { -QList *value =qobject_to (QList, obj); -dump_qlist (comp_indent, value); -break ; - } -case QTYPE_QBOOL : { -QBool *value =qobject_to (QBool, obj); -qemu_printf ("%s" ,qbool_get_bool (value) ?"true" :"false" ); -break ; - } -default : -abort (); - } -} - -static void dump_qlist (int indentation,QList *list) -{ -const QListEntry *entry; -int i =0 ; - -for (entry =qlist_first (list); entry; entry =qlist_next (entry), i++) { -QType type =qobject_type (entry->value); -bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); -qemu_printf ("%*s[%i]:%c" , indentation *4 ,"" , i, - composite ?'\n' :' ' ); -dump_qobject (indentation +1 , entry->value); -if (!composite) { -qemu_printf ("\n" ); - } - } -} - -static void dump_qdict (int indentation,QDict *dict) -{ -const QDictEntry *entry; - -for (entry =qdict_first (dict); entry; entry =qdict_next (dict, entry)) { -QType type =qobject_type (entry->value); -bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); -char *key =g_malloc (strlen (entry->key) +1 ); -int i; - -/* replace dashes with spaces in key (variable) names */ -for (i =0 ; entry->key[i]; i++) { - key[i] = entry->key[i] =='-' ?' ' : entry->key[i]; - } - key[i] =0 ; -qemu_printf ("%*s%s:%c" , indentation *4 ,"" , key, - composite ?'\n' :' ' ); -dump_qobject (indentation +1 , entry->value); -if (!composite) { -qemu_printf ("\n" ); - } -g_free (key); - } -} -void bdrv_image_info_specific_dump (ImageInfoSpecific *info_spec) {QObject *obj, *data;
@@ -785,7 +705,7 @@ void bdrv_image_info_specific_dump(ImageInfoSpecific *info_spec)visit_type_ImageInfoSpecific (v,NULL , &info_spec, &error_abort);visit_complete (v, &obj); data =qdict_get (qobject_to (QDict, obj),"data" ); -dump_qobject (1 , data); +dump_qobject (1 , data, qemu_printf);qobject_unref (obj);visit_free (v); }
include/qapi/qmp/qdict.h +2 -0
@@ -67,4 +67,6 @@ QDict *qdict_clone_shallow(const QDict *src);QObject *qdict_crumple (const QDict *src,Error **errp);void qdict_flatten (QDict *qdict); +void dump_qdict (int indentation,QDict *dict,int (*qemu_printf)(const char *fmt, ...)); +#endif /* QDICT_H */
include/qapi/qmp/qlist.h +1 -0
@@ -62,4 +62,5 @@ static inline const QListEntry *qlist_next(const QListEntry *entry) return QTAILQ_NEXT(entry, next); } +void dump_qlist (int indentation,QList *list,int (*qemu_printf)(const char *fmt, ...));#endif /* QLIST_H */
include/qapi/qmp/qobject.h +1 -0
@@ -135,4 +135,5 @@ static inline QObject *qobject_check_type(const QObject *obj, QType type) } } +void dump_qobject (int comp_indent,QObject *obj,int (*qemu_printf)(const char *fmt, ...));#endif /* QOBJECT_H */
qobject/qdict.c +25 -0
@@ -442,3 +442,28 @@ void qdict_destroy_obj(QObject *obj)g_free (qdict); } + +void dump_qdict (int indentation,QDict *dict,int (*qemu_printf)(const char *fmt, ...)) +{ +const QDictEntry *entry; + +for (entry =qdict_first (dict); entry; entry =qdict_next (dict, entry)) { +QType type =qobject_type (entry->value); +bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); +char *key =g_malloc (strlen (entry->key) +1 ); +int i; + +/* replace dashes with spaces in key (variable) names */ +for (i =0 ; entry->key[i]; i++) { + key[i] = entry->key[i] =='-' ?' ' : entry->key[i]; + } + key[i] =0 ; +qemu_printf ("%*s%s:%c" , indentation *4 ,"" , key, + composite ?'\n' :' ' ); +dump_qobject (indentation +1 , entry->value, qemu_printf); +if (!composite) { +qemu_printf ("\n" ); + } +g_free (key); + } +}
qobject/qlist.c +17 -0
@@ -182,3 +182,20 @@ void qlist_destroy_obj(QObject *obj)g_free (qlist); } + +void dump_qlist (int indentation,QList *list,int (*qemu_printf)(const char *fmt, ...)) +{ +const QListEntry *entry; +int i =0 ; + +for (entry =qlist_first (list); entry; entry =qlist_next (entry), i++) { +QType type =qobject_type (entry->value); +bool composite = (type ==QTYPE_QDICT || type ==QTYPE_QLIST ); +qemu_printf ("%*s[%i]:%c" , indentation *4 ,"" , i, + composite ?'\n' :' ' ); +dump_qobject (indentation +1 , entry->value, qemu_printf); +if (!composite) { +qemu_printf ("\n" ); + } + } +}
qobject/qobject.c +35 -0
@@ -70,3 +70,38 @@ bool qobject_is_equal(const QObject *x, const QObject *y)return qis_equal[x->base.type](x, y); } + +void dump_qobject (int comp_indent,QObject *obj,int (*qemu_printf)(const char *fmt, ...)) +{ +switch (qobject_type (obj)) { +case QTYPE_QNUM : { +QNum *value =qobject_to (QNum, obj); +char *tmp =qnum_to_string (value); +qemu_printf ("%s" , tmp); +g_free (tmp); +break ; + } +case QTYPE_QSTRING : { +QString *value =qobject_to (QString, obj); +qemu_printf ("%s" ,qstring_get_str (value)); +break ; + } +case QTYPE_QDICT : { +QDict *value =qobject_to (QDict, obj); +dump_qdict (comp_indent, value, qemu_printf); +break ; + } +case QTYPE_QLIST : { +QList *value =qobject_to (QList, obj); +dump_qlist (comp_indent, value, qemu_printf); +break ; + } +case QTYPE_QBOOL : { +QBool *value =qobject_to (QBool, obj); +qemu_printf ("%s" ,qbool_get_bool (value) ?"true" :"false" ); +break ; + } +default : +abort (); + } +}
Signature · 1 line
2.31.1
Re: [PATCH 1/3] qdict: make available dump_qobject(), dump_qdict(), dump_qlist()
Quoted 6 lines · Laurent Vivier
move them from
block/qapi.ctoqobject/qdict.c,qobject/qlist.c,qobject/qobject.cThis is useful to debug qobjects
Signed-off-by Laurent Vivier <[email protected]>
I think qobject_to_json_pretty() is better suited to debugging, because it preserves differences like the one between the string "1" and the number 1.
Re: [PATCH 1/3] qdict: make available dump_qobject(), dump_qdict(), dump_qlist()
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Laurent Vivier
move them from
block/qapi.ctoqobject/qdict.c,qobject/qlist.c,qobject/qobject.c
Quoted 8 lines
Quoted 3 lines
This is useful to debug qobjects
Signed-off-by Laurent Vivier <[email protected]>I think
qobject_to_json_pretty()is better suited to debugging, because it preserves differences like the one between the string "1" and the number 1.
Yes, you're right. I didn't think about this solution.
So we can drop this patch.
Thanks,
Laurent
PATCH 2/3 qtest/libqos: add a function to initialize secondary PCI buses
In reply to Laurent VivierScan 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.31.1
PATCH 3/3 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 | 3 + tests/qtest/virtio-net-failover.c | 567 ++++++++++++++++++++++++++++++ 2 files changed, 570 insertions(+) create mode 100644 tests/qtest/virtio-net-failover.c
tests/qtest/meson.build +3 -0
@@ -22,6 +22,9 @@ qtests_generic = \ (config_all_devices.has_key('CONFIG_VIRTIO_SCSI') ? ['fuzz-virtio-scsi-test'] : []) + \ (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) + \ (config_all_devices.has_key('CONFIG_SDHCI_PCI') ? ['fuzz-sdcard-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') ? ['virtio-net-failover'] : []) + \ [ 'cdrom-test', 'device-introspect-test',
tests/qtest/virtio-net-failover.c new file +567 -0
567 lines not on this page · raw message
Signature · 1 line
2.31.1