From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0070.outbound.protection.outlook.com [104.47.41.70]) by dpdk.org (Postfix) with ESMTP id 6E5FF558D for ; Mon, 26 Dec 2016 13:50:42 +0100 (CET) Received: from BN6PR03CA0023.namprd03.prod.outlook.com (10.168.230.161) 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.803.11; Mon, 26 Dec 2016 12:50:40 +0000 Received: from BL2FFO11FD041.protection.gbl (2a01:111:f400:7c09::159) by BN6PR03CA0023.outlook.office365.com (2603:10b6:404:23::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.803.11 via Frontend Transport; Mon, 26 Dec 2016 12:50:40 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD041.mail.protection.outlook.com (10.173.161.137) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.789.10 via Frontend Transport; Mon, 26 Dec 2016 12:50:39 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQCl90K011201; Mon, 26 Dec 2016 05:50:37 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:20:34 +0530 Message-ID: <1482756644-13726-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> References: <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131272302401211091; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.158.2; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(7916002)(39400400002)(39450400003)(39850400002)(39380400002)(39410400002)(39860400002)(39840400002)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(47776003)(4326007)(2351001)(50986999)(2906002)(76176999)(97736004)(48376002)(50466002)(189998001)(81156014)(81166006)(8676002)(36756003)(8936002)(575784001)(86362001)(5003940100001)(50226002)(68736007)(69596002)(8656002)(104016004)(33646002)(85426001)(38730400001)(105606002)(5890100001)(626004)(2950100002)(77096006)(106466001)(6666003)(5660300001)(6916009)(356003)(110136003)(305945005)(92566002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0751; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD041; 1:aAGfSF3lA8KtWjpLOrzXEO4q/maWjkdZhUVRt8frl8HtCV0qGTcxrvoy6F0KOY+cihIUE3GdPIkvHA87ZbwXYXzg6KA3IZW5qMKGbwOOVQ5E0nm5OyuQePcAj7FfcXAw1WM4DLXgjveZNf5TUGQ0hol11ICH3OWfYVul0tzF4sRMIfwktaQBinZNQkC2OV2y7dQbLWTMEmoGZ+QNci44+y5eT855VgRlu9Du7PtlRIGoRcSU9Ppnk2u167I8onICqDr0RT5Xu7cLweREwd8qQB3esjsthv+h2ygtnDYBgeatYt1ulvgapD8z8XE0UKoA8eT6brCwVMyMn7nS8kCbgc174eMv10JjG0zHxDxYywYY48808ov5p+ubLoNuTRQzfo3TVr2Ze7rRWVIpHURTVU7B96UyiZEsAGW/5+eXA71rO8OzmvCkzYBzQ/iG2xTBLXxg/wsbMpOXJLjzlbtubqgTC/GnmBfkk9zZLHOasNfnTwCN/oCdRDJcsyLzarvvLtdbRfahgoSRXI0Lc3WJnwBIYLK/EwhHRx1fd9Zj+ykuW232rQJX+2Pd2ONbRbS2uwUA3TRCRxnrBF3MuicKGad/HdisiwwyJMVr+CZVcimJYBMEmHJrXDfHbCC10V19AEjiYZFtbbedPiuN5XDZC59S7Q61dr5lioBTql1Z8uT/hyzhAGqNRPsGsC6Hygz6O/9SCNfMo+ymK7PYlJzx1Yzn8MYxu/mMtn6NJK6jKCk= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: f74d95f7-304c-4df2-6972-08d42d8dcbed X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 3:opr4Un5/hZmnGww4p2RyhOL6ctfCLqmAzGNAjPvDdrOfMWKsqgrtmVGtIsNwLJxGtGYNxtGtFFMgmtOS2RPRQvmEgoQatNhtvHiCYq2IruqWVVHOF+MskeHwqJDJJwf+V1I7abJowxeeTKRTQPSzGM/UXaDMyH4ah1NSyqUERqL7LrYoS0LuWyFrHeoln/YpiowvsCNYI+uwt7UeU+ftF24lom8N4DIyvfpYboBrVh9oD2W9NkZsjSwhkjty0EiymOgz1ejl+aSPtHEX/Du4Mrx3z6lqzJJTLbDgyWm8oTZU2iackcIqiei2fp9poa1hqC3S3MTtgk6wlbgDdC+cSnTTZ8YegmpkvUckjzsrJ5k= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 25:jXBcSHUedPzJZOr0PD3u4cLDVxTpaxFaEC393ztGvjknQs186ppwpQ494Fh4rloTJHgx3IK5wXHKHHtTXI7M1Hlp7esfYWHrSj1HZ4guYO1+RG/Nufn/4DKzqaWGguo7g4AwRkhgGmIzKIfGd9Iovc7JCATw9N6oLCcy4c7cTMPry4qVbbRfHRhG2JnyBzc+X32nOd0sAhxOTg0yTS4Dy7MEatIyEPyFHBPSv92kmokd6e+2sPhGt9BoL5GCYSmBD64FstBmI4DBnIQ+Mb0ZPxr+0fJhSbzEpHyxKPie0yUC4naNUwZ9kwZUnepbM6B3a0Eq85kb7V3bJEDAVdvBNRULVrFMHC0mqROKzQO/gpDPG0GXVN4aLJgFu4RRwSVC/93hB6lFqu9ZVQM/KkPwb9j56FSnoC6CzXlRqd3Rrlh5DK9DyBhP1hxQ66edxc4IIBJ1kWQTUp7NWbZN/JOXISJoCy2DlSEAqfcrp9vu+3wWX8L19UrbwTNBpMqYZj19XbO3+l54TeYqk4mbvhxGt/Z75gM164FWcgsc3bZB2r6xLdFt2sgsY5adC9wQq4C0k8pARhhaxEgEBGV7DH8i4Yd/M96iXaa0njizHGIp/pNARI9ivlbMzWWNjER9c8bmtcqcgGVCd+Ap/Beaws5gkNSKcmBVqFi4wVXxasls2wSwI86DrQQX6M1O/ZVQfrnLMUfumzXMv8SVa76iqtJiPpLdkWwhoPlzRtUrvUMF+1TJUKBaTAFla4GPB6WQa3MPay+e4VIPmISz6Wzo30MSDvve3lTnZ3W1kA0MRTMhrdo= X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 31:F0X+wynVmuLvf/hv7NfW0+nlrokyhG5p9W8s7ix/roW0odyssWkDBLABSEpT/l1tWl+9Qs89FuPGffxLC08UkWcGGfIwLnZVtWEjJ/hGognantLbLwgxHvpPfONeRXlcLE9oe1bHrdQzTHfuglHaRoghsHGOt6wPcKcXrVb9MsKhgy7c6TVLeanuo95Wmovz5pStk1cgjNWPT+3JM3841+502G9z76wc9MCYavxcxn1OnbS+pfS3Zs9IsaxULtYx/7DKgoGvmAKqtFx8TAHkjg== 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)(13015025)(13017025)(13018025)(13023025)(8121501046)(13024025)(5005006)(3002001)(10201501046)(6055026)(6096035)(20161123559025)(20161123556025)(20161123563025)(20161123561025)(20161123565025); SRVR:DM2PR0301MB0751; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0751; X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 4:klZCaxSTOdOZTsM5qjBtrV2KB8h1SRdXrL6nDeMDLawEF3avmoHIEMjlmnC5AikWGpJUuMpBEk3PRmphIeb0yeUw6O18EtwUoTBivWhTePWS/xJ9Ns4xkEyaEIXp9wzQ+uUeac3Db/U/6bF2/kyuAYH3oguFM4UNjk4ifkfuQIxpj4yXKtIEDF+O1jJMazCqT3FpbyznuiIIvcQnfj9IUHvFcKMwE/z3/qDjlQUm909jBoPCNztsQVujNmSpDX4C6uElxsq73rJtTQnj5hAdNL86JXBP+aq4pF4823h/6+u1VytIfiHzDDiCGwkMd/+2ehYpfmXGF/fiHGvCiusaM6WoukgdpAYIS69Zf2Btyf/o8J8zWNIU76LVTht+O+KYrFu8RHkuFEkFAWXEUi1mX7AEkkF9Fx4408dc7Cn5cE8E77WDdO1SW1OACIJZ/AEgQxyQ3AKY09LdIXEHpQH6v83K9f1jpnWuuWCnmc8yRkZBuz02U3Igyv7Mo6tHmIOobAGGHjOrs6dBiev+OYkrAq4cH/NQNkgfgPPqXFW2saTi/+7VcOvRjteX2D9iri0Qfp7C+mXBsCcvFzatitIQpGZFeKK2xlFwccL3rg090guUm9d3wSpdZ+mG2xoMIvhdVeyAxnLz0ERzft8LryNES/cjRPro5VMKaMjSbRs1EDJ67uU5ts/XacUChputB9Cj5kkU7qEi6K17QFQugiEWEL7aQYQHFlYBTb6Y4M5pbuMc6qvGZtb0E72gxnmxYAsL X-Forefront-PRVS: 016885DD9B X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0751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e5jkM3w7ULeFSHnRTCrwQBBhkTJxEA/JVzygFHLhH; 5:lKRqEqycoB04JmItilsknVKvNlW8NMe27q2rrdswwvUtZhY3E/72m+dXDVI1wUcLRi0eagW+bEXrV0ob/66NiVKZCuEUBgjJpOfzjfA6ZWrbkVXv71AXr7MwsdRMA/tbGcTY+usPPBC6d6PuqLp1BnFOczDpdwzjiwHLTyBhoukGNZJZNF0rCflVxKKQh0wH; 24:wEjp9owHIVehDtQQ1Cz2KhVnFjz9ePN+sMaSFPv2MExqpRENvW6wjYsrLUbjoVlctgPsl9cTIcDx8alt6M40GTVaK6QUD4BcXce3uS7D0dQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0751; 7:t8GYxwP3e4o9gAGz1rTNycDVr5+Jd/8ue3HfTFJvEENaHwyT7/xdXuCOOFi6qswQc7q/olZLO4J9BV5v4Qb660uAdCkotLNmV2/Ds0NUPb9/R92At/pGkIBWsf7EMdmgEYDYowrt+deiyg7o8FpPbr6ZQStgG05rx5BD/nAQMo/mPpLfPAwT5B1stNT9lky5hX1LTZMrAXnDrhPs0grRHpPXw5Dp5IehJB7cbd2OnBERVVQnoud3Ogue/nK353F+aRkHd5AHCRxFQKN1q/2wtPzDA4wQhvsawflobjf8R9pIeovfgTON7/c9/zEgkw5lMSbel1bJ7Xav0U4bLveMUesX4isgvKtSGmvgXIBMkmg1Unw7CuEkuh7WHjaJQxKndPYPCcrRQ/ks9JcEODiAeknaO0/lvmlMfY6JQzsimPfi/E0Tnkuw8wPWhpiNzA28AH71CqhzwNB9ldfiQ3kDxg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 12:50:39.8871 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0751 Subject: [dpdk-dev] [PATCH v4 02/12] 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: Mon, 26 Dec 2016 12:50:43 -0000 Verification of bus registration, driver registration on a bus. Signed-off-by: Shreyansh Jain --- app/test/Makefile | 2 +- app/test/test.h | 2 + app/test/test_bus.c | 424 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 427 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..60950d3 --- /dev/null +++ b/app/test/test_bus.c @@ -0,0 +1,424 @@ +/*- + * 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 "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 + +/* A structure representing a ethernet/crypto device, embedding + * the rte_device. + */ +struct dummy_device { + const char *name; + struct rte_device dev; +}; + +/* Structure representing a Bus with devices attached to it, and drivers + * for those devices + */ +struct dummy_bus { + const char *name; + struct rte_bus *bus; + struct rte_driver *drivers[MAX_DRIVERS_ON_BUS]; + struct dummy_device *devices[MAX_DEVICES_ON_BUS]; +}; + +struct rte_bus_list orig_bus_list = + TAILQ_HEAD_INITIALIZER(orig_bus_list); + +struct rte_bus busA = { + .name = "busA", /* "busA" */ +}; + +struct rte_bus busB = { + .name = "busB", /* "busB */ +}; + +struct rte_driver driverA = { + .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 rte_driver driverB = { + .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 dummy_buses[] = { + { + .name = "busA", + .bus = &busA, + .drivers = {&driverA, NULL}, + .devices = {&devA1, &devA2, NULL}, + }, + { + .name = "busB", + .bus = &busB, + .drivers = {&driverB, NULL}, + .devices = {&devB1, &devB2, NULL}, + }, + {NULL, NULL, {NULL,}, {NULL,}, }, +}; + +/* @internal + * Dump the device tree + */ +static void +dump_device_tree(void) +{ + int i; + struct dummy_bus *db; + struct rte_bus *bus; + struct rte_driver *drv; + struct rte_device *dev; + + printf("------>8-------\n"); + printf("Device Tree:\n"); + for (i = 0; dummy_buses[i].name; i++) { + db = &dummy_buses[i]; + + bus = rte_eal_bus_get(db->name); + if (!bus) + return; + + printf(" Bus: %s\n", bus->name); + + printf(" Drivers on bus:\n"); + TAILQ_FOREACH(drv, &bus->driver_list, next) { + printf(" %s\n", drv->name); + } + + printf(" Devices on bus:\n"); + TAILQ_FOREACH(dev, &bus->device_list, next) { + printf(" Addr: %p\n", dev); + if (dev->driver) + printf(" Driver = %s\n", 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_eal_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); + } + + dump_device_tree(); + return 0; +} + + +static int +test_bus_registration(void) +{ + int i; + int ret; + struct rte_bus *bus = NULL; + + for (i = 0; dummy_buses[i].name != NULL; i++) { + bus = dummy_buses[i].bus; + rte_eal_bus_register(bus); + printf("Registered Bus %s\n", dummy_buses[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 dummy_buses */ + ret = strcmp(bus->name, dummy_buses[i].name); + if (ret) { + /* Bus name doesn't match */ + printf("Unable to correctly register bus (%s).\n", + dummy_buses[i].name); + return -1; + } + i++; + } + + /* Current value of dummy_buses[i] should be the NULL entry */ + if (dummy_buses[i].name != NULL) { + printf("Not all buses were registered. For e.g. (%s)\n", + dummy_buses[i].name); + return -1; + } + + printf("Buses registered are:\n"); + rte_eal_bus_dump(stdout); + + return 0; +} + +static int +test_bus_unregistration(void) +{ + int i; + struct rte_bus *bus = NULL; + + for (i = 0; dummy_buses[i].name != NULL; i++) { + bus = rte_eal_bus_get(dummy_buses[i].name); + if (bus) { + printf("Unregistering bus: '%s'\n", bus->name); + rte_eal_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; +} + +/* Positive case: For each driver in dummy_buses, perform + * registration + */ +static int +test_driver_registration_on_bus(void) +{ + int i, j; + struct rte_bus *bus = NULL; + struct rte_driver *drv, *drv2; + + /* For each bus on the dummy_buses list: + * 1. get the bus reference + * 2. register all drivers from dummy_buses + */ + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_bus_get(dummy_buses[i].name); + if (!bus) { + printf("Unable to find bus (%s)\n", + dummy_buses[i].name); + return -1; + } + + /* For bus 'bus', register all drivers */ + for (j = 0; dummy_buses[i].drivers[j]; j++) { + drv = dummy_buses[i].drivers[j]; + rte_eal_bus_add_driver(bus, drv); + } + } + + /* Drivers have been registered. Verify by parsing the list */ + drv = NULL; + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_bus_get(dummy_buses[i].name); + if (!bus) { + printf("Unable to find bus (%s)\n", + dummy_buses[i].name); + return -1; + } + + j = 0; + TAILQ_FOREACH(drv, &bus->driver_list, next) { + drv2 = dummy_buses[i].drivers[j++]; + if (strcmp(drv2->name, drv->name)) { + printf("Incorrectly registered drivers." + " Expected: %s; Available: %s\n", + drv2->name, drv->name); + return -1; + } + } + } + + printf("Driver registration test successful.\n"); + dump_device_tree(); + + return 0; +} + +static int +test_driver_unregistration_on_bus(void) +{ + int i; + struct rte_bus *bus = NULL; + struct rte_driver *drv; + + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_bus_get(dummy_buses[i].name); + if (!bus) { + printf("Unable to find bus (%s)\n", + dummy_buses[i].name); + return -1; + } + + /* For bus 'bus', unregister all drivers */ + TAILQ_FOREACH(drv, &bus->driver_list, next) { + rte_eal_bus_remove_driver(drv); + } + } + + /* Verifying that all drivers have been removed */ + for (i = 0; dummy_buses[i].name; i++) { + bus = rte_eal_bus_get(dummy_buses[i].name); + + if (!TAILQ_EMPTY(&bus->driver_list)) { + printf("Unable to remove all drivers on bus (%s)\n", + bus->name); + return -1; + } + } + + printf("Unregistration of drivers on all buses is successful.\n"); + /* All devices from all buses have been removed */ + 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; + + /* Assuming that buses are already registered, register drivers + * with them. + */ + if (test_driver_registration_on_bus()) + return -1; + + if (test_driver_unregistration_on_bus()) + 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); -- 2.7.4