From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0065.outbound.protection.outlook.com [104.47.42.65]) by dpdk.org (Postfix) with ESMTP id A3A355591 for ; Fri, 16 Dec 2016 14:09:02 +0100 (CET) Received: from BN3PR0301CA0005.namprd03.prod.outlook.com (10.160.180.143) by MWHPR03MB2480.namprd03.prod.outlook.com (10.169.200.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Fri, 16 Dec 2016 13:09:00 +0000 Received: from BN1BFFO11FD033.protection.gbl (2a01:111:f400:7c10::1:141) by BN3PR0301CA0005.outlook.office365.com (2a01:111:e400:4000::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.789.14 via Frontend Transport; Fri, 16 Dec 2016 13:09:00 +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 BN1BFFO11FD033.mail.protection.outlook.com (10.58.144.96) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.771.7 via Frontend Transport; Fri, 16 Dec 2016 13:08:59 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:806; Count:10 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id uBGD8BtE028345; Fri, 16 Dec 2016 06:08:56 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Fri, 16 Dec 2016 18:40:44 +0530 Message-ID: <1481893853-31790-4-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> References: <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> <1481893853-31790-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131263673399101233; (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)(39860400002)(39840400002)(39850400002)(39380400002)(39450400003)(39400400002)(39410400002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(50986999)(4326007)(105606002)(5890100001)(626004)(104016004)(81156014)(2906002)(97736004)(50466002)(36756003)(8676002)(5001770100001)(33646002)(81166006)(189998001)(85426001)(356003)(8936002)(5003940100001)(5660300001)(48376002)(50226002)(38730400001)(86362001)(2950100002)(68736007)(8666005)(305945005)(6666003)(92566002)(76176999)(77096006)(575784001)(106466001)(47776003)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2480; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD033; 1:FziOp+b2XqH5UXk8jnI9oIrkdaGR9DZDW1o7bEGfNVIBfF6pvD9aA+sxyW1ifq4dvk2S6drZ8ztNJWGRCUOLTjGUK5IcUmVwYLaKCBvPauQHXFsn8J0Q+K8UmsHJ6pKW9kzxdtv6/BYQ78TXirbGoQ0QheQqS+OmJuu0MONy+0xr3BdJwwxjZF5/69C6QF/JXxWAQOkp3lr4nVNeqKB1QY3lp52AnVPyZSTpleb38cETFESv+UBk14/VPY+0/8qBxTQmW/HfDrKoXy7HfHCGMW64FXGUc0f5SnbcuMCkmntdAdCEql/7GkLCbcBcnSMqXR4ryX0fyyPim+cgjcQFkXEk7GJzJp0IL7tWSkLa1v8IKRVmNYsP6h2soV2b/+c4fjpHb96WCDhOLwSnS14UPjy7vY6985a9CtKvmyV3Oe8E7OwnOqXJBKyO2pmirvDu0EZhF+LTRdgklRSdlLAnK3QfLPyAWuY1ecvMl2UHj5ZJWpggadLUq8mHsY6ZXQPFMFNGqjZgrAqfhZX7CjHCGVW0BhbMctRRBUC7vfe8vxWgytmy2mi2eUamj7n5VeIwwPfAWG9Tz0LpFzn4+9RZBpeFf97+ClrOWW9TbvMijb8u4D9Kc/z95WR8uEgFspqNw6hCb6PiB+XsPMmxm/tKGEkJP1H/br5F02Q2oPwxgJDjpermewGf/iZzMMlWbkXU9gi0eliLkuDBySgiS9UQJhYq/JpDRzgNU6i2uDVY/r1Wa/rLkRxInhKEtPJ9xoCj/iKuGLopd43MlMpmW2jo2w== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 3aac2443-06d4-4efe-bc39-08d425b4b341 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:MWHPR03MB2480; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2480; 3:HjItfAF5vCT1CuCwMxvih07+OYxevWBOIBBVBCk7wVbleB0qR4vwnCisfJZUmuaB5h84oOr2w9gXI9lHE3NEETsPGI6/mKfU1bK2q8pSmEjkgRWWq6egkyanprqQKjav41QLcM+hV7Hr/5VGx8bjV7Fm4jBWD++2yeB3lVNZnOLoK8RbHPP+fUMHHrEZ/P6JSDY+dJ1Fzjs/MHNTrxXn4yNJYnnzxvzTHNJJrjCA54k7ZQlD9RFFWolHvKqTTOwWwem5kNhLUINpb2dLBZvgRAvtaOQ57c7p7VmhrgmH+Lb2q+WM8VhWfQRUGPtsUjAmu2LRbMHN4mr0jXzT+cxoijIcODr9NMILZvw0ZH/jZ7/bRqnBwRZIouvbYrzEzypb; 25:Xe7pY99BPPzgAs5lRd2Ym76oQo2XopbwH7tl7Ed4jQtc2CpRNG37MW4SUTww3ikgR171Wpw05FJr0IUdh9Ojl+eP3K+hzm1/2Lr7SEtPbe6ZobkAVOM2KaQobhtxhzm+hg4jX0rYDM9NcbXyN9MU9CRkEC01WabxRKK4SOMWqcGS3rwx9gDWggZTPyqOltLyhj7TWDg1GAA09gkXkt1Ky4krDwoRJEnbBcauZYDuqJrpg9oAvVWU0BcUFNzxIaQIYd3KnMqbnzZxIsd+rAS1aiYI7cbMW+uw3rw8rR1Yuf4LiO+Dt5LqoTLckI9z50ayY1kjcYQwGO+krG7lrJMBvKhHwveVjx/GUaNlKDINtsGLdYsqGCaYkeCKHEtFeMzUUNkJDVp9pgwmVq7VOgR3xuReR0WcgXvECS8CdyVKy4T6XehOHpLY3mTknJcIacevrVKGyoLu81TWGgIb9LCZYw== X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2480; 31:Og+SOLvqzeG/oM5gfVb1fyYkK9fQrw+Ke17sDk93iZSK11JHzs1YDLSGNeSxdB7JB+3rJ1OAvdIpJnfoRmiJMgZf2sY8LHfwLQiN+KKToQvcQXtIvt6i39g06NJ8L+8CpTQAiDkhbW1KLEStte7MjcUli84UMPFAi43XZAsnEOiX+3LYfiqct+DpS81v7HZ0zR5kT8o4avLi3v7abFVb0tYzJ9BGBx5cb/sXtM0H9nqLBttRTZdZJEmV/pM5VzwV/kAISzWUlpK8bvtGGdNSXHOPl0hjR8Nacd+TKlVOM7U= 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)(13023025)(13017025)(13015025)(13024025)(13018025)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6096035)(20161123556025)(20161123559025)(20161123565025)(20161123561025)(20161123563025); SRVR:MWHPR03MB2480; BCL:0; PCL:0; RULEID:(400006); SRVR:MWHPR03MB2480; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2480; 4:0LZCXrKidXx99UtTzcsHQMmY9sun6CTU9Rc2gw8cTm9mVT0AQDaHZoXeZFSLazLKcIBfQKfIPoj5mh+CBOk3uXBVAmqcB4l/P03DKDzSjwYsHn8YWAzF9ceVWAJKFoRIjvYgiqkj7BnAiYPqoxSQm5M665Apf8LGikF2LikG+1J9VNp2sZqWbIctbUk6D0YduS/2bDZObBcvLwnKW9PLN7TPDEqLAr7yfTIqkxkIn2azv+xgg38HgdjCzy6kK6gsQWBNVRL8s5F5OyxVRx69OpRGXbxOIEj1TD5ugDUkrmEdjsIBLbVuKex2hZ+momKC33kHTTqJfIz4Fv+D+ClEyLpyUWk0x6lD9NstoL9ku1n/1ny1kb7GKxRjfQjCvCtqK57xgvaClmmaK6gfRQ4KcbBc0bivNAHtVXaQLoZdyCuFIOuquvZD6y3AdwcgOi0rSqEN0oGKgeOAMpoJPS3xd0t83EacpHtlD3z1zvkR39ZccsE9A2R2p+9Ok39qdpJ6veGfsnuIVmoy8smbYls/ywqMJ2Wt4oOEp8e9xkuUTtuUR209OPjr6vwxlMFPAtDxB7sd6jJybxzHir/lF5wSgQEW5PfswTVDiVanv+0hSsrY1pDyUhHeW1LTMf8Vi0AzISQh/Hndz/ZWYI3tSe04pTWjSG5WU54Np+TsQJSejcaZWIO0tQG3AXx0aZE3J4Jkebc372Iyfy8Oeydlg8kFwWZUjfWJjgXs3RioADg88Vc+nOdgGRbewHrP3uyKOxNF X-Forefront-PRVS: 01583E185C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2480; 23:3CskNbXTaFMyU2+qsOrMXyGSmFBe1+5PYWj4gW1NI?= =?us-ascii?Q?WiJc4r4yz0ViKamZJCUXrR7uznA+jTdjP0DAkdEBRD77G//eZx4xgDr9fpFA?= =?us-ascii?Q?zP9mTNVO00g0/SAtekoBZFKR8n1do29GMA0VT7/UFBturUT0kwB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qy1TQ5VIo1ByFogtM7rBjuiCR22n87DwarkByQt7NC/ylRxi6D9lreRWVKhQYi7TtTytLbAiCIaKi8chi4vaIK9wl6Y8MZKX8= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2480; 7:kn9xlQZrmd6hJZoG/LBWubFO0moztqEBuNIRl9vYiRnuUeTxzJRZabwqaVT80c5XmW7oNLl0eqqbQZYDjDPG0KVzdEWgmw4Z8XHkaz6kxzzOlkJetrZdG1XDa0T2uD4jm0JVFGoTTlQAoJpZog0wgxfDbPPjj3EMAwk8smALrKIzHuFio6DZtS4gmuoxBPHEMCOVm4gL7p+M8WSTU4MaMWrgV942zrFlkpvarpB21Bflth6yDkntVBCwEd2iox0L9vr6Eht6g8UyWA+eQftyrLeeg5z7p7TPIsI/FxUL1dEAS0493NRI8j269CGNHtJZmpJRskhYFgOFD7bQt6ysHUsOSAbOXnRrnJ7gQ1d5d5tyzNz3hNWxWaTRhYklmhIQ9jsPG0J9v2Wgqahrj+hqeIdAmM9RN10m1Xm9mdvf5uf/IkLhRG3ZE06QJPKPhAiF2UPyTCfC2JtF243uuDktBQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Dec 2016 13:08:59.6137 (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: MWHPR03MB2480 Subject: [dpdk-dev] [PATCH v3 03/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: Fri, 16 Dec 2016 13:09:03 -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