From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-DM3-obe.outbound.protection.outlook.com (mail-dm3nam03on0081.outbound.protection.outlook.com [104.47.41.81]) by dpdk.org (Postfix) with ESMTP id E718DB33E for ; Mon, 26 Dec 2016 14:21:16 +0100 (CET) Received: from CY4PR03CA0003.namprd03.prod.outlook.com (10.168.162.13) by BN6PR03MB2466.namprd03.prod.outlook.com (10.168.223.20) 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 13:21:15 +0000 Received: from BL2FFO11FD033.protection.gbl (2a01:111:f400:7c09::144) by CY4PR03CA0003.outlook.office365.com (2603:10b6:903:33::13) 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 13:21:15 +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 BL2FFO11FD033.mail.protection.outlook.com (10.173.161.129) 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 13:21:14 +0000 Received: from Tophie.ap.freescale.net ([10.232.14.87]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id uBQDKVCS029786; Mon, 26 Dec 2016 06:21:11 -0700 From: Shreyansh Jain To: CC: , , Shreyansh Jain Date: Mon, 26 Dec 2016 18:53:55 +0530 Message-ID: <1482758645-23057-3-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> References: <1482756644-13726-1-git-send-email-shreyansh.jain@nxp.com> <1482758645-23057-1-git-send-email-shreyansh.jain@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131272320746743119; (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)(39840400002)(39860400002)(39380400002)(39400400002)(39850400002)(39410400002)(39450400003)(2980300002)(1110001)(1109001)(339900001)(199003)(189002)(5003940100001)(8936002)(106466001)(50226002)(47776003)(85426001)(5890100001)(305945005)(92566002)(81166006)(38730400001)(86362001)(105606002)(97736004)(76176999)(69596002)(50986999)(8676002)(575784001)(189998001)(81156014)(104016004)(356003)(77096006)(110136003)(626004)(2950100002)(6916009)(8656002)(50466002)(48376002)(6666003)(4326007)(2906002)(2351001)(68736007)(36756003)(5660300001)(33646002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2466; H:az84smr01.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD033; 1:HDl2MOKIVjQm7gpY70sOY77H+lHiYTb4QJ7muJE/onMFw7Dz+8/Mg3PxP7wvK2dmHMFPy5tDK7epdLD4GLuPUfrTk+Po1uTlA4OtzYVXQQxgXCS/MRoJiIsQws3toSi3aFKhDupVkfWt9jh0NYGE2GpcjcVRSqHzwFg606drAqRVeZIEJxgihQGZEC5WM1apQbhHE+WK7X9ILqBmOZA4RBa+BV+LK4/kqUFmcF065zhdVAr/e8A249I2hFjDk4xzUaAv2yl8E6Oc7+bdsU2I5PBpF+WMN/fx11+Ge9fpyIMHS5T/oNIPlsOPg8whlVMKopk3pLsUHMC9Cr5TORKL7aX8dBXS1GMGipmq64c+kw1UgjXTmY0ZNQ341WjRFw2W/Kfj8wc/uuqLUGQ5RSMd5YSTS2X1CX5WWJSJHoJDhk19Msa9pam+XaIK/bVrMc3eUuGzZezS2jzrAomaPXOcTo4+9CkDqzEz90FxRD0r+Ur4FeWSJFNybO7ko5cf56te0VVOx+uuHhWmnPFODW3hbEWh40cnaFHcvImMzF3HPDqp5I8e1KSSpvuVC0WIPjUsQrqvyHvXbB1Mq5Pa6fI6OcjFWA0KvSYLoczQ2dN8sx5G5Eud1djjf+UgcpDkCqL/PIJGNGST1iWIHYCTaU6yIXLdC/KW0jrN9aLxSxvE07pkTsgYfglmRGnshUjKJjOjzRr/tu/K1FeoFRDNv02Opz/xRPj97hGwRkF8lUktuRY= MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: fc694c75-e85a-43da-f8e6-08d42d921154 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN6PR03MB2466; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 3:crwWlHYu3SsNJU2G5G+zan8J2LqFW6kzOxWsbkWn+84/nMKPuw5tt1I6tONmpVFP70SL/RJmvKtLcZo/i2wfEEnxWn3QMI0p+JCa70DERGNC6+ZOS2fvzxJ9AQ7YnRJFhiHiEX47k+TO/AKaUFRJ/bf8HUiRVPOjw/aSmhJaur1fnQQV/VxEn8riR+OE1trI/3KJPwtT/pYVn439m7E55GC+uUMFHWlTE2XsG8+4reIjqVSV18uLMbkLMgQdgJsesfXK+qs3mL1Z3qFtOpjd52hqAIopG7q5t2ng1lQIhFZF5/M+K84oYDY2MtZ+3JQqwfVBRiPjukaulhohI5iULboj/xA7tH36cwqmIasRomszwpZ8a5rAR9WJYkrxuh6q; 25:aqs4aoP4J7BzBoDEV2109boLQ12eWYUWJ0TN2ugfZQfo/cl3qn95PgzWP0nxGi2qTGUZ+omQStokOU41+my+k/aZbP9fh68O1rUHkIxGnqOR/8t4urJTeZTw9VXzgTESJXWofgrqfkg7A0JPgTGpFQr3N+YUf/FA0skc9azCHoCBUtvK3qAJLdRfeV094H4cMF8vtllrQnURNebXgIWbw/hz2Rzf7tjSHcWsEmrOhk+3xtyuMSKOaepuTMNfA7d3PSziPtjyYvig2kWwCIKmMbpPam6SJvlWm61hU+QMZteISiY/27rnqXJisiLbdf5Hh4pcHus6ae8guiKTnLEEZVU4zKx4vWhwqiEXeMG4dgQE0jdfyDu8k7m4sdw2/b7ekrTFOFqXWi92ckU3k2YEBnZAl032/kHKD45F6KyM1NtIIAUefBt032Fs/mutL77lLJFxALpSX1DAVF4ieob+PQ== X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 31:m53dlOQtA2KJymyWWnwAbD8ljmQrcnANOojnZb6yKYBDEJDhbTavz9ay4vI/XNOeSp96aSU9cBOtbmNoUT1QtmXPqFMaiFGEfftsvZyiGeqtA1z71cPwn3cpeBtBAmuTGXUF4KxCEA53EmSV+TOAUtaN/HjXmLKYHjx0ABM4+Mlvht6Ps5fDWurJFP2h3gOaRMq5Jhs2nBvYr+g5FXGFiN7brMVKuK+rkm2wjArxYbnerzIJvwswfOCeyTLVzQftNAyQXSStKoI4FA1PdXzT7Q== 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)(13015025)(13018025)(13023025)(13024025)(8121501046)(5005006)(3002001)(10201501046)(6055026)(6096035)(20161123565025)(20161123563025)(20161123559025)(20161123556025)(20161123561025); SRVR:BN6PR03MB2466; BCL:0; PCL:0; RULEID:(400006); SRVR:BN6PR03MB2466; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 4:hPym9e3Kq1MCIEZWJonKFkVH2IC+P+QLxqbcHf4MRdvWk9p+DpaCcX3RruT1hn3SBXZodwxu/U7CQWThIG4NkzMtrr6kT7vLO+cPEVhBePwmM/tRJXy6FRjUi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X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2466; 7:3fiiK7sA51uA7v9hHDryI9obNQw5oKXq4HuqUZns4GIkPCn5KLQQ5eoOEBchTjwq3QPAbgtf8/eEXQhu5EQRhf3RTf8rNxc0CJaCy4iR8zaiEyehNSp1Ujc92zQlynQn/z05EaZMKBTeyA4aoDq6Vk3rUlcC7/W+23r1sUMEDiqaYWDSSiPKjHywzSeLyaDUat1PugL9AMd5PeNNnqawSLD2LedxStk5hYuC1gtyueTkr3oIHp4Zo3KD0szJKadqsjUwRanoOUgVFS23QJQhsU3jzKqTWa1mp83pryPkxUZ+q+TeiQhbIrgr0RnrsoaAVYB2Rs9f7UpQB0W1hjXsI0oP/CfEskSHOft6BCXmXhQgv2BFGMzj8oV0tyrYMi7uOlh4xcLLER8tRCWYVEAenHcxVlaZ4dBM+Hl3s+gQMkLnsHon/jzLCtqMnhdDCaPOpRxvam9O3cUZwu97XIZyDQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2016 13:21:14.2843 (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: BN6PR03MB2466 Subject: [dpdk-dev] [PATCH v5 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 13:21:17 -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