From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0071.outbound.protection.outlook.com [104.47.32.71]) by dpdk.org (Postfix) with ESMTP id 208311094 for ; Tue, 17 Jan 2017 11:06:19 +0100 (CET) Received: from DM2PR03CA0010.namprd03.prod.outlook.com (10.141.96.20) by DM2PR0301MB0751.namprd03.prod.outlook.com (10.160.97.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.845.12; Tue, 17 Jan 2017 10:06:17 +0000 Received: from BN1AFFO11FD020.protection.gbl (2a01:111:f400:7c10::100) by DM2PR03CA0010.outlook.office365.com (2a01:111:e400:2428::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.860.13 via Frontend Transport; Tue, 17 Jan 2017 10:06:17 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com;nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD020.mail.protection.outlook.com (10.58.52.80) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.803.8 via Frontend Transport; Tue, 17 Jan 2017 10:06:16 +0000 Received: from tophie.ap.freescale.net ([10.232.14.39]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v0HA67Tf024558; Tue, 17 Jan 2017 03:06:14 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Tue, 17 Jan 2017 15:39:27 +0530 Message-ID: <1484647774-28984-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484647774-28984-1-git-send-email-shreyansh.jain@nxp.com> References: <1484581107-2025-1-git-send-email-shreyansh.jain@nxp.com> <1484647774-28984-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131291211765015859; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(7916002)(39410400002)(39450400003)(39860400002)(39380400002)(39850400002)(39400400002)(39840400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(6666003)(50466002)(110136003)(5660300001)(68736007)(2950100002)(2351001)(48376002)(47776003)(30001)(106466001)(50986999)(5003940100001)(105606002)(6916009)(92566002)(36756003)(50226002)(305945005)(76176999)(626004)(2906002)(97736004)(38730400001)(77096006)(8936002)(4326007)(33646002)(189998001)(81166006)(356003)(104016004)(5890100001)(8676002)(85426001)(86362001)(575784001)(54906002)(8656002)(81156014); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0751; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD020; 1:tb/sDPEDgCUxcjqPnCpQuVAy+Hi/p//ly2T6QF1dOiXQrRPdrIbNcKKUPY1BvtB+OJ3283htaSRMkUcEk0lWCcvrMRPPNBxK+IlecKxyReFGmBsowjkiq5Pm5bTyfzp3Rb/lNtatmJo7aWslDr/Okx65iu5rUzUaVeVw8XShMyBK1Qxy6swW77eIfVQNWkv9CPVItPYy1pGUlt/U0Hqap/l8IHN8LrgintznOOGrsa+wwEhLErgGRQ+YX7ibs/LrscMA+61MLSJobLJPaOkJc2PtWvmVDyJEypK255e09eoOzJx7Z/XkIBe4E8FzwnmaH7NJ80I0V3+mYF7k6EA/G06CmMZAKqnE+BNGOORAvVLsvWpN/eP4BePGVs7u9NUZB15ecmLa+s88aaPa0s9o8WsHhuiowA5VE5k2h6fxxmc/rS2xNtJg+EDgRvPIScfhRb0C8K2KAAY2Zkmf+6dSb9QrW+5cq2sIaYJ+btNDHpyMSbKm+LRA7f666hlGfR800ZN5Pwid6T3ign7+kg7ueEO5kT/bT5akW03/mX85cEAg1lcn3U/aSnjQGavoRulbRxuEU/I7I16mzU85uNXavdKSFxTeixSaoer25gGfQqkxcRdnC8ZoSlUGqBmnTP2BOdB3UeaIP9qUQ5Xs8flP1pmQl/xCIwDnxpNN3/B6nMT2OnQOhGr7wCtn2SbZEuK34lVryizeMgMb7VXYhr0SKA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: d383842f-97d9-41c3-6533-08d43ec079d9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 3:55/jX62cWQ0xjdzkbbOtGWprhKd1SRekqeXL6dml+KPKreHotF34e6pLKmyz7isaYaDA7tpAbqL9PCaiotMfC69qU7JL4zFrXdMb2Q0UGdBP24m3W0+aYXwn46qoOW5hdFs33HhezwJ0jucEAx4IE/iWHW6dHdayaRYLut2E4ShJFFIZcU7PmZ84jaoStt8phmfyLHi8fG+aqh439ieXy884SNJzu/A8xCDtK8W/qKJ2eRgUZDxSFnrXrCEOTJ/ztWoXZqZIeTuMXYKcF7RYmONxfxnIBjVzcuqWqpUgOgu8gNo40CnJWdlbL1UD2z/GRoY3uK8llm7XXWq1Wa8gqTAoITHXdiQ2JdLuYpdd5qjuXBnOaapmN/l6ZTiQAnI2; 25:QwmxvC9jyvkVtl5M4FYVaJm29VRsrrzdySKtl4wJrdZemyPY9vA6lW+iRy/kC2BkM7b4RPomO8m/iSFsxzFxS/GsTn+gSiTtP6n5wtwEgJpDeJ6zGsoGPXQoAq3hTF30g2AVSC8LTuZK9tPhs9XxfoV3wFIiAznIxn2x91GzwDQj5QLCFDisQFdFq88z0o6ayI4OhAFAtwjLlBqh82+eiHJktkxu8ie299yv571XZfc0G//JYAWSrgac9OWjvS4texZZ1g2tIHTqpbo4XHY6umntUNngK53k1K9lAdSQLgUlcK7cIvXiFAxz1C514pdX2gj1jwnUovzxOv534NTvh8G6S7gN+2+MJ07kP+Fl/tSTS8It6cfQYRixkiLVrhIFY2D5JSBErdthoXZazh6s1a/v6r4WPTr4WGg2kwAF6yPLYn277ECauJaZPC6dhKud4sDubzLMgBai5fMdHKLxLA== X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 31:2FoL3MhHQQegr94kNPtG4M+owFxVSVph5MOPJY+jviWk89NpmAvkjj7L6knovAZnUoZTVqE4OiK+A0BnAeR3WC0dFjv9w89ElBRPDx9vKZFNuPIAOtsHDYz9tD8bEVlkmsh1ttTWxrsMMhq7ka7y6+eqGvupNZTugDWH2lraGYzQvmAY2V39apwWc+agF3wKFPLjVGJNXGr25GCWsi1lbVJM/Byy/gBDuQiGDuZ3tlqMNSg2PWdqwHnMyr3mYheS2r4lNeg6xHG5b4XTgp4XMg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095060)(601004)(2401047)(5005006)(8121501046)(13018025)(13015025)(13017025)(13023025)(13024025)(10201501046)(3002001)(6055026)(6096035)(20161123559025)(20161123561025)(20161123556025)(20161123563025)(20161123565025); SRVR:DM2PR0301MB0751; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 4:3S8TFybEo9kfQhsBt5AhQcZ/h7nkPAru8BRzbJz3c0PtxWXx6KAS+uO61aV5VTXAtqD2MeF59oOW8SFlpVgX/h7O12JKQ2K+h18beJzlX8HVyqVP7K8w1N0Qbti1IkZELmbuRjcuk66QBnqzz9PP6p3HoYM7elN+fRu6jhN2Lwz2vNMgMYsH9jL/W6ZKjiRckvm+4SFbrqTxakgI1q054QNPQ/3DNlRjbsKI0sHqBbWjcm+HChhpGkMDnUUVK8Yv8lErUFrAKcXDWZap9WhcIOJqCgfDItQ9UWBB4AXRR2TZHhEHENgJJVF8BXWzb+zI7UAojW7sK+cPU4UKIRw0JDdZdzyP17tODgVyFNkTwpNo7Er4CNp+idKAN9TWVqxtN8enMRW2aflUze0o+GL+fZ7jYGpp2LG8psN0WaKrUZRoW14Loxmex/WVFtKV9d/fenJAlif9r9mHKjY7HC7Nb1Xjy9Ub3o4gCFXHGK/vSwgxHjllgkKjxsy+nSqyuaf82bbTg22oFwV2+s2YbXwkIF9FkHrnSRTtIoDs0NgpxEiR/KAbU/xmOzLUnVV4BwVVHO1xR/HCYjj7uijVtVQePe2xetvoQ+pE8aws4/poZqn4FAevCM69Lu/e0RxPGvWDzbQjbscmdmD4iDFn3FxHzZcznondE18M78IuACHemUln2mr6zM39klJYu/h40n2Kpt4ol786h01/BmvTfYMY93tyO5s16/7q1EiYSZWzc6DDCGgC+nCl6L0ifMAo46mC X-Forefront-PRVS: 01901B3451 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0751; 23:d5g/zMAKQZjIPMKLySwXzKJdZKcnh7EPLtFy6ma?= =?us-ascii?Q?V7NDt/uWUxKvye34oQ9QCJxE1nadOb6Dg58gUBRy9lwWN6OPp1xL9MNyTz7Q?= =?us-ascii?Q?yShqJ1CwDfAkqq3gqqEdo3xTTn5TGXqBia0zWGlvE96cMg915VAL5wETEypf?= =?us-ascii?Q?ewArTpseF4sa5/V1akdhnAaSDz0xHhzf6uzzBV8tV2pT/KgB+059PSfCmC07?= =?us-ascii?Q?rzIC/CIVKvgXtpx1yCkEd3ypzdN6LBzKat/8cu0rSQcSYkVLiZLLGtCa1H9i?= =?us-ascii?Q?W8/+VbvlevmTrVgzt+4H8IMDuYg4RbIvec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Exchange-Diagnostics: 1; DM2PR0301MB0751; 7:Yf/1KPgEk55vlEIOOh762SHFxDJ6IF2aQVd885i5vGCu4a4THIoXf5VufxEYyQCHKOH8HBHR88hJtIwIknTM2BKtt0GbhkaszZAYSGE/Qv39kqlpsckg21NmsIbXlLOKnQfRVNvXWOAGoHsjPU6+Grani1vLd5/60cvGkz7HJXl8+TOcdL8MB7bXRXZhrVUM5ZVNZuxutYDdZVKhG9U1y9sQDzr4evdmq+M0JB701C5Keq3Skmb+Xea3y2N1cOdkJN19xNr/yOAXIyjUIwQ3eyhN5yzKXhm3t1auHza8+/4Js4+Roe7sPwVYGJoCES33z2honTAAr+VnCHrQ5llFAUqmnFOgT5+pb0Kgr6+nMKgl7jbcfLvsf6SpD9dO5AqBXvr2LDM0340HKmXtmZZhJf5m9JCiOm2AZEaT6zQCoD24EaK9fax/aVyvtd12P4eG1Ftssn+dpmTUU3fYrH9RTQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jan 2017 10:06:16.3143 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0751 Subject: [dpdk-dev] [PATCH v7 2/9] test: add basic bus infrastructure tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jan 2017 10:06:19 -0000 Verification of bus registration, deregistration methods. Signed-off-by: Shreyansh Jain --- app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 359 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_bus.h | 3 + 4 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 app/test/test_bus.c diff --git a/app/test/Makefile b/app/test/Makefile index 5be023a..ca0f106 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -94,7 +94,7 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c - +SRCS-y += test_bus.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c SRCS-y += test_pmd_perf.c diff --git a/app/test/test.h b/app/test/test.h index 82831f4..c8ec43f 100644 --- a/app/test/test.h +++ b/app/test/test.h @@ -236,6 +236,8 @@ int commands_init(void); int test_pci(void); int test_pci_run; +int test_bus(void); + int test_mp_secondary(void); int test_set_rxtx_conf(cmdline_fixed_string_t mode); diff --git a/app/test/test_bus.c b/app/test/test_bus.c new file mode 100644 index 0000000..9680bac --- /dev/null +++ b/app/test/test_bus.c @@ -0,0 +1,359 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2016 NXP. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of NXP nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#include "test.h" +#include "resource.h" + +/* Visualizing following bus-device-driver model for test + * + * ===.===========.===========.=========,= busA + * | | . | + * devA1 devA2 . '____CPU_ + * `-----------`-------> driverA | + * ' + * ===.===========.===========.=========|= busB + * | | . + * devB1 devB2 . + * `-----------`-------> driverB + * + */ + +#define MAX_DEVICES_ON_BUS 10 +#define MAX_DRIVERS_ON_BUS 10 + +struct dummy_driver; +struct dummy_device; +struct dummy_bus; + +TAILQ_HEAD(dummy_device_list, dummy_device); /**< List of dummy devices */ +TAILQ_HEAD(dummy_driver_list, dummy_driver); /**< List of dummy drivers */ + +/* A structure representing a ethernet/crypto device, embedding + * the rte_device. + */ +struct dummy_device { + TAILQ_ENTRY(dummy_device) next; + const char *name; + struct rte_device dev; +}; + +/* A structure representing a PMD driver of a particular type, + * for e.g. PCI. + */ +struct dummy_driver { + TAILQ_ENTRY(dummy_driver) next; + const char *name; + struct rte_driver drv; +}; + +struct dummy_bus { + TAILQ_ENTRY(dummy_bus) next; + const char *name; + struct rte_bus bus; + struct dummy_driver_list driver_list; + struct dummy_device_list device_list; +}; + +/* Structure representing a Bus with devices attached to it, and drivers + * for those devices + */ +struct dummy_bus_map { + const char *name; + struct dummy_bus *dbus; + struct dummy_driver *ddrivers[MAX_DRIVERS_ON_BUS]; + struct dummy_device *ddevices[MAX_DEVICES_ON_BUS]; +}; + +struct rte_bus_list orig_bus_list = + TAILQ_HEAD_INITIALIZER(orig_bus_list); + +struct dummy_bus busA = { + .name = "busA_impl", /* busA */ + .bus = { + .name = "busA", + }, +}; + +struct dummy_bus busB = { + .name = "busB_impl", /* busB */ + .bus = { + .name = "busB", + }, +}; + +struct dummy_driver driverA = { + .name = "driverA_impl", + .drv = { + .name = "driverA", + }, +}; + +struct dummy_device devA1 = { + .name = "devA1", + .dev = { + .bus = NULL, + .driver = NULL, + } +}; + +struct dummy_device devA2 = { + .name = "devA2", + .dev = { + .bus = NULL, + .driver = NULL, + } +}; + +struct dummy_driver driverB = { + .name = "driverB_impl", + .drv = { + .name = "driverB", + }, +}; + +struct dummy_device devB1 = { + .name = "devB1", + .dev = { + .bus = NULL, + .driver = NULL, + } +}; + +struct dummy_device devB2 = { + .name = "devB2", + .dev = { + .bus = NULL, + .driver = NULL, + } +}; + +struct dummy_bus_map bus_map[] = { + { + .name = "busA", + .dbus = &busA, + .ddrivers = {&driverA, NULL}, + .ddevices = {&devA1, &devA2, NULL}, + }, + { + .name = "busB", + .dbus = &busB, + .ddrivers = {&driverB, NULL}, + .ddevices = {&devB1, &devB2, NULL}, + }, + {NULL, NULL, {NULL,}, {NULL,}, }, +}; + +/* @internal + * Dump the device tree + */ +static void +dump_device_tree(void) +{ + int i; + struct dummy_bus_map *db; + struct rte_bus *bus; + struct dummy_bus *dbus; + struct dummy_driver *ddriver; + struct dummy_device *ddevice; + + printf("------>8-------\n"); + printf("Device Tree:\n"); + for (i = 0; bus_map[i].name; i++) { + db = &bus_map[i]; + + bus = &db->dbus->bus; + if (!bus) + return; + + dbus = container_of(bus, struct dummy_bus, bus); + printf(" Bus: %s (Implementation name: %s)\n", + bus->name, dbus->name); + + printf(" Drivers on bus:\n"); + TAILQ_FOREACH(ddriver, &dbus->driver_list, next) { + printf(" %s\n", ddriver->name); + } + + printf(" Devices on bus:\n"); + TAILQ_FOREACH(ddevice, &dbus->device_list, next) { + printf(" Addr: %p\n", ddevice); + if (ddevice->dev.driver) + printf(" Driver = %s\n", + ddevice->dev.driver->name); + else + printf(" Driver = None\n"); + } + } + printf("------>8-------\n"); +} + +static int +test_bus_setup(void) +{ + struct rte_bus *bus_p = NULL; + + /* Preserve the original bus list before executing test */ + while (!TAILQ_EMPTY(&rte_bus_list)) { + bus_p = TAILQ_FIRST(&rte_bus_list); + TAILQ_REMOVE(&rte_bus_list, bus_p, next); + TAILQ_INSERT_TAIL(&orig_bus_list, bus_p, next); + } + + return 0; +} + +static int +test_bus_cleanup(void) +{ + struct rte_bus *bus_p = NULL; + + /* Cleanup rte_bus_list before restoring entries */ + while (!TAILQ_EMPTY(&rte_bus_list)) { + bus_p = TAILQ_FIRST(&rte_bus_list); + rte_bus_unregister(bus_p); + TAILQ_REMOVE(&rte_bus_list, bus_p, next); + } + + bus_p = NULL; + /* Restore original entries */ + while (!TAILQ_EMPTY(&orig_bus_list)) { + bus_p = TAILQ_FIRST(&orig_bus_list); + TAILQ_REMOVE(&orig_bus_list, bus_p, next); + TAILQ_INSERT_TAIL(&rte_bus_list, bus_p, next); + } + + return 0; +} + +static int +test_bus_registration(void) +{ + int i; + int ret; + struct rte_bus *bus = NULL; + + for (i = 0; bus_map[i].name != NULL; i++) { + bus = &(bus_map[i].dbus->bus); + rte_bus_register(bus); + printf("Registered Bus %s\n", bus_map[i].name); + } + + /* Verify that all buses have been successfully registered */ + i = 0; + TAILQ_FOREACH(bus, &rte_bus_list, next) { + /* Or, if the name of the bus is NULL */ + if (!bus->name) { + /* Incorrect entry in list */ + printf("Incorrect bus registered.\n"); + return -1; + } + + /* Or, if the bus name doesn't match that of bus_map */ + ret = strcmp(bus->name, bus_map[i].name); + if (ret) { + /* Bus name doesn't match */ + printf("Unable to correctly register bus (%s).\n", + bus_map[i].name); + return -1; + } + i++; + } + + /* Current value of bus_map[i] should be the NULL entry */ + if (bus_map[i].name != NULL) { + printf("Not all buses were registered. For e.g. (%s)\n", + bus_map[i].name); + return -1; + } + + printf("Buses registered are:\n"); + rte_bus_dump(stdout); + + return 0; +} + +static int +test_bus_unregistration(void) +{ + int i; + struct rte_bus *bus = NULL; + + for (i = 0; bus_map[i].name != NULL; i++) { + bus = &(bus_map[i].dbus->bus); + if (bus) { + printf("Unregistering bus: '%s'\n", bus->name); + rte_bus_unregister(bus); + } + } + + if (!TAILQ_EMPTY(&rte_bus_list)) { + /* Unable to unregister all dummy buses */ + printf("Unable to unregister all buses\n"); + return -1; + } + + printf("All buses have been unregistered.\n"); + dump_device_tree(); + return 0; +} + +int +test_bus(void) +{ + /* Make necessary arrangements before starting test */ + if (test_bus_setup()) + return -1; + + if (test_bus_registration()) + return -1; + + if (test_bus_unregistration()) + return -1; + + /* Restore the original environment/settings */ + if (test_bus_cleanup()) + return -1; + + return 0; +} + +REGISTER_TEST_COMMAND(bus_autotest, test_bus); diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index 2250269..fe0f69d 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -56,6 +56,9 @@ extern "C" { /** Double linked list of buses */ TAILQ_HEAD(rte_bus_list, rte_bus); +/* Bus list exposed */ +extern struct rte_bus_list rte_bus_list; + /** * A structure describing a generic bus. */ -- 2.7.4