From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0056.outbound.protection.outlook.com [104.47.36.56]) by dpdk.org (Postfix) with ESMTP id 7A9582E83 for ; Tue, 13 Dec 2016 14:34:53 +0100 (CET) Received: from BN6PR03CA0001.namprd03.prod.outlook.com (10.168.230.139) by BY2PR0301MB0744.namprd03.prod.outlook.com (10.160.63.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.13; Tue, 13 Dec 2016 13:34:51 +0000 Received: from BN1AFFO11FD043.protection.gbl (2a01:111:f400:7c10::184) by BN6PR03CA0001.outlook.office365.com (2603:10b6:404:23::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.771.8 via Frontend Transport; Tue, 13 Dec 2016 13:34:51 +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 BN1AFFO11FD043.mail.protection.outlook.com (10.58.52.190) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.761.6 via Frontend Transport; Tue, 13 Dec 2016 13:34:50 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:803; 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 uBDDYRw7005048; Tue, 13 Dec 2016 06:34:47 -0700 From: Shreyansh Jain To: , CC: , , , Shreyansh Jain Date: Tue, 13 Dec 2016 19:07:03 +0530 Message-ID: <1481636232-2300-4-git-send-email-shreyansh.jain@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> References: <1480846288-2517-1-git-send-email-shreyansh.jain@nxp.com> <1481636232-2300-1-git-send-email-shreyansh.jain@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131261096908443467; (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)(7916002)(336005)(39410400002)(39400400002)(39380400002)(39840400002)(39850400002)(39860400002)(39450400003)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(36756003)(2906002)(77096006)(575784001)(86362001)(4326007)(356003)(48376002)(50466002)(38730400001)(8666005)(305945005)(85426001)(8936002)(2950100002)(6666003)(81166006)(50226002)(104016004)(68736007)(5660300001)(5003940100001)(626004)(81156014)(97736004)(5001770100001)(106466001)(33646002)(5890100001)(105606002)(92566002)(47776003)(189998001)(50986999)(8676002)(76176999)(7059030)(2101003); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB0744; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD043; 1:85+75dWENJGnoWh5XEb0BLFaNbMm6pk6kcpamamJ6Zo654pjiNup8lDu/itFdxRo1+Iy7NAhlUJM2K+dq4TIy2p98bwoP86dgO1B8PDGYdXH2tnj+ojnCFvdJ46C9t0UeJZGXPnAqS/1HZmc5RjNq8FfpUvlSrtBEajzxwphLaIN/nWq/T33Bex+OZt9ATNuGEm8eZC1LF+6zSmMNHdIE7NPuMlvdGhJpz0KnxLh0Pk8jb3SawY2epSRFwgwS2sH5noOkuecOkp9Oha63MXwKiDNYi//ShmlZtgbT9sjdA1t13xqXv00u4pi+35EF2QIGDM8VCvJWX2o+P6N19UcJqKw2W1vUGUgqzdB4/6aut+U+QDOYnjGdLSm2Vxm757gmmn2gm6ebJZbW6/Rdd0/mtDfbYg6njVqGcP2LRPu2shypODwxYWJ/DFPhrHrNzYX7X/7vVf+d5q91kGRLZ2blvTcD6VlXnNhmZHBe+RYV1v+I5PowxjvjCliLRX2SHtVlXN95k0w1wFFLVNxPIkm5Qt4YW+K6an9raPc6LMMWkkuNfpWU+zpCQwZNd/V50fbGDjyAiUmTWSKXFXwBLzr6AqLF76nQi97r4BL05re6pg07RgKFt2rUJQGPBp7Kwt3u1q0D2oo5XZJCqAbWjmI5KXWv723BXnaLNawDAkWKxLTGMD+jUoIjwstKIrQGIc7i4zQe43h5w5IuYkw6m9FCi3iPMdOBjYhaW8748meVEFkK/xSfkqAfC1bRygRQ9C5JfqVdvprNiHThkHCpZmBCA== MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 8e0c9435-2722-44a8-edea-08d4235cd082 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BY2PR0301MB0744; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 3:9RJlylIvZhHca5w3tW6M2DNjoXupXS7HqgKRYOfGCtfkDZSXz1CtG+hfWf6sNlCP+NaQswUMBzVTVDWESfHTWqe/uR0nxzntnN9s+TFvC+zD5ioxem11qOxBXk1t+ZG8tanPx1wzLDniPaOtxWoGBApRydFDBxq4pLputjXwkM0IEB5QBBG4Uo2itQ6duQBl0t6I7sBplCtZRFNwiQkBMIhpN2SzUMf0pVGOj0KfFAe/+OMF9wT5YCAO0JJ0Uy1Ab3+LJ4S+hWLUDV1Da4NXbnI3jab/FeKJ+sdXCLlkgQ7tgj9765/3AbAvvVov96Y9KTlAndNIQirtCekt5QnK+OQG1pS01TM5xTRYMiBjiGBsTHz5VRnx4baSjdoiHaBR X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 25:OOxAJymYoUg6KoXdTDeKia3WYRUvxvW9muQ7HHT9zyylfc2vzi4xToP8u275m7L6u/wiMHkT6rgrK87KLrAn0R+S5Qa1HgBjgSel5t8Kxgbu00cjDic961L8U012ko/POtpOZO0WasIhALHMkuBcRUErGCd4fiQah+Bt5xgxA3S4zO2yvKZk77P6N0hz6qaWpTpdBD/kDMYis5Ynoty+hNh0RiIReLoIBqGqw1xeMgNKJz5sdrx6lzTZGrcRFK9wXScFoEiFiZA7yaaUadvIfVyUfEsUul/w/ewTb9qMAsN2z0or5BfW2Hz+OkUAGVtmmaNAZE721dXYzsx7ooHRt9USPlwnEt6PsA+EqLe/PWWRsN+R63MBLkjZAoBHxyWg3uFAWBwcPTP0tXWCzCkkYLKOQ3Qbx9qVRgQWVAJfHWFmKhZuEWUN46LnbZadZwMRkKgCBAyT97ELAoHvb0q/6YQ2bOjuA4uJ1roJP1nChxVFbGlW2kH/tQ8bSbY6tSF5ko4BxgH1+8xsW03Xq33mH9ZBqin1dkfEAnKrhHYbDEEtPjZsxGtFa0Y42B+3hiNJyVQYbGzI2uGX6loMxTDxmKsHEw4flQ5k6t9mLvaTcNKDVdkGbVvHOaI9hdcvUFxjo56Ef5CHl4nDqQQrR6tarAoYhf+dEi3QcZZr82ojC0ansK9B85cnplny3RVlbISNi/oNqGwoQ9zC98hWBrG0f4zUycg2wXJb7cLNLh+843wGnxnmamkbqRRF9N3eHd2GpQE1nCeOZl2iAtWROZPmMBcrEMLJ9AYr+wiPQ9INi24= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 31:F3U8OriisDFuRp8Ujy5XFRjiItBCZaBO84NogHPg8Kr/BOLU1SDjbhTV5RWmEZc8AdPJEdtIfXkkMups43DbkHYH9fDwJXICyHYCCwxDefEh2vFKUKwUbKtUmojbOtMlf8/2f1I99Dzd82oLkeKY/hcAghAsFXzroI+o3RGVHrD4Q0vaO4Tog39pcSFJlyAjeSuUMbhET13E2qB59YvGUxlEjSr/ZhO8cbIe7a4ii7aNafvmG9QRDRbJSA1EGVO+tAjQJZZ+2oZ31+JprhU7gVF558N84LSsR/qO0lQD7jk= 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)(13015025)(13023025)(13017025)(13024025)(13018025)(10201501046)(3002001)(6055026)(6096035)(20161123565025)(20161123556025)(20161123563025)(20161123561025)(20161123559025); SRVR:BY2PR0301MB0744; BCL:0; PCL:0; RULEID:(400006); SRVR:BY2PR0301MB0744; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 4:8lnKqNAHGMjHsaYzJUntIrcojuGXWIGEs4zdGNpuwwr4cRIcl7889SMThY9sgGzKhTlwU7LJ1RkufhdlG3JEhCRq3uTyqvN3fW/kx59n8QsDDR00IKnR9oY5iz9YQB+EzFQtsNQPdlTIhwdL7rnbohE3ytBKEfPE7AeZCXdIpeKfItIlZm6YQOXqSwZpwuGbvQhvXOZcb7E5Az9pPelYgPxLn7shPlUXp8qIGFwvv+MVUMX8hBTE5ueOImjjFQn+QVeXmxE6e0S5SQJuucTF4E9jWAm/+6lKy0t1IlH08cEmih+BHPGPnqsdhnOzOEzBJrlXtjh8Oqza0JQ2iLFcuu2Ar9wS39ZrGw40p6+eaQtRLDvHglj6TqERd0JyAP9KqHMNCjIVfdFEcq+jmx9cnhNCJd/zFsOs5rLBPYHTYKfShISBrW9nuAYzuOaECwuPJ/NkC+KZTiMZD9TO7KDsUQYWD8XiPhvzsJyBC8And9gHBaKQDRYJFWjX49QzZk3ZTC5gQK5xiQFgZlwSx4l6obhUVN9xYKSFJD5mPKoL3E13IKAALxJorqYpqHgyVeJlUhtDbjVMF5zVXZle9RtEpfDIYAjilQ/p8nAQBS6Xd4kaZS+depZw85B1+esLkVpjS31BlQn8NTULvrvJ397MILHgaP2Rn/rSKErwxOwLoWOnBYX2pD7R3Dxe6QnC4x+C1opiJ08qow1nIOyKRJvnDy/Jl4a2g1W0X/p794ZJGfbsmeexhm7x48zOxmkNeO0Y X-Forefront-PRVS: 01559F388D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BY2PR0301MB0744; 23:73rUlgroxKhkoePFJ+wbxk/oRohfatffAt+TLMo?= =?us-ascii?Q?bgQ06TJH6d49WIRWlA80C8Td03NV9szHMFywhK6xiM36xFeV+My3SIWbx5fw?= =?us-ascii?Q?YapCwUy1kPdHZV0svH3SlIb97BoOXQpQ37Jhc0jCzvGxEKV0QbHV9TM54yxM?= =?us-ascii?Q?offIIfD0Njxvh5Gl9rC+dnhxRVj4cpdIR8ql1dBK7LW4CIu0sd3FfJoiTLEx?= =?us-ascii?Q?OFngIxFmy4IbhefYeMC+CMMKgJaechhn32VuLOB4OpobHJtlJGKmchTz35qa?= =?us-ascii?Q?VoLoq9om6Mev6aOw0Sl4092DmqGAAzM1Fm7NZGa3p2kUwwnumeo3LGuBMoJP?= =?us-ascii?Q?iFnD8B1x257bPGipzZ9hqdlanioy1HEVT0biDqIaL1FHbG8/MUB5prhNrEEm?= =?us-ascii?Q?ysVnw2AEVuTUneUCMke3Dr8aiBVv/mamX47yDZX7j1tgon9Mr1g5MQLumcuQ?= =?us-ascii?Q?HakvfFRtfgJNQxKWMeMqqgaBz+xmSJitdRJTuDUZn4lGYNJOK3z2ZkwQzSKg?= =?us-ascii?Q?J89pBb+P8+JM+cLVcEie2QedkkX0GXjazUzRhcRQQSAaOnMNM/EhLxRhIO6O?= =?us-ascii?Q?4LB64FmRgS2UTli74tf9UQOEQkncf4EROlGw+T9qgDvUevHlXoG5X8BpFYng?= =?us-ascii?Q?/m2fWT4LBnQ5Yvs/Wdnaj+i4BPISiCGi9B9a31rOnk4nUYuqmvla54Z14wFN?= =?us-ascii?Q?eEgfoc7F6VDR+ed+Mp6jp5oJiZzRecyfYa3MPJ685TRUj1QH8iOWJXbj5LIN?= =?us-ascii?Q?STtPFPQy+h+JxUwq/vCby2odjNPMY0wd4rGmpkqNpeEoiNd9TOhsCg7naYjV?= =?us-ascii?Q?XWst50piD5euCr+YPrekWQjEYxVuWIRh4WaArzfCh+aZwmNBzcrgnT4evey1?= =?us-ascii?Q?jg1mb2uLRLD64Pe0d4eZSvt2m51shdUWzE02C31zBIpL18cHg8Cn/Qfb2N/p?= =?us-ascii?Q?jd7zGhSOeB10yMZvniWAE5NAeSRruv85YsZhjRYNj7EuYVsDN7LbB8JcuvBo?= =?us-ascii?Q?5AoY6LUMeRJIeRxcwAmyKReJv3xavgq/nDfMmf4kgAjjYSgKT6aUbq9g1ZcD?= =?us-ascii?Q?ObpFf0yJmaKu7nE2JeOPLkyaa99BdLMFj9WPplPuJizEKCsGRFa0V18x7m5Y?= =?us-ascii?Q?TgVIDY/lnGV9UAXBpPUM14Clq9oZMtAQGB28LWujh2mTs0z79l+/D4L6WkTp?= =?us-ascii?Q?2UyjGgwNwlBIAxtMlx1Lp31L88R8dNps7FidxwyiS+PRyOmXqX3Blw20vki3?= =?us-ascii?Q?WvcB3q1deFG0vK1obm92jFixttot2EIyLz54+2rlq+F2Auy11AXaj9zy0Z3i?= =?us-ascii?Q?SoFzO8P0yzV2VjthdB+toR2I71HDvp8DRuUmq+CAcSYuB?= X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 6:3Xs7/+1xwkjpAeh4t/vdimCagnzm0uFM4STM+wXBai/AAYrio6h3fDmbr7PZQewi3gD1VfmaU3TO4JenItoursdpNBDYZmCLGveOhkN3Nn6/s4SFNHVtsCcxzEvBmfw/z0WFPAAkSi8Oi7ZVAXJYVMxJeDmec/WtyVcmklowF7ycDnlvKIU7wKW5NZxjvqrKhtcMq5YNIQzrMmfGQoGAeeIXGANBG4zqEpSAerAsR7V0Fm7FeEQwl3ZP20qWf35fz3Fa5zrwzJcnuR7b9n1rlryxvTIpX+u0UihWmwDhUwGZqPDLj9s/ry9CirbuPOq9ejjQ7pqGj4PacjeRsU3lX17u/RovWAC0S3K/6qBtunNtogMqV6qteMC/SKBrfxc+ImQupsSa9Sgn829hrT8GYRTF8z2bO8L+T5tMF9x5OtiPYzZF/Xtvj5NPNzkq7TpZ; 5:8PBFagmpaaODvi/QuAyH4QIXq0DFO9fFxNpJLfdMLRB+Nva/0hrydOE1QwQbo2WoGz7IIlILCo/vXYfDhmQAzBibzIdbHweFTCg1/oguOUR1VIRZXNf9dAO5GSTxNjKmd46R0texMMvSQ0fuQQAJi1em7lvwXuqhg+l4pBYZFg8jXuL7py/yV3LNmrT3KDxO; 24:ueNOl8NrXtb73/7Pz+eFc4Oml1P4fNBgQw2Mv7AApPOaW01YY3kxcbjfGdcDQD/zUwEFWxWV8K3LZL0A1xUL3FYeq7jpWOtm4IKr6ZKJI+I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB0744; 7:U4IuY3ErLv+iWSetEeBJqbfZfOhQLLAwN7b/NDkQmg04qKQBYQUmULdoIGSVTWQUGm560jxfEBzpU/V+jdmw8zKhk5+vwUbsA6rNLHNllAfaBpEUGgYPvhSFE4qLSCPmi5WsDVOEPBBtXZsmnFAO+TT5sSEOINuKnVVMF33ECoXqLSdlGYprZvNmArpXtS2r9R1O6c1oCB6k+wm1P86lau+CiA+BZoKm5XPtPZ8IQw3qJw1/faOQfkb3J6lPgxCpK8vVyV1SECKN2P4YBh7IlcUkscvOa0/hXMbvxKxSKGRRAp0cexgrrBKd1WcIdwF9BiFhzslOqG+mU5EpxzkkJRBAaioHQ1v6TruLAtayfT2XphoU/Zqf/7ZqFqvGVXY5yAiadSZEHqOFpRjIoueFtnUPsq7Fdo7dFMlw0sGnR/pRRHNQjFf/UXm8qUnEpGFZLH8fnCShyF8if7vDX6TymQ== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Dec 2016 13:34:50.6415 (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: BY2PR0301MB0744 Subject: [dpdk-dev] [PATCH v2 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: Tue, 13 Dec 2016 13:34:54 -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