@@ -247,6 +247,7 @@ F: app/test/test_bitmap.c
PMD Bitops
M: Joyce Kong <joyce.kong@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@arm.com>
@@ -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)
@@ -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",
@@ -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',
new file mode 100644
@@ -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);