Re: [PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
On 08/12/2021 09.52, Laurent Vivier wrote: On 08/12/2021 09:39, Thomas Huth wrote: On 07/12/2021 18.23, Laurent Vivier wrote: 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 --- [...] diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c new file mode 100644 index ..7444d30d2900 --- /dev/null +++ b/tests/qtest/virtio-net-failover.c [...] +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. 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
Re: [PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
On 08/12/2021 09:39, Thomas Huth wrote: On 07/12/2021 18.23, Laurent Vivier wrote: 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 --- [...] diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c new file mode 100644 index ..7444d30d2900 --- /dev/null +++ b/tests/qtest/virtio-net-failover.c [...] +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. I don't know how I missed that as I have pre-commit git hook to run checkpatch.pl Thank you. Laurent
Re: [PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
On 07/12/2021 18.23, Laurent Vivier wrote: 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 --- [...] diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c new file mode 100644 index ..7444d30d2900 --- /dev/null +++ b/tests/qtest/virtio-net-failover.c [...] +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. +qobject_unref(resp); + +return mac; +} Thomas
Re: [PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
On Wed, Dec 08, 2021 at 08:33:31AM +0100, Thomas Huth wrote: > On 07/12/2021 18.23, Laurent Vivier wrote: > > 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 > > --- > > 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 > > Acked-by: Thomas Huth > > 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. -- MST
Re: [PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
On 07/12/2021 18.23, Laurent Vivier wrote: 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 --- 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 Acked-by: Thomas Huth I'll take this series through my "testing" branch (unless someone speaks up that it should go through some virtio/network branch instead).
[PATCH v7 2/4] tests/qtest: add some tests for virtio-net failover
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 --- 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 diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index c9d8458062ff..975a0f2f5f25 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -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', diff --git a/tests/qtest/virtio-net-failover.c b/tests/qtest/virtio-net-failover.c new file mode 100644 index ..7444d30d2900 --- /dev/null +++ b/tests/qtest/virtio-net-failover.c @@ -0,0 +1,771 @@ +/* + * QTest testcase for virtio-net failover + * + * See docs/system/virtio-net-failover.rst + * + * Copyright (c) 2021 Red Hat, Inc. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "libqos/libqtest.h" +#include "libqos/pci.h" +#include "libqos/pci-pc.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" +#include "qapi/qmp/qjson.h" +#include "libqos/malloc-pc.h" +#include "libqos/virtio-pci.h" +#include "hw/pci/pci.h" + +#define ACPI_PCIHP_ADDR_ICH90x0cc0 +#define PCI_EJ_BASE 0x0008 + +#define BASE_MACHINE "-M q35 -nodefaults " \ +"-device pcie-root-port,id=root0,addr=0x1,bus=pcie.0,chassis=1 " \ +"-device pcie-root-port,id=root1,addr=0x2,bus=pcie.0,chassis=2 " + +#define MAC_PRIMARY0 "52:54:00:11:11:11" +#define MAC_STANDBY0 "52:54:00:22:22:22" + +static QGuestAllocator guest_malloc; +static QPCIBus *pcibus; + +static QTestState *machine_start(const char *args, int numbus) +{ +QTestState *qts; +QPCIDevice *dev; +int bus; + +qts = qtest_init(args); + +pc_alloc_init(_malloc, qts, 0); +pcibus = qpci_new_pc(qts, _malloc); +g_assert(qpci_secondary_buses_init(pcibus) == numbus); + +for (bus = 1; bus <= numbus; bus++) { +dev = qpci_device_find(pcibus, QPCI_DEVFN(bus, 0)); +g_assert_nonnull(dev); + +qpci_device_enable(dev); +qpci_iomap(dev, 4, NULL); + +g_free(dev); +} + +return qts; +} + +static void machine_stop(QTestState *qts) +{ +qpci_free_pc(pcibus); +alloc_destroy(_malloc); +qtest_quit(qts); +} + +static void test_error_id(void) +{ +QTestState *qts; +QDict *resp; +QDict *err; + +qts = machine_start(BASE_MACHINE +"-device virtio-net,bus=root0,id=standby0,failover=on", +2); + +resp = qtest_qmp(qts, "{'execute': 'device_add'," + "'arguments': {" + "'driver': 'virtio-net'," + "'bus': 'root1'," + "'failover_pair_id': 'standby0'" + "} }"); +g_assert(qdict_haskey(resp, "error")); + +err = qdict_get_qdict(resp, "error"); +g_assert(qdict_haskey(err, "desc")); + +g_assert_cmpstr(qdict_get_str(err, "desc"), ==, +"Device with failover_pair_id needs to have id"); + +qobject_unref(resp); + +machine_stop(qts); +} + +static void test_error_pcie(void) +{ +QTestState *qts; +QDict *resp; +QDict *err; + +qts = machine_start(BASE_MACHINE +"-device virtio-net,bus=root0,id=standby0,failover=on", +2); + +resp = qtest_qmp(qts, "{'execute': 'device_add'," + "'arguments': {" + "'driver': 'virtio-net'," + "'id': 'primary0'," + "'bus': 'pcie.0'," + "'failover_pair_id': 'standby0'" + "} }"); +g_assert(qdict_haskey(resp, "error")); + +err = qdict_get_qdict(resp, "error"); +g_assert(qdict_haskey(err, "desc")); + +g_assert_cmpstr(qdict_get_str(err, "desc"), ==, +