From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0076.outbound.protection.outlook.com [104.47.38.76]) by dpdk.org (Postfix) with ESMTP id 79EE5199A9 for ; Thu, 7 Sep 2017 16:40:24 +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=99loh1iexunJ0NWNF78J4/4yFbkRgXghHxz6ZPUFio8=; b=Mbm+KkxgtEjQ+G1IUTW/hXbzCIpneqcywqitGqptUBW5nG2EtUMXqoTtuwB6YA1NYAqgTiFTjq3Y8ArjKMnY0eYSVqNuSsAjZJJj/6HPka7JbO3A6JJ00tyhXkxgYoXH4PKeBKsdoFewek5W9yPaMq0SLxXAhHj7JnCxMwwcH7A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from PBHAGAVATULA-LT.caveonetworks.com (111.93.218.67) by CY4PR07MB3461.namprd07.prod.outlook.com (10.171.252.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.35.12; Thu, 7 Sep 2017 14:40:22 +0000 From: Pavan Nikhilesh To: cristian.dumitrescu@intel.com, stephen@networkplumber.org Cc: dev@dpdk.org, Pavan Nikhilesh Date: Thu, 7 Sep 2017 20:09:47 +0530 Message-Id: <1504795187-11087-2-git-send-email-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504795187-11087-1-git-send-email-pbhagavatula@caviumnetworks.com> References: <1504795187-11087-1-git-send-email-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: PN1PR01CA0105.INDPRD01.PROD.OUTLOOK.COM (10.174.144.21) To CY4PR07MB3461.namprd07.prod.outlook.com (10.171.252.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c0dc45c9-b422-4128-c02e-08d4f5fe5f82 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:CY4PR07MB3461; X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3461; 3:4v6TKAzt5MXIeofyUVdfNZ6zvqRXKOSgxN1kNvEBbx+6P4Gz5nqeNs0lTFaPhHSOPA6J+6NfcqTAsRsmadXxeE/Bu+yX213Q2dYzSEZcjFwC72Nw5+5CLtIsu+ZrpfnmyopcY5VnJ8CQJOaraaM5sGtbckwoG6DAKpGXnE/8bQB4V8dpzwqyi64ZnlVVUgkVo6JpBIvgmpOsCp6tTh8RfwSu08YHvmM+Ldw2lT03TPHO0YG7pAYOELuOY9Iimho3; 25:mmJ8re//yZyaaY1GMEGasmYAiWv/Z1iBOJ+ITuxdQRP7zUlSH2HiaM5XLxl22WZInq1NL0F2g7k+ejp+WFlnx57lholm0WsvQNCwg6C6f/NE8R8D5SEIHi1G/TWW4sNP7YXNGXjdOcT9ZFPVEr0VTMyGx4fLA/uXRL5hgu4Z1o1Vg04NL85VLfwLltWvSEGgYOjuTWOE/ncmqWbNYKumaSwLSz+ACmaZuUAYAsxcsfGooFlDe83OUnWL0c2oV2uWXfDHUbtCJPpipBi/v5u4DphvsXH3nkIlM/ZxGJmlSovSTi7LIsXJLYDQ7ag7wRCQV33dKXxf8Xb0jJY96IFAPA==; 31:kKYF0KVSkBvS5gr4U1N/Athgl23/uj7AJhHqoqwChE4Z3NuTIe1soLTqhIFCYEscpincUeoAaLtMmaz2lsybyMamewm/dr/Ii47pscsknNIXPRQvXtYyttGeLQvArjyaK5zTfECHKoYL7ePCtapjyUUrrwJ6xlfNKP1JJs81NJqsBZSWZy6+TxHhHypkdzor0mvImqzeJSVnKEkuBhiicnB1Jms1He1WlNOb9lthcDE= X-MS-TrafficTypeDiagnostic: CY4PR07MB3461: X-Microsoft-Exchange-Diagnostics: 1; CY4PR07MB3461; 20:NYksb4SdLthb+urLREWl5NhoWy4Vvm0WEJgP5dq5SCnRZUuc3rSRlpMchfQBMxAmwaM60mWq7ARvoSaxsAZBfmbeEOZrljVe7BgwRN5WNrSn1leMafev+lHJvJIAmDgNehhdE43xCzT20F0qJzBEBHq0mpqO681jWnbiHbQqQqi+McOOskj8Yv2hlO1MI72IayCAM45HqKlfu8xlfeuQ76VYyNoOP5wWfiTRt4CUJIgodk4eUqZ8/qrquAGHPqGztPTFZ4lterQsWSdFOBnVvmz6+GPoJzgg7P1JHio0r5gQnw+YpUuSeziJDV7F5Vrw+MIGBCvjRIeqd7RWM0j/YN4aAkj27jZ4yYRsYnzS2lP+qHPT20Me/UAssWPim/Y6BytUqapgJZfPcMMZkoMYb41IYxTv/JUtxNLkgOIhqLjEPtmI7ZypuF0/JFhEqXPewvcmv0iDzAGZ3b3+joyhrGDlbxkvSb/ak3UPrvf3PhG7KWsFqssmRyAYX//vXuxAiLNAdSMDaoXBWpv6QYg2rzmhPL0YiW7i2+syatRDGs5/eRQFQOU+JCqHj2eYkbxwzMvvYl19FwplZt6nztG2RQhoCaIsSBGobCyEtLXlPko=; 4:0oO6D4arj1A/9tG4FlE/OmobmGKdQdNW9lALfD+JYullzDP5w9SWN7xfYa6k8ZANMulh1zmMMBj7LyA4Qa5TZESQNdV83GLtoDRY6jLi7XsdYAHt6o0KUL1aX+q76mxHNwHFr1gDOFQK5DjcKZi0TPpXg6l9GE7fhVoJNovg+2IMCpoPH8Ei0dOeZZAeKAqord4me9DZ9PqYs708ebF3xQuJAar2LCSCXueltT5GaMycseoOUuZx3yY9z6jU+hWS 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)(8121501046)(5005006)(3002001)(10201501046)(93006095)(100000703101)(100105400095)(6041248)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123562025)(20161123564025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:CY4PR07MB3461; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:CY4PR07MB3461; X-Forefront-PRVS: 04238CD941 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(189002)(199003)(72206003)(97736004)(25786009)(6512007)(478600001)(107886003)(110136004)(5009440100003)(6506006)(50466002)(4326008)(69596002)(48376002)(3846002)(2906002)(6116002)(50226002)(8676002)(81156014)(81166006)(42186005)(53416004)(50986999)(6666003)(76176999)(5003940100001)(36756003)(6486002)(105586002)(33646002)(5660300001)(305945005)(106356001)(189998001)(66066001)(42882006)(68736007)(47776003)(101416001)(7736002)(53936002)(575784001)(8936002)(2950100002)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:CY4PR07MB3461; 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; CY4PR07MB3461; 23:wy+CK7FPs3FmZYNzEEi1k030lkdEXPikmTpKYvVUU?= =?us-ascii?Q?5Tgq6nK3k56U+cE99zUnFdIbdD2olbdx9fQTt9lxrV44PzU8O6lqfMQPkMr2?= =?us-ascii?Q?nC5O4fZh7HnsWSJLjU+h0uZOJLCyYvFqwwR28dtJwEbAvZRsiIMBqzkx09iF?= =?us-ascii?Q?fpwQS0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8w= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2017 14:40:22.2266 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR07MB3461 Subject: [dpdk-dev] [PATCH 2/2] 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, 07 Sep 2017 14:40:26 -0000 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