[dpdk-dev] [PATCH v7 2/6] test/pmdbitops: add PMD bit operation test case
Joyce Kong
joyce.kong at arm.com
Mon Mar 9 10:54:06 CET 2020
Add test cases of bit operations which used by PMDs.
Signed-off-by: Joyce Kong <joyce.kong at arm.com>
Reviewed-by: Gavin Hu <gavin.hu at arm.com>
Reviewed-by: Phil Yang <phil.yang at arm.com>
---
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 <joyce.kong at arm.com>
F: lib/librte_eal/common/include/rte_pmd_bitops.h
+F: app/test/test_pmd_bitops.c
MCSlock - EXPERIMENTAL
M: Phil Yang <phil.yang at arm.com>
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 <rte_launch.h>
+#include <rte_pmd_bitops.h>
+#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
More information about the dev
mailing list