From nobody Thu Nov 13 23:42:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1583327321; cv=none; d=zohomail.com; s=zohoarc; b=Ik/a5PwbAVT/O+MTz602xcuTr1LJHwioDY2QfU90z6IrpaygtwLZtwin0h8aQnetqUvOnu4w6XWg1CC0vRqJRpJabLHxuXlHDAK5R1R9n1nNoR/XsLSaJmeEuqz28RNykN+lvqj5lyctk8023JlUoCUPuC8Ij/yoku8z8iv5oW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583327321; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=RzA7COy6OjGENVG5q5PdG3mDLFc4iPpo75ImpI9/idQ=; b=iboebSvlpCRFsh2nU2HCHlu9YWv1Azvk/W7SDwrbd3tzudiDHNrf+ihvIOzY2xqNFIceD+CYcxIwFURW1bvO5kbmoI7j9Z55uj0jepsyNPahTFX15gP9NDGexPydLe+l2b0A/+Off/+Olt1PrWPgKR0CGDrj/yjRrmCLr4lMXcA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1583327321542476.29660890693424; Wed, 4 Mar 2020 05:08:41 -0800 (PST) Received: from localhost ([::1]:34052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9TlP-0004U4-4d for importer@patchew.org; Wed, 04 Mar 2020 08:08:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37180) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j9TkH-0002mn-SZ for qemu-devel@nongnu.org; Wed, 04 Mar 2020 08:07:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j9TkG-0001CP-K8 for qemu-devel@nongnu.org; Wed, 04 Mar 2020 08:07:29 -0500 Received: from forwardcorp1j.mail.yandex.net ([2a02:6b8:0:1619::183]:40464) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j9TkD-00012X-Oh; Wed, 04 Mar 2020 08:07:26 -0500 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id E6B6B2E1695; Wed, 4 Mar 2020 16:07:22 +0300 (MSK) Received: from sas1-9998cec34266.qloud-c.yandex.net (sas1-9998cec34266.qloud-c.yandex.net [2a02:6b8:c14:3a0e:0:640:9998:cec3]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id fDcZyQkbLf-7JJKZglc; Wed, 04 Mar 2020 16:07:22 +0300 Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:b4f7:3f29:4fea:8822]) by sas1-9998cec34266.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ujb0Gsh6CR-7IWOaIsp; Wed, 04 Mar 2020 16:07:19 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Precedence: bulk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1583327242; bh=RzA7COy6OjGENVG5q5PdG3mDLFc4iPpo75ImpI9/idQ=; h=In-Reply-To:Message-Id:References:Date:Subject:To:From:Cc; b=InvlNaS+6VR8q2ihOkE87gsAyKN7LhYTRQObXdwhw7Zc39oH3dBVLg1PkzoD/5Iox vh7w995083AolKuaLn3q1GpsyysEnHLG2OLsBtnFS8alONLPesN/dQ7rIZA+K2jHsb JemjMrst8VWPU1Y0q5zVcEzSdnyOG+Osf3rwfgbE= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru From: Alexey Kirillov To: Eric Blake , Thomas Huth , Markus Armbruster Subject: [PATCH v2 2/4] tests: Add tests for query-netdevs command Date: Wed, 4 Mar 2020 16:06:54 +0300 Message-Id: <20200304130656.16859-3-lekiravi@yandex-team.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200304130656.16859-1-lekiravi@yandex-team.ru> References: <20200304130656.16859-1-lekiravi@yandex-team.ru> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a02:6b8:0:1619::183 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Dmitry Fleytman , "Michael S. Tsirkin" , Jason Wang , qemu-devel@nongnu.org, Vincenzo Maffione , Gerd Hoffmann , "Edgar E. Iglesias" , Sven Schnelle , Rob Herring , Stefano Stabellini , Paul Durrant , Joel Stanley , Anthony Perard , Samuel Thibault , Aleksandar Rikalo , David Gibson , Laurent Vivier , Jiri Pirko , yc-core@yandex-team.ru, Stefan Weil , Alistair Francis , Beniamino Galvani , qemu-arm@nongnu.org, Peter Chubb , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , xen-devel@lists.xenproject.org, Giuseppe Lettieri , Luigi Rizzo , Richard Henderson , Andrew Jeffery , Michael Walle , qemu-ppc@nongnu.org, Aleksandar Markovic , Alexey Kirillov , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Alexey Kirillov --- tests/qtest/Makefile.include | 2 + tests/qtest/test-query-netdevs.c | 120 +++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 tests/qtest/test-query-netdevs.c diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index e769c1ad70..6924843ef9 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -9,6 +9,7 @@ check-qtest-generic-y +=3D qmp-cmd-test check-qtest-generic-y +=3D qom-test check-qtest-generic-$(CONFIG_MODULES) +=3D modules-test check-qtest-generic-y +=3D test-hmp +check-qtest-generic-$(CONFIG_SLIRP) +=3D test-query-netdevs =20 check-qtest-pci-$(CONFIG_RTL8139_PCI) +=3D rtl8139-test check-qtest-pci-$(CONFIG_VGA) +=3D display-vga-test @@ -303,6 +304,7 @@ tests/qtest/tpm-crb-test$(EXESUF): tests/qtest/tpm-crb-= test.o tests/qtest/tpm-em tests/qtest/tpm-tis-swtpm-test$(EXESUF): tests/qtest/tpm-tis-swtpm-test.o = tests/qtest/tpm-emu.o \ tests/qtest/tpm-util.o tests/qtest/tpm-tests.o $(test-io-obj-y) tests/qtest/tpm-tis-test$(EXESUF): tests/qtest/tpm-tis-test.o tests/qtest/= tpm-emu.o $(test-io-obj-y) +tests/qtest/test-query-netdevs$(EXESUF): tests/qtest/test-query-netdevs.o =20 # QTest rules =20 diff --git a/tests/qtest/test-query-netdevs.c b/tests/qtest/test-query-netd= evs.c new file mode 100644 index 0000000000..e077358a50 --- /dev/null +++ b/tests/qtest/test-query-netdevs.c @@ -0,0 +1,120 @@ +/* + * QTest testcase for the query-netdevs + * + * Copyright Yandex N.V., 2019 + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include "libqtest.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qlist.h" + +/* + * Events can get in the way of responses we are actually waiting for. + */ +GCC_FMT_ATTR(2, 3) +static QObject *wait_command(QTestState *who, const char *command, ...) +{ + va_list ap; + QDict *response; + QObject *result; + + va_start(ap, command); + qtest_qmp_vsend(who, command, ap); + va_end(ap); + + response =3D qtest_qmp_receive(who); + + result =3D qdict_get(response, "return"); + g_assert(result); + qobject_ref(result); + qobject_unref(response); + + return result; +} + +static void qmp_query_netdevs_no_error(QTestState *qts, + size_t netdevs_count) +{ + QObject *resp; + QList *netdevs; + + resp =3D wait_command(qts, "{'execute': 'query-netdevs'}"); + + netdevs =3D qobject_to(QList, resp); + g_assert(netdevs); + g_assert(qlist_size(netdevs) =3D=3D netdevs_count); + + qobject_unref(resp); +} + +static void test_query_netdevs(void) +{ + const char *arch =3D qtest_get_arch(); + size_t correction =3D 0; + QObject *resp; + QTestState *state; + + /* Archs which still have a netdev despite of -nodefaults */ + if (g_str_equal(arch, "cris") || + g_str_equal(arch, "microblaze") || + g_str_equal(arch, "microblazeel") || + g_str_equal(arch, "sparc")) { + correction =3D 1; + } + + if (g_str_equal(arch, "arm") || + g_str_equal(arch, "aarch64")) { + state =3D qtest_init( + "-nodefaults " + "-M virt " + "-netdev user,id=3Dslirp0"); + } else if (g_str_equal(arch, "tricore")) { + state =3D qtest_init( + "-nodefaults " + "-M tricore_testboard " + "-netdev user,id=3Dslirp0"); + } else { + state =3D qtest_init( + "-nodefaults " + "-netdev user,id=3Dslirp0"); + } + g_assert(state); + + qmp_query_netdevs_no_error(state, 1 + correction); + + resp =3D wait_command(state, + "{'execute': 'netdev_add', 'arguments': {" + " 'id': 'slirp1'," + " 'type': 'user'}}"); + qobject_unref(resp); + + qmp_query_netdevs_no_error(state, 2 + correction); + + resp =3D wait_command(state, + "{'execute': 'netdev_del', 'arguments': {" + " 'id': 'slirp1'}}"); + qobject_unref(resp); + + qmp_query_netdevs_no_error(state, 1 + correction); + + qtest_quit(state); +} + +int main(int argc, char **argv) +{ + int ret =3D 0; + g_test_init(&argc, &argv, NULL); + + qtest_add_func("/net/qapi/query_netdevs", + test_query_netdevs); + + ret =3D g_test_run(); + + return ret; +} --=20 2.17.1