From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0085.outbound.protection.outlook.com [104.47.37.85]) by dpdk.org (Postfix) with ESMTP id D642D1B19C for ; Thu, 21 Sep 2017 13:50:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=LbcCSeWx3UmlW4Vs+IhAsYB1BBwXcEtqBr+8pEbPZY0=; b=XxlKyRU0cOJ68zbFVRVJ6Nab6ALvSFSAdt4asnKXTAHTyEcN4Ud4anma2/9as82ps12s/FpoCGhnFnaels8372Zle8V9kBXeFRiGotIvs711FZnBht+nAyA8/h5SEaWx7VZ2Xwv17j1YeYgobXw6+vGyrM7z3EOLclV6H38eQJo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from PBHAGAVATULA-LT.caveonetworks.com (111.93.218.67) by MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Thu, 21 Sep 2017 11:50:45 +0000 From: Pavan Nikhilesh To: cristian.dumitrescu@intel.com, stephen@networkplumber.org Cc: dev@dpdk.org, Pavan Bhagavatula Date: Thu, 21 Sep 2017 17:20:21 +0530 Message-Id: <1505994622-902-2-git-send-email-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505994622-902-1-git-send-email-pbhagavatula@caviumnetworks.com> References: <1505921833-2286-1-git-send-email-pbhagavatula@caviumnetworks.com> <1505994622-902-1-git-send-email-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0085.INDPRD01.PROD.OUTLOOK.COM (10.174.208.153) To MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) X-MS-Office365-Filtering-Correlation-Id: 3086f1f4-5a5d-4237-03a1-08d500e6ff31 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:MWHPR07MB3471; X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 3:7XCRDLufyWvBfA/mY9bSxFld8uHmVO5u3hj3WMldWnoZkfiYC1Pd7WP1M8mZpQKM1yNX544gxvBy+hgRdg49kqYrBa/6w71y+osGMnOGj9xMVu4aw3rYj89MmyCgSUtu/s0hHLUVrz+sJQHK/ujqzyZlCdTx2QEpSfob6abiiCzcBg+LGiEY3w5wNVYiiguNii6RfEVgIRyyFUwsFfy9OMivln0Z226rInCD+c78grh/NiVCSujMbizhtvbUO6an; 25:ojncY5E9uKdTFlQYoLfStbfQ3jSV1SzBC04MKXn+1LzmDroImTXE3+x8RhzF8nQcrNL4fRfdLyJhHgjewDwP5wB7foLGVJQoN7wbqM7bbASLmTFVzL8pvGPInN9bu9O0+wzf69uTSeczR6ZNKSNfyXdD78e1WwwiCNhG+7jMB4M587MJibFG37dmOqVB23tmH7JtbIFYwlYTdljQoKrcIWkvoJLoIZF0L+VjywHEo+dOVBF1/pooiYi5M2J9L7E8qmnr5z6iYCdK5LSSytHyt1ol25BH4rPveANfvcP6Wpa+Cg8CfhAnOLiIUec9lLn5uemzQ/IiR7tbEQWOUuAEgg==; 31:l2PHCEesIZjHLcRLoZb4J9CX2vzOVVnolVwpprS7pQVuM8ZUPmr/hLePHdSgMxOiMV+7cTsGJpozkJFXfO2XvUvKv/592J8R3ATSKzVJnjyrFZde8SjWL0JuIPoUcSyqYW0DsskVApvpUh5iDENY7YB3T5E0Uw/haCtm5erI2onB3C2+Bo0XsCK+2UJGbjfdV5oRWAopGERFYIvxOfETn/Ji6WSieWBAk7js/jwk9bE= X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR07MB3471: X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 20:PjqVQuE4LEV2bwPcCA+abPZq/1NvEPFaJvhqKruoo04MHwrMNOHeslJbPiaQquKWpQd2fpIwr8bl3Go6wGvUUNbM9RDb446Fkf59N/tvdOgsHIVB0oSutRSggiMCaopL4aCQ0hR5lABZ+FEoXWe2/i0ctKG/lWaPFKCEbSeMFmDu2I5kcjs0tj7gAOXR2YtYX9Kb1MTiNibMlfHhipt2d/x5HYlD47UTE5dy4eo10J0mbtpS5OlEaeebJ1rLeGlh5t6ysZVpu6La7xDK/+phjxrJsBW/inHFTPrsLtiveoZxJlSonuu3GQ0HLjEAvcAC9ODk/eIEGUbeYRlIfgIecom7FuAL+LIRV3DhLB13i16djf9h2E7IShSJc3ObQEpplg9rjtJ/EMGab3duaTM/g8JYflj1nzPA6yfBG7NKQ7QCjf3pq46H+TlBTShaEvZh3tUz/LgfifbqD4fPSprnFcOXHmueS7J2SMlOlA2lw+q6IPW0si16Ps+DAw4+wSlVcU2BuLGgUsVPdCqcnbKEwS8E5OQuiMZM6f8uDqs29RffC304T5je4m+RPd7EEFzgrqMMNeQsE8F2cvKL3kFv1MrrmDa/GAu5eRfGdB/JE7U=; 4:yRq8MJI61kxSn5MWd00Hnkfrncoz23Sdd1l55FoSvuT9S0674W6lplX0UreOcGmz3CYLaQfPfUMBeLmSRixiuEOcZAn5edtYy2BYA774vkW8VZg43GWJ+l0ho9Z4r+uf2eyvMMisQ6tI2baLXGb1Mkrx2FAZAcRxHyVMDQyOGJeMZaoyRWprtUQvr7jGD4RZPfxbBe4sM9/FBeqH9gTxTuK9uNzzRXSmq+Fkp/Q9+s+9/Bj3RXq8eUHdFL0ZUDSf X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(6041248)(20161123555025)(20161123558100)(20161123560025)(20161123564025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR07MB3471; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR07MB3471; X-Forefront-PRVS: 04371797A5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(189002)(199003)(5003940100001)(50986999)(68736007)(6116002)(3846002)(101416001)(42882006)(106356001)(48376002)(50466002)(7736002)(105586002)(53936002)(2950100002)(5660300001)(16586007)(16526017)(316002)(76176999)(66066001)(47776003)(4326008)(69596002)(8936002)(81166006)(81156014)(107886003)(72206003)(8676002)(53416004)(2906002)(6512007)(97736004)(33646002)(575784001)(189998001)(25786009)(478600001)(305945005)(36756003)(50226002)(6486002)(6666003)(6506006)(5009440100003)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR07MB3471; H:PBHAGAVATULA-LT.caveonetworks.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR07MB3471; 23:/U5KFQcewjzcb0ekefAk6/oksaCJ4e1zHK9Y86qFn?= =?us-ascii?Q?KaOs8HTHU7f/ySRcogPhjEb7sRaMQN/iwKCaO2fQ5KYdJloDuEN5UnY9ZMOY?= =?us-ascii?Q?wol8n8ykFBYgsl9mgNgPhytP2RQccvgbaCXxRjTqw1+1p1iFW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y/XkUDFe62t669fwtMYMWokwL5OlS4jjbQA2qFj2M= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2017 11:50:45.0581 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3471 Subject: [dpdk-dev] [PATCH v3 2/3] test: add test for bitmap operations 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: Thu, 21 Sep 2017 11:50:48 -0000 From: Pavan Bhagavatula This patch adds a test for verifying the bitmap operations. Signed-off-by: Pavan Nikhilesh --- test/test/Makefile | 1 + test/test/test_bitmap.c | 192 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 193 insertions(+) create mode 100644 test/test/test_bitmap.c diff --git a/test/test/Makefile b/test/test/Makefile index 42d9a49..2fda8d9 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -94,6 +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_bitmap.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c diff --git a/test/test/test_bitmap.c b/test/test/test_bitmap.c new file mode 100644 index 0000000..5c9eee9 --- /dev/null +++ b/test/test/test_bitmap.c @@ -0,0 +1,192 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium, Inc. 2017. + * + * 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 Cavium, Inc 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 "test.h" + +#define MAX_BITS 1000 + +static int +test_bitmap_scan_operations(struct rte_bitmap *bmp) +{ + uint32_t pos = 0; + uint64_t slab1_magic = 0xBADC0FFEEBADF00D; + uint64_t slab2_magic = 0xFEEDDEADDEADF00D; + uint64_t out_slab = 0; + + rte_bitmap_reset(bmp); + + rte_bitmap_set_slab(bmp, pos, slab1_magic); + rte_bitmap_set_slab(bmp, pos + RTE_BITMAP_SLAB_BIT_SIZE, slab2_magic); + + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab1_magic != out_slab) { + printf("Scan operation sanity failed.\n"); + return TEST_FAILED; + } + + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab2_magic != out_slab) { + printf("Scan operation sanity failed.\n"); + return TEST_FAILED; + } + + /* Wrap around */ + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab1_magic != out_slab) { + printf("Scan operation wrap around failed.\n"); + return TEST_FAILED; + } + + /* Scan reset check. */ + __rte_bitmap_scan_init(bmp); + + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + if (slab1_magic != out_slab) { + printf("Scan reset operation failed.\n"); + return TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_bitmap_slab_set_get(struct rte_bitmap *bmp) +{ + uint32_t pos = 0; + uint64_t slab_magic = 0xBADC0FFEEBADF00D; + uint64_t out_slab = 0; + + rte_bitmap_reset(bmp); + rte_bitmap_set_slab(bmp, pos, slab_magic); + + if (!rte_bitmap_scan(bmp, &pos, &out_slab)) { + printf("Failed to get slab from bitmap.\n"); + return TEST_FAILED; + } + + + if (slab_magic != out_slab) { + printf("Invalid slab in bitmap.\n"); + return TEST_FAILED; + } + + + return TEST_SUCCESS; +} + +static int +test_bitmap_set_get_clear(struct rte_bitmap *bmp) +{ + int i; + + rte_bitmap_reset(bmp); + for (i = 0; i < MAX_BITS; i++) + rte_bitmap_set(bmp, i); + + for (i = 0; i < MAX_BITS; i++) { + if (!rte_bitmap_get(bmp, i)) { + printf("Failed to get set bit.\n"); + return TEST_FAILED; + } + } + + for (i = 0; i < MAX_BITS; i++) + rte_bitmap_clear(bmp, i); + + for (i = 0; i < MAX_BITS; i++) { + if (rte_bitmap_get(bmp, i)) { + printf("Failed to clear set bit.\n"); + return TEST_FAILED; + } + } + + return TEST_SUCCESS; +} + +static int +test_bitmap(void) +{ + void *mem; + uint32_t bmp_size; + struct rte_bitmap *bmp; + + bmp_size = + rte_bitmap_get_memory_footprint(MAX_BITS); + + mem = rte_zmalloc("test_bmap", bmp_size, RTE_CACHE_LINE_SIZE); + if (mem == NULL) { + printf("Failed to allocate memory for bitmap\n"); + return TEST_FAILED; + } + + bmp = rte_bitmap_init(MAX_BITS, mem, bmp_size); + if (bmp == NULL) { + printf("Failed to init bitmap\n"); + return TEST_FAILED; + } + + if (test_bitmap_set_get_clear(bmp) < 0) + return TEST_FAILED; + + if (test_bitmap_slab_set_get(bmp) < 0) + return TEST_FAILED; + + if (test_bitmap_scan_operations(bmp) < 0) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(bitmap_test, test_bitmap); -- 2.7.4