1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019 Arm Limited
5 #include <rte_launch.h>
6 #include <rte_bitops.h>
12 #define MAX_BITS_32 32
13 #define MAX_BITS_64 64
19 * - The main test function performs several subtests.
20 * - Check bit operations on one core.
21 * - Initialize valXX to specified values, then set each bit of valXX
22 * to 1 one by one in "test_bit_relaxed_set".
24 * - Clear each bit of valXX to 0 one by one in "test_bit_relaxed_clear".
26 * - Function "test_bit_relaxed_test_set_clear" checks whether each bit
27 * of valXX can do "test and set" and "test and clear" correctly.
31 test_bit_relaxed_set(void)
35 for (i = 0; i < MAX_BITS_32; i++)
36 rte_bit_relaxed_set32(i, &val32);
38 for (i = 0; i < MAX_BITS_32; i++)
39 if (!rte_bit_relaxed_get32(i, &val32)) {
40 printf("Failed to set bit in relaxed version.\n");
44 for (i = 0; i < MAX_BITS_64; i++)
45 rte_bit_relaxed_set64(i, &val64);
47 for (i = 0; i < MAX_BITS_64; i++)
48 if (!rte_bit_relaxed_get64(i, &val64)) {
49 printf("Failed to set bit in relaxed version.\n");
57 test_bit_relaxed_clear(void)
61 for (i = 0; i < MAX_BITS_32; i++)
62 rte_bit_relaxed_clear32(i, &val32);
64 for (i = 0; i < MAX_BITS_32; i++)
65 if (rte_bit_relaxed_get32(i, &val32)) {
66 printf("Failed to clear bit in relaxed version.\n");
70 for (i = 0; i < MAX_BITS_64; i++)
71 rte_bit_relaxed_clear64(i, &val64);
73 for (i = 0; i < MAX_BITS_64; i++)
74 if (rte_bit_relaxed_get64(i, &val64)) {
75 printf("Failed to clear bit in relaxed version.\n");
83 test_bit_relaxed_test_set_clear(void)
87 for (i = 0; i < MAX_BITS_32; i++)
88 rte_bit_relaxed_test_and_set32(i, &val32);
90 for (i = 0; i < MAX_BITS_32; i++)
91 if (!rte_bit_relaxed_test_and_clear32(i, &val32)) {
92 printf("Failed to set and test bit in relaxed version.\n");
96 for (i = 0; i < MAX_BITS_32; i++)
97 if (rte_bit_relaxed_get32(i, &val32)) {
98 printf("Failed to test and clear bit in relaxed version.\n");
102 for (i = 0; i < MAX_BITS_64; i++)
103 rte_bit_relaxed_test_and_set64(i, &val64);
105 for (i = 0; i < MAX_BITS_64; i++)
106 if (!rte_bit_relaxed_test_and_clear64(i, &val64)) {
107 printf("Failed to set and test bit in relaxed version.\n");
111 for (i = 0; i < MAX_BITS_64; i++)
112 if (rte_bit_relaxed_get64(i, &val64)) {
113 printf("Failed to test and clear bit in relaxed version.\n");
126 if (test_bit_relaxed_set() < 0)
129 if (test_bit_relaxed_clear() < 0)
132 if (test_bit_relaxed_test_set_clear() < 0)
138 REGISTER_TEST_COMMAND(bitops_autotest, test_bitops);