From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 70A09A0588; Thu, 16 Apr 2020 07:39:50 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6E0431DA8A; Thu, 16 Apr 2020 07:39:43 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 927211DA8A for ; Thu, 16 Apr 2020 07:39:41 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 126A01063; Wed, 15 Apr 2020 22:39:41 -0700 (PDT) Received: from net-arm-thunderx2-03.shanghai.arm.com (net-arm-thunderx2-03.shanghai.arm.com [10.169.41.185]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8942B3F6C4; Wed, 15 Apr 2020 22:43:51 -0700 (PDT) From: Joyce Kong To: thomas@monjalon.net, stephen@networkplumber.org, david.marchand@redhat.com, mb@smartsharesystems.com, jerinj@marvell.com, bruce.richardson@intel.com, ravi1.kumar@amd.com, rmody@marvell.com, shshaikh@marvell.com, xuanziyang2@huawei.com, cloud.wangxiaoyun@huawei.com, zhouguoyang@huawei.com, honnappa.nagarahalli@arm.com, gavin.hu@arm.com, phil.yang@arm.com Cc: nd@arm.com, dev@dpdk.org Date: Thu, 16 Apr 2020 13:38:49 +0800 Message-Id: <20200416053853.440-3-joyce.kong@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200416053853.440-1-joyce.kong@arm.com> References: <20200416053853.440-1-joyce.kong@arm.com> In-Reply-To: <1571125801-45773-1-git-send-email-joyce.kong@arm.com> References: <1571125801-45773-1-git-send-email-joyce.kong@arm.com> Subject: [dpdk-dev] [PATCH v8 2/6] test/bitops: add bit operation test case 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add test cases for setting bit, clearing bit, testing and setting bit, testing and clearing bit operation. Signed-off-by: Joyce Kong Reviewed-by: Gavin Hu Reviewed-by: Phil Yang --- MAINTAINERS | 1 + app/test/Makefile | 1 + app/test/autotest_data.py | 6 ++ app/test/meson.build | 2 + app/test/test_bitops.c | 137 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 app/test/test_bitops.c diff --git a/MAINTAINERS b/MAINTAINERS index 1d5fad28b..4b4b80fe6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -244,6 +244,7 @@ F: app/test/test_bitmap.c Bitops M: Joyce Kong F: lib/librte_eal/include/rte_bitops.h +F: app/test/test_bitops.c MCSlock - EXPERIMENTAL M: Phil Yang diff --git a/app/test/Makefile b/app/test/Makefile index 1f080d162..76014764e 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -70,6 +70,7 @@ SRCS-y += test_ticketlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c SRCS-y += test_bitmap.c +SRCS-y += test_bitops.c SRCS-y += test_reciprocal_division.c SRCS-y += test_reciprocal_division_perf.c SRCS-y += test_fbarray.c diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py index 7b1d01389..fc3fcc159 100644 --- a/app/test/autotest_data.py +++ b/app/test/autotest_data.py @@ -404,6 +404,12 @@ "Func": default_autotest, "Report": None, }, + { + "Name": "Bitops test", + "Command": "bitops_test", + "Func": default_autotest, + "Report": None, + }, { "Name": "Hash multiwriter autotest", "Command": "hash_multiwriter_autotest", diff --git a/app/test/meson.build b/app/test/meson.build index 351d29cb6..da3ca523e 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -12,6 +12,7 @@ test_sources = files('commands.c', 'test_alarm.c', 'test_atomic.c', 'test_barrier.c', + 'test_bitops.c', 'test_bpf.c', 'test_byteorder.c', 'test_cmdline.c', @@ -160,6 +161,7 @@ fast_tests = [ ['acl_autotest', true], ['alarm_autotest', false], ['atomic_autotest', false], + ['bitops_autotest', true], ['byteorder_autotest', true], ['cmdline_autotest', true], ['common_autotest', true], diff --git a/app/test/test_bitops.c b/app/test/test_bitops.c new file mode 100644 index 000000000..01245b17c --- /dev/null +++ b/app/test/test_bitops.c @@ -0,0 +1,137 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2019 Arm Limited + */ + +#include +#include +#include "test.h" + +uint32_t val32; +uint64_t val64; + +#define MAX_BITS_32 32 +#define MAX_BITS_64 64 +/* + * Bitops functions + * ================ + * + * - The main test function performs several subtests. + * - Check bit operations on one core. + * - Initialize valXX to specified values, then set each bit of valXX + * to 1 one by one in "test_bitops_set_relaxed". + * + * - Clear each bit of valXX to 0 one by one in "test_bitops_clear_relaxed". + * + * - Function "test_bitops_test_set_clear_relaxed" checks whether each bit + * of valXX can do "test and set" and "test and clear" correctly. + */ + +static int +test_bitops_set_relaxed(void) +{ + unsigned int i; + + for (i = 0; i < MAX_BITS_32; i++) + rte_set_bit32_relaxed(i, &val32); + + for (i = 0; i < MAX_BITS_32; i++) + if (!rte_get_bit32_relaxed(i, &val32)) { + printf("Failed to set bit in relaxed version.\n"); + return TEST_FAILED; + } + + for (i = 0; i < MAX_BITS_64; i++) + rte_set_bit64_relaxed(i, &val64); + + for (i = 0; i < MAX_BITS_64; i++) + if (!rte_get_bit64_relaxed(i, &val64)) { + printf("Failed to set bit in relaxed version.\n"); + return TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_bitops_clear_relaxed(void) +{ + unsigned int i; + + for (i = 0; i < MAX_BITS_32; i++) + rte_clear_bit32_relaxed(i, &val32); + + for (i = 0; i < MAX_BITS_32; i++) + if (rte_get_bit32_relaxed(i, &val32)) { + printf("Failed to clear bit in relaxed version.\n"); + return TEST_FAILED; + } + + for (i = 0; i < MAX_BITS_64; i++) + rte_clear_bit64_relaxed(i, &val64); + + for (i = 0; i < MAX_BITS_64; i++) + if (rte_get_bit64_relaxed(i, &val64)) { + printf("Failed to clear bit in relaxed version.\n"); + return TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_bitops_test_set_clear_relaxed(void) +{ + unsigned int i; + + for (i = 0; i < MAX_BITS_32; i++) + rte_test_and_set_bit32_relaxed(i, &val32); + + for (i = 0; i < MAX_BITS_32; i++) + if (!rte_test_and_clear_bit32_relaxed(i, &val32)) { + printf("Failed to set and test bit in relaxed version.\n"); + return TEST_FAILED; + } + + for (i = 0; i < MAX_BITS_32; i++) + if (rte_get_bit32_relaxed(i, &val32)) { + printf("Failed to test and clear bit in relaxed version.\n"); + return TEST_FAILED; + } + + for (i = 0; i < MAX_BITS_64; i++) + rte_test_and_set_bit64_relaxed(i, &val64); + + for (i = 0; i < MAX_BITS_64; i++) + if (!rte_test_and_clear_bit64_relaxed(i, &val64)) { + printf("Failed to set and test bit in relaxed version.\n"); + return TEST_FAILED; + } + + for (i = 0; i < MAX_BITS_64; i++) + if (rte_get_bit64_relaxed(i, &val64)) { + printf("Failed to test and clear bit in relaxed version.\n"); + return TEST_FAILED; + } + + return TEST_SUCCESS; +} + +static int +test_bitops(void) +{ + val32 = 0; + val64 = 0; + + if (test_bitops_set_relaxed() < 0) + return TEST_FAILED; + + if (test_bitops_clear_relaxed() < 0) + return TEST_FAILED; + + if (test_bitops_test_set_clear_relaxed() < 0) + return TEST_FAILED; + + return TEST_SUCCESS; +} + +REGISTER_TEST_COMMAND(bitops_autotest, test_bitops); -- 2.17.1