From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0059.outbound.protection.outlook.com [104.47.40.59]) by dpdk.org (Postfix) with ESMTP id 030524A59 for ; Sun, 4 Dec 2016 11:09:10 +0100 (CET) Received: from BN6PR03CA0026.namprd03.prod.outlook.com (10.175.124.12) by DM5PR03MB2474.namprd03.prod.outlook.com (10.168.233.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Sun, 4 Dec 2016 10:09:09 +0000 Received: from BY2FFO11FD005.protection.gbl (2a01:111:f400:7c0c::132) by BN6PR03CA0026.outlook.office365.com (2603:10b6:404:10c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.761.9 via Frontend Transport; Sun, 4 Dec 2016 10:09:09 +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 BY2FFO11FD005.mail.protection.outlook.com (10.1.14.126) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.734.4 via Frontend Transport; Sun, 4 Dec 2016 10:09:06 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:689; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uB4A8pK7019825; Sun, 4 Dec 2016 03:09:04 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Sun, 4 Dec 2016 15:41:18 +0530 Message-ID: <1480846288-2517-4-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131253197486367537; (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)(7916002)(2980300002)(1110001)(1109001)(339900001)(336004)(189002)(199003)(6666003)(189998001)(104016004)(50226002)(50466002)(626004)(5660300001)(47776003)(92566002)(97736004)(68736007)(8666005)(36756003)(39410400001)(39400400001)(39380400001)(8676002)(8936002)(5003940100001)(50986999)(110136003)(76176999)(2950100002)(106466001)(6916009)(105606002)(81166006)(81156014)(39450400002)(4326007)(86362001)(2906002)(33646002)(38730400001)(575784001)(69596002)(48376002)(7846002)(77096006)(5890100001)(356003)(305945005)(85426001)(2351001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2474; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD005; 1:Y6c6UjbSMB2iulUyzbKUMu4gJI+Sm6I8fMteFpvJysyShTSN0LXLQhv7U/8GJq3+JCVGS+WWgYN7s8gc8s64dC3HPsxMosf/fqrZ67gB0Sl8ljNq3gdGuG4hnTW1ZB1I1wnuf9H2ZpBScfpodlSPfumcSebX3Z6e611EIwk+ifISqRYeid9Q8GAyxPWDSsem8GdF7psFhqgPUcZjD4wca8iY4yxVg+6hTKeUVm8+atUNa1VHvtxIdjBQtVuZYhxWHQXDPuZsQvfw/tHn0bWbA4FZMI36VF7e1V6zJTcxl1FcqIhk/sH4y8VgubEP6vE9dwNVqn7rgWUKL7Zh9wy59YxDxbEIM/eR4eKU0+9u0TuL4pSvlXgXn2fOomkaVyYJnCp0GDzxsIn7zXe6MZFSdUk1PTJhh+6daAyRPbCwxkh5OQeDVZQtWOr0Hp+sZaamYgRBTJiAqtCnHfkcDZ+0zz8WujZtW34oHlf0MF+hsnqXFqiLI0N4Xli2s8WqTLBDBUJ4ZNr0P4tLnjHYzQ0v8Jz+G503+wyZHYQ0yWB8eJROZ1hgwzlqj161o9wPsPL2pYQE9bzmTMlF8U5klcl2VO0y+yMyh0318jSxvYG2QakQJcaR7Oz/BO67ESdxr9iwxL6Dt07hpNABEb28A1O7UUHJ2S1mntdJzpO7JOoCqqUgNffxJKjRE/0Wro4GGc5YjSdICp5q2mtjMc8b534X+gSwz9WwN+OrV8nzQVpV2oY= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: f323f7e3-eabc-4353-c1d2-08d41c2d9643 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DM5PR03MB2474; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 3:K4GVoEFlg6lwjDi5iLmDA95ACmMoFlQUvGX301aPY+mANpDgztzdb4q3BORomB367Es7rrc9AVtdLHK2/Ix1RDs5VbLhgUr1QkBdRCf/sfrKV/NFxsaZFDb9twdXTqUGmkr0CgV43+X/zomDvnb0o6fWBgDj1riG/yVPXbgDmoDKMfGO82lirhPWOO478+fNwHgqJWNgLc6QanX4KHm9p0Jyfmq9S5Muu0gYaTDZaxWndXDW5iF001dOqCksiNGNXyeXioNWXrgZhIR0MNiYe/citw/+MosXB+GDl1gYb/1nwTgagInqnY6qanCjJl7zss4nTqqkICG+5MTdwKLMKGnJCrHnj+nIZ7sF6nGVWCzOFr31UBlLnAT5eBGsbrA7; 25:pZUk15KGz+zCN2XfHx9IbQla950wBxuf4Y5CwECwdwIVpmIQpIJBwIdoPkKaPQtklnoNEGZhxFjtMQosGWtuU0FfHGy4zeo6fSuaQqsOzim2CV118Zt9mdfQuMxn7NbsQpj1bK/Or96f/P3nwSui10sDwwRnMCP1Q8OBcWydqpswayYg7/w5+lIIQJazDgWPlQdFrOO5xqRsXmm89D5Kfu1rzzQQAg+6hPCYxIiZ+qjJiNsivZ0jrEYHzh3kHhlq5oPy9XR5uX09VyV+hoWUHRyfm4FlLYpc98NR/4o2BfqycXoHvwQhIWhRkG5PbobsSxJ354I9wwIRISIG6o+TX5sOcibQwxyy4xyU4gprZzoDdmdhOunm4wDsP6V9tKRafbqu3CUJdxqhFXL8hcaxh2Vp2D3fwEBxG48nSZFNTldeHK4GHRxBRaSjgAXptQw/cOUVxwaRdDxofQaqwp0X3A== X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 31:PqKBO1eq2kJwaXIOT2qjspn5736reQNP134KBZfZx2JsIgEQcpqwmEVSABhtlkbGMs2XkkEQsFRPWQlmFNwcSzwK7T+euOjRxRqyBP2f/YZj+qeJflJ6O8JiUqHHGpRlhuHK+YrWpwDzBGsDy/J/9D69SUoL7u1sSqwX/ak+ZY54Obq3vuX5QGiXuvRoEmff9VJ8rXybSIlgmIreXRmz0qliIkfk3tUH1HDRkaXosu5onCg5PjLoMbE3Dn2RdtajfkLHOSGpdiwlr4/u4dRoEA== 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)(13017025)(13023025)(13015025)(13024025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123561025)(20161123559025)(20161123556025)(20161123563025); SRVR:DM5PR03MB2474; BCL:0; PCL:0; RULEID:(400006); SRVR:DM5PR03MB2474; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 4:XG78TuHzfwQjQLGx5WctJK4ZynsCWmjQmpHxxP0WmE6cMi8lLfh89BUs7LyHtTXNuQP8IwWwN+XYjlMb5f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98gDKZjiVs6xlvswngGi3zecZIw6m1g8iYgKo?= =?us-ascii?Q?9AaGjjq/URwb9/pPXfSf85m1YeRYKigs1VOgoMdJFkNZRf31YGdQNx4VTpWn?= =?us-ascii?Q?/YFJ6iN0N9MIzhlYiVVxDZft+Vl+ah3zjS/Z5uQ9FQavAVz54Hk4eV1LK0bc?= =?us-ascii?B?dz09?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 6:Pa7vI00tX1E6GlUMuHud4y2FvxZbFyRCvVkBPtsbKXJC5Mhxkswl0JnKDEc5UhhOdeIVZcwQS3TytLWEaknHS/XtASzFB4PPp7UbUEh7qL6LEgMbh6qkxqqEqF3TXeNf568Y/LV3Cgv1lx6KmryHIiIlCUhUtRezWdwnKgblRx0OAqcohEO2tF+OsjPdYv725GoNRUBFunO/UTX4ztcru+3OAGu+vARab7PdoGsyRTmcLRYQ45IKHKgLQSxXvNh9U/1e1uhT9u8un+WMxxB5I2kt7PdXhjCJ9OHUnBnx/KwkbBtT54HlCaYhCTQDhiuh7bQsMXSZe+AjxKnglZx5KbKpawYlYQLVO+SEaKn1BZH8Ls2YQ7X90o48dWPMDDZIV9y0JTtexKTuETW8PpYpjJS1qAjsef6BVTAEafsn6Xub0yzn8VSVj63sbean7Ptj; 5:SS8H5SLLWCeTehv6h2/5/bQ5Swp4Oc2DNXd/IrFZu0hIDSA1wdH6lPiHqhDLL1VC83tCaFzmI8rhY+SIOzEL1PogZUZQNVPFMlxM7EMtENpNeSSFbwY+i/xMYlhKn62SPRfmAQdmclMugTD5XeJZNjbzMLVxZTaJ6M4ieaBpA0qM35fz8sumcwT9U7IeFN+n; 24:h1ZA8UElGKBwaTqCqQg2HMFrY88bld2k49/HuQXtLvkpEVJoAZi55Pbdyk8SpeDl5P5LLedHSsu31XS7/1tOdTHz2EZK8mgOxHLRuEoa9P8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2474; 7:NqT161UkDDYL6lA6q2gR6h6uZtZvBr2bz1KjdVew3ryCXxYOrjbiPxQ834hkOYL6JR50EJPITPt4exsLrs0SHNzQNJ1mcYT1sO2Kx2JLKBez6IMtA4/O3ioTIWNlWc6b60EjprJleouQpjGnVoaa79l6wTsQGult5U0Jc4R+tV/Yfrwr28lynle867lNPjiVK3WNIIPyPElSp04OotgPDvmO6ADFPK8WA0NT0v/hC+QX9MM0DFI/M3y7UmPKXtDzSa8kilysSnPNZVoM0FDEO8RTHPYWnZsJtvkpOE+D9t0zzLZ7u9lJFkgwGsEZWjdmfpexp0wOulfc7e01Q8yV2AsrryYjrUDj8hl/jgsjM0r1kzkQmC57zOj69NkEPSYLlbpfPqZeuyBs1v/esf2tZGz0WUFiF6kv8hXOWUm14KJf4S9K1G/Lrlpe2s1zdao3xywTAFwMwcQBXpCg/QqTYw== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2016 10:09:06.9207 (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: DM5PR03MB2474 Subject: [dpdk-dev] [PATCH 03/13] 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: Sun, 04 Dec 2016 10:09:11 -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 | 423 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 426 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..760d40a --- /dev/null +++ b/app/test/test_bus.c @@ -0,0 +1,423 @@ +/*- + * 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_get_bus(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); + rte_eal_bus_unregister(bus_p); + 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); + } + + 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); + rte_eal_bus_register(bus_p); + } + + 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_get_bus(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_get_bus(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_get_bus(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_get_bus(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_get_bus(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