1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
5 #include <vppinfra/format.h>
6 #include <vppinfra/vector_funcs.h>
7 #include <vppinfra/test_vector_funcs.h>
10 clib_compress_u32_wrapper (u32 *dst, u32 *src, u64 *mask, u32 n_elts)
12 return clib_compress_u32 (dst, src, mask, n_elts);
21 static compress_test_t tests[] = {
22 { .mask = { 1 }, .n_elts = 1 },
23 { .mask = { 2 }, .n_elts = 2 },
24 { .mask = { 3 }, .n_elts = 2 },
25 { .mask = { 0, 1 }, .n_elts = 66 },
26 { .mask = { 0, 2 }, .n_elts = 69 },
27 { .mask = { 0, 3 }, .n_elts = 66 },
28 { .mask = { ~0ULL, ~0ULL, ~0ULL, ~0ULL }, .n_elts = 62 },
29 { .mask = { ~0ULL, ~0ULL, ~0ULL, ~0ULL }, .n_elts = 255 },
30 { .mask = { ~0ULL, 1, 1, ~0ULL }, .n_elts = 256 },
34 test_clib_compress_u32 (clib_error_t *err)
40 for (i = 0; i < ARRAY_LEN (src); i++)
43 for (i = 0; i < ARRAY_LEN (tests); i++)
45 compress_test_t *t = tests + i;
49 for (j = 0; j < ARRAY_LEN (dst); j++)
52 r = clib_compress_u32_wrapper (dst, src, t->mask, t->n_elts);
54 for (j = 0; j < t->n_elts; j++)
56 if ((t->mask[j >> 6] & (1ULL << (j & 0x3f))) == 0)
60 return clib_error_return (err,
61 "wrong data in testcase %u at "
62 "(dst[%u] = 0x%x, src[%u] = 0x%x)",
63 i, dp - dst, dp[0], j, src[j]);
67 if (dst[dp - dst + 1] != 0xa5a5a5a5)
68 return clib_error_return (err, "buffer overrun in testcase %u", i);
71 return clib_error_return (err, "wrong number of elts in testcase %u",
78 REGISTER_TEST (clib_compress_u32) = {
79 .name = "clib_compress_u32",
80 .fn = test_clib_compress_u32,