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 | d154a17 | 2021-07-13 21:12:41 +0200 | [diff] [blame] | 6 | #include <vppinfra/vector/test/test.h> |
| 7 | #include <vppinfra/vector/mask_compare.h> |
Damjan Marion | e3e3555 | 2021-05-06 17:34:49 +0200 | [diff] [blame] | 8 | |
| 9 | __clib_test_fn void |
| 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 | |
| 15 | __clib_test_fn void |
| 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 | |
| 21 | static clib_error_t * |
| 22 | test_clib_mask_compare_u16 (clib_error_t *err) |
| 23 | { |
| 24 | u16 array[513]; |
| 25 | u64 mask[10]; |
| 26 | u32 i, j; |
| 27 | |
| 28 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 29 | array[i] = i; |
| 30 | |
| 31 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 32 | { |
| 33 | for (j = 0; j < ARRAY_LEN (mask); j++) |
| 34 | mask[j] = 0xa5a5a5a5a5a5a5a5; |
| 35 | |
| 36 | clib_mask_compare_u16_wrapper (i, array, mask, i + 1); |
| 37 | |
| 38 | for (j = 0; j < (i >> 6); j++) |
| 39 | { |
| 40 | if (mask[j]) |
| 41 | return clib_error_return (err, "mask at position %u not zero", j); |
| 42 | } |
| 43 | if (mask[j] != 1ULL << (i & 0x3f)) |
| 44 | return clib_error_return (err, |
| 45 | "mask at position %u is %lx, expected %lx", |
| 46 | j, mask[j], 1ULL << (i % 64)); |
| 47 | |
| 48 | if (mask[j + 1] != 0xa5a5a5a5a5a5a5a5) |
| 49 | return clib_error_return (err, "mask overrun at position %u", j + 1); |
| 50 | } |
| 51 | return err; |
| 52 | } |
| 53 | |
| 54 | REGISTER_TEST (clib_mask_compare_u16) = { |
| 55 | .name = "clib_mask_compare_u16", |
| 56 | .fn = test_clib_mask_compare_u16, |
| 57 | }; |
| 58 | |
| 59 | static clib_error_t * |
| 60 | test_clib_mask_compare_u32 (clib_error_t *err) |
| 61 | { |
| 62 | u32 array[513]; |
| 63 | u64 mask[10]; |
| 64 | u32 i, j; |
| 65 | |
| 66 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 67 | array[i] = i; |
| 68 | |
| 69 | for (i = 0; i < ARRAY_LEN (array); i++) |
| 70 | { |
| 71 | for (j = 0; j < ARRAY_LEN (mask); j++) |
| 72 | mask[j] = 0xa5a5a5a5a5a5a5a5; |
| 73 | |
| 74 | clib_mask_compare_u32_wrapper (i, array, mask, i + 1); |
| 75 | |
| 76 | for (j = 0; j < (i >> 6); j++) |
| 77 | { |
| 78 | if (mask[j]) |
| 79 | return clib_error_return (err, "mask at position %u not zero", j); |
| 80 | } |
| 81 | if (mask[j] != 1ULL << (i & 0x3f)) |
| 82 | return clib_error_return (err, |
| 83 | "mask at position %u is %lx, expected %lx", |
| 84 | j, mask[j], 1ULL << (i % 64)); |
| 85 | |
| 86 | if (mask[j + 1] != 0xa5a5a5a5a5a5a5a5) |
| 87 | return clib_error_return (err, "mask overrun at position %u", j + 1); |
| 88 | } |
| 89 | return err; |
| 90 | } |
| 91 | |
| 92 | REGISTER_TEST (clib_mask_compare_u32) = { |
| 93 | .name = "clib_mask_compare_u32", |
| 94 | .fn = test_clib_mask_compare_u32, |
| 95 | }; |