Add test cases for set bit, clear bit, test and set bit, test and clear bit operations.
Signed-off-by: Joyce Kong <joyce.k...@arm.com> Reviewed-by: Gavin Hu <gavin...@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 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); -- 2.7.4