Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2021 Cisco Systems, Inc. |
| 3 | */ |
| 4 | |
| 5 | #include <vppinfra/format.h> |
Damjan Marion | c3542e1 | 2023-03-15 11:42:06 +0000 | [diff] [blame] | 6 | #include <vppinfra/test/test.h> |
Damjan Marion | d154a17 | 2021-07-13 21:12:41 +0200 | [diff] [blame] | 7 | #include <vppinfra/vector/mask_compare.h> |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 8 | |
Damjan Marion | 3323e20 | 2021-12-02 11:28:57 +0100 | [diff] [blame] | 9 | __test_funct_fn void |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 10 | clib_mask_compare_u16_wrapper (u16 v, u16 *a, u64 *mask, u32 n_elts) |
| 11 | { |
| 12 | clib_mask_compare_u16 (v, a, mask, n_elts); |
| 13 | } |
| 14 | |
Damjan Marion | 3323e20 | 2021-12-02 11:28:57 +0100 | [diff] [blame] | 15 | __test_funct_fn void |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 16 | clib_mask_compare_u32_wrapper (u32 v, u32 *a, u64 *mask, u32 n_elts) |
| 17 | { |
| 18 | clib_mask_compare_u32 (v, a, mask, n_elts); |
| 19 | } |
| 20 | |
Mohsin Kazmi | 556b5a3 | 2022-01-24 23:19:29 +0000 | [diff] [blame] | 21 | __test_funct_fn void |
| 22 | clib_mask_compare_u64_wrapper (u64 v, u64 *a, u64 *mask, u64 n_elts) |
| 23 | { |
| 24 | clib_mask_compare_u64 (v, a, mask, n_elts); |
| 25 | } |
| 26 | |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 27 | static clib_error_t * |
| 28 | test_clib_mask_compare_u16 (clib_error_t *err) |
| 29 | { |
| 30 | u16 array[513]; |
| 31 | u64 mask[10]; |
| 32 | u32 i, j; |
| 33 | |
| 34 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 35 | array[i] = i; |
| 36 | |
| 37 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 38 | { |
| 39 | for (j = 0; j < ARRAY_LEN (mask); j++) |
| 40 | mask[j] = 0xa5a5a5a5a5a5a5a5; |
| 41 | |
| 42 | clib_mask_compare_u16_wrapper (i, array, mask, i + 1); |
| 43 | |
| 44 | for (j = 0; j < (i >> 6); j++) |
| 45 | { |
| 46 | if (mask[j]) |
| 47 | return clib_error_return (err, "mask at position %u not zero", j); |
| 48 | } |
| 49 | if (mask[j] != 1ULL << (i & 0x3f)) |
| 50 | return clib_error_return (err, |
| 51 | "mask at position %u is %lx, expected %lx", |
| 52 | j, mask[j], 1ULL << (i % 64)); |
| 53 | |
| 54 | if (mask[j + 1] != 0xa5a5a5a5a5a5a5a5) |
| 55 | return clib_error_return (err, "mask overrun at position %u", j + 1); |
| 56 | } |
| 57 | return err; |
| 58 | } |
| 59 | |
| 60 | REGISTER_TEST (clib_mask_compare_u16) = { |
| 61 | .name = "clib_mask_compare_u16", |
| 62 | .fn = test_clib_mask_compare_u16, |
| 63 | }; |
| 64 | |
| 65 | static clib_error_t * |
| 66 | test_clib_mask_compare_u32 (clib_error_t *err) |
| 67 | { |
| 68 | u32 array[513]; |
| 69 | u64 mask[10]; |
| 70 | u32 i, j; |
| 71 | |
| 72 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 73 | array[i] = i; |
| 74 | |
| 75 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 76 | { |
| 77 | for (j = 0; j < ARRAY_LEN (mask); j++) |
| 78 | mask[j] = 0xa5a5a5a5a5a5a5a5; |
| 79 | |
| 80 | clib_mask_compare_u32_wrapper (i, array, mask, i + 1); |
| 81 | |
| 82 | for (j = 0; j < (i >> 6); j++) |
| 83 | { |
| 84 | if (mask[j]) |
| 85 | return clib_error_return (err, "mask at position %u not zero", j); |
| 86 | } |
| 87 | if (mask[j] != 1ULL << (i & 0x3f)) |
| 88 | return clib_error_return (err, |
| 89 | "mask at position %u is %lx, expected %lx", |
| 90 | j, mask[j], 1ULL << (i % 64)); |
| 91 | |
| 92 | if (mask[j + 1] != 0xa5a5a5a5a5a5a5a5) |
| 93 | return clib_error_return (err, "mask overrun at position %u", j + 1); |
| 94 | } |
| 95 | return err; |
| 96 | } |
| 97 | |
| 98 | REGISTER_TEST (clib_mask_compare_u32) = { |
| 99 | .name = "clib_mask_compare_u32", |
| 100 | .fn = test_clib_mask_compare_u32, |
| 101 | }; |
Mohsin Kazmi | 556b5a3 | 2022-01-24 23:19:29 +0000 | [diff] [blame] | 102 | |
| 103 | static clib_error_t * |
| 104 | test_clib_mask_compare_u64 (clib_error_t *err) |
| 105 | { |
| 106 | u64 array[513]; |
| 107 | u64 mask[10]; |
| 108 | u32 i, j; |
| 109 | |
| 110 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 111 | array[i] = i; |
| 112 | |
| 113 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 114 | { |
| 115 | for (j = 0; j < ARRAY_LEN (mask); j++) |
| 116 | mask[j] = 0xa5a5a5a5a5a5a5a5; |
| 117 | |
| 118 | clib_mask_compare_u64_wrapper (i, array, mask, i + 1); |
| 119 | |
| 120 | for (j = 0; j < (i >> 6); j++) |
| 121 | { |
| 122 | if (mask[j]) |
| 123 | return clib_error_return (err, "mask at position %u not zero", j); |
| 124 | } |
| 125 | if (mask[j] != 1ULL << (i & 0x3f)) |
| 126 | return clib_error_return (err, |
| 127 | "mask at position %u is %lx, expected %lx", |
| 128 | j, mask[j], 1ULL << (i % 64)); |
| 129 | |
| 130 | if (mask[j + 1] != 0xa5a5a5a5a5a5a5a5) |
| 131 | return clib_error_return (err, "mask overrun at position %u", j + 1); |
| 132 | } |
| 133 | return err; |
| 134 | } |
| 135 | |
| 136 | REGISTER_TEST (clib_mask_compare_u64) = { |
| 137 | .name = "clib_mask_compare_u64", |
| 138 | .fn = test_clib_mask_compare_u64, |
| 139 | }; |