[v2,2/6] test/iobitops: add io bit operation test case

Message ID 1571799298-18873-3-git-send-email-joyce.kong@arm.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series implement common rte bit operation APIs in PMDs |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Joyce Kong Oct. 23, 2019, 2:54 a.m. UTC
  Add test cases for set bit, clear bit, test and set bit,
test and clear bit operations.

Signed-off-by: Joyce Kong <joyce.kong@arm.com>
Reviewed-by: Gavin Hu <gavin.hu@arm.com>
---
 app/test/Makefile         |  1 +
 app/test/test_io_bitops.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 app/test/test_io_bitops.c
  

Patch

diff --git a/app/test/Makefile b/app/test/Makefile
index df7f77f..3e47c94 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_io_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/test_io_bitops.c b/app/test/test_io_bitops.c
new file mode 100644
index 0000000..c61bec7
--- /dev/null
+++ b/app/test/test_io_bitops.c
@@ -0,0 +1,86 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2019 Arm Limited
+ */
+
+#include <rte_io_bitops.h>
+#include <rte_malloc.h>
+
+#include "test.h"
+
+#define MAX_BITS 32
+
+static int
+test_io_bitops_set(unsigned long *addr)
+{
+	unsigned int i;
+
+	for (i = 0; i < MAX_BITS; i++)
+		rte_io_set_bit(i, addr);
+
+	for (i = 0; i < MAX_BITS; i++)
+		if (!rte_io_get_bit(i, addr)) {
+			printf("Failed to set bit.\n");
+			return TEST_FAILED;
+		}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_io_bitops_clear(unsigned long *addr)
+{
+	unsigned int i;
+
+	for (i = 0; i < MAX_BITS; i++)
+		rte_io_clear_bit(i, addr);
+
+	for (i = 0; i < MAX_BITS; i++)
+		if (rte_io_get_bit(i, addr)) {
+			printf("Failed to clear bit.\n");
+			return TEST_FAILED;
+	}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_io_bitops_test_set_clear(unsigned long *addr)
+{
+	unsigned int i;
+
+	for (i = 0; i < MAX_BITS; i++)
+		rte_io_test_and_set_bit(i, addr);
+
+	for (i = 0; i < MAX_BITS; i++)
+		if (!rte_io_test_and_clear_bit(i, addr)) {
+			printf("Failed to set and test bit.\n");
+			return TEST_FAILED;
+	}
+
+	for (i = 0; i < MAX_BITS; i++)
+		if (rte_io_get_bit(i, addr)) {
+			printf("Failed to test and clear bit.\n");
+			return TEST_FAILED;
+		}
+
+	return TEST_SUCCESS;
+}
+
+static int
+test_io_bitops(void)
+{
+	unsigned long *addr = rte_zmalloc(NULL, MAX_BITS, RTE_CACHE_LINE_SIZE);
+
+	if (test_io_bitops_set(addr) < 0)
+		return TEST_FAILED;
+
+	if (test_io_bitops_clear(addr) < 0)
+		return TEST_FAILED;
+
+	if (test_io_bitops_test_set_clear(addr) < 0)
+		return TEST_FAILED;
+
+	return TEST_SUCCESS;
+}
+
+REGISTER_TEST_COMMAND(io_bitops_autotest, test_io_bitops);