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 6AC65A052E; Mon, 9 Mar 2020 10:54:50 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 94AEF1C0C5; Mon, 9 Mar 2020 10:54:43 +0100 (CET) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by dpdk.org (Postfix) with ESMTP id 170E31C0C5 for ; Mon, 9 Mar 2020 10:54:42 +0100 (CET) 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 8F2C3101E; Mon, 9 Mar 2020 02:54: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 E163F3F67D; Mon, 9 Mar 2020 02:54:35 -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, phil.yang@arm.com, gavin.hu@arm.com Cc: nd@arm.com, dev@dpdk.org Date: Mon, 9 Mar 2020 17:54:06 +0800 Message-Id: <20200309095410.28983-3-joyce.kong@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200309095410.28983-1-joyce.kong@arm.com> References: <20200309095410.28983-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 v7 2/6] test/pmdbitops: add PMD 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 of bit operations which used by PMDs. 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_pmd_bitops.c | 137 +++++++++++++++++++++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 app/test/test_pmd_bitops.c diff --git a/MAINTAINERS b/MAINTAINERS index 071daf887..876cb2bfd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -247,6 +247,7 @@ F: app/test/test_bitmap.c PMD Bitops M: Joyce Kong F: lib/librte_eal/common/include/rte_pmd_bitops.h +F: app/test/test_pmd_bitops.c MCSlock - EXPERIMENTAL M: Phil Yang diff --git a/app/test/Makefile b/app/test/Makefile index 1f080d162..3bdcbfdcf 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -78,6 +78,7 @@ SRCS-y += test_rand_perf.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c +SRCS-y += test_pmd_bitops.c SRCS-y += test_pmd_perf.c ifeq ($(CONFIG_RTE_LIBRTE_TABLE),y) diff --git a/app/test/autotest_data.py b/app/test/autotest_data.py index 7b1d01389..143b59097 100644 --- a/app/test/autotest_data.py +++ b/app/test/autotest_data.py @@ -284,6 +284,12 @@ "Func": default_autotest, "Report": None, }, + { + "Name": "PMD bitops autotest", + "Command": "pmd_bitops_autotest", + "Func": default_autotest, + "Report": None, + } { "Name": "PMD ring autotest", "Command": "ring_pmd_autotest", diff --git a/app/test/meson.build b/app/test/meson.build index 0a2ce710f..5567b9d1c 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -84,6 +84,7 @@ test_sources = files('commands.c', 'test_mcslock.c', 'test_mp_secondary.c', 'test_per_lcore.c', + 'test_pmd_bitops.c', 'test_pmd_perf.c', 'test_power.c', 'test_power_cpufreq.c', @@ -198,6 +199,7 @@ fast_test_names = [ 'meter_autotest', 'multiprocess_autotest', 'per_lcore_autotest', + 'pmd_bitops_autotest', 'prefetch_autotest', 'rcu_qsbr_autotest', 'red_autotest', diff --git a/app/test/test_pmd_bitops.c b/app/test/test_pmd_bitops.c new file mode 100644 index 000000000..f84c582be --- /dev/null +++ b/app/test/test_pmd_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. + * - For relaxed version, 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