Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2019 Arm Limited 3 : : */ 4 : : 5 : : #include <rte_launch.h> 6 : : #include <rte_bitops.h> 7 : : #include "test.h" 8 : : 9 : : uint32_t val32; 10 : : uint64_t val64; 11 : : 12 : : #define MAX_BITS_32 32 13 : : #define MAX_BITS_64 64 14 : : 15 : : /* 16 : : * Bitops functions 17 : : * ================ 18 : : * 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". 23 : : * 24 : : * - Clear each bit of valXX to 0 one by one in "test_bit_relaxed_clear". 25 : : * 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. 28 : : */ 29 : : 30 : : static int 31 : 1 : test_bit_relaxed_set(void) 32 : : { 33 : : unsigned int i; 34 : : 35 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 36 : : rte_bit_relaxed_set32(i, &val32); 37 : : 38 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 39 [ - + ]: 32 : if (!rte_bit_relaxed_get32(i, &val32)) { 40 : : printf("Failed to set bit in relaxed version.\n"); 41 : 0 : return TEST_FAILED; 42 : : } 43 : : 44 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 45 : : rte_bit_relaxed_set64(i, &val64); 46 : : 47 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 48 [ - + ]: 64 : if (!rte_bit_relaxed_get64(i, &val64)) { 49 : : printf("Failed to set bit in relaxed version.\n"); 50 : 0 : return TEST_FAILED; 51 : : } 52 : : 53 : : return TEST_SUCCESS; 54 : : } 55 : : 56 : : static int 57 : 1 : test_bit_relaxed_clear(void) 58 : : { 59 : : unsigned int i; 60 : : 61 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 62 : : rte_bit_relaxed_clear32(i, &val32); 63 : : 64 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 65 [ - + ]: 32 : if (rte_bit_relaxed_get32(i, &val32)) { 66 : : printf("Failed to clear bit in relaxed version.\n"); 67 : 0 : return TEST_FAILED; 68 : : } 69 : : 70 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 71 : : rte_bit_relaxed_clear64(i, &val64); 72 : : 73 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 74 [ - + ]: 64 : if (rte_bit_relaxed_get64(i, &val64)) { 75 : : printf("Failed to clear bit in relaxed version.\n"); 76 : 0 : return TEST_FAILED; 77 : : } 78 : : 79 : : return TEST_SUCCESS; 80 : : } 81 : : 82 : : static int 83 : 1 : test_bit_relaxed_test_set_clear(void) 84 : : { 85 : : unsigned int i; 86 : : 87 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 88 : : rte_bit_relaxed_test_and_set32(i, &val32); 89 : : 90 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 91 [ - + ]: 32 : if (!rte_bit_relaxed_test_and_clear32(i, &val32)) { 92 : : printf("Failed to set and test bit in relaxed version.\n"); 93 : 0 : return TEST_FAILED; 94 : : } 95 : : 96 [ + + ]: 33 : for (i = 0; i < MAX_BITS_32; i++) 97 [ - + ]: 32 : if (rte_bit_relaxed_get32(i, &val32)) { 98 : : printf("Failed to test and clear bit in relaxed version.\n"); 99 : 0 : return TEST_FAILED; 100 : : } 101 : : 102 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 103 : : rte_bit_relaxed_test_and_set64(i, &val64); 104 : : 105 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 106 [ - + ]: 64 : if (!rte_bit_relaxed_test_and_clear64(i, &val64)) { 107 : : printf("Failed to set and test bit in relaxed version.\n"); 108 : 0 : return TEST_FAILED; 109 : : } 110 : : 111 [ + + ]: 65 : for (i = 0; i < MAX_BITS_64; i++) 112 [ - + ]: 64 : if (rte_bit_relaxed_get64(i, &val64)) { 113 : : printf("Failed to test and clear bit in relaxed version.\n"); 114 : 0 : return TEST_FAILED; 115 : : } 116 : : 117 : : return TEST_SUCCESS; 118 : : } 119 : : 120 : : static int 121 : 1 : test_bitops(void) 122 : : { 123 : 1 : val32 = 0; 124 : 1 : val64 = 0; 125 : : 126 [ + - ]: 1 : if (test_bit_relaxed_set() < 0) 127 : : return TEST_FAILED; 128 : : 129 [ + - ]: 1 : if (test_bit_relaxed_clear() < 0) 130 : : return TEST_FAILED; 131 : : 132 [ - + ]: 1 : if (test_bit_relaxed_test_set_clear() < 0) 133 : 0 : return TEST_FAILED; 134 : : 135 : : return TEST_SUCCESS; 136 : : } 137 : : 138 : 235 : REGISTER_FAST_TEST(bitops_autotest, true, true, test_bitops);