Vladislav Grishenko | 8a4b797 | 2022-09-28 13:37:02 +0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright(c) 2023 Yandex LLC. |
| 3 | */ |
| 4 | |
| 5 | #include <vppinfra/pool.h> |
| 6 | |
| 7 | /* can be a very large size */ |
| 8 | #define NELTS 1024 |
| 9 | |
| 10 | int |
| 11 | main (int argc, char *argv[]) |
| 12 | { |
| 13 | u32 *junk = 0; |
| 14 | int i; |
| 15 | u32 *tp = 0; |
| 16 | u32 *indices = 0; |
| 17 | |
| 18 | clib_mem_init (0, 3ULL << 30); |
| 19 | |
| 20 | vec_validate (indices, NELTS - 1); |
| 21 | vec_set_len (indices, 0); |
| 22 | |
| 23 | /* zero size allocation is ok */ |
| 24 | pool_alloc (tp, 0); |
| 25 | |
| 26 | fformat (stdout, "%d pool elts of empty pool\n", pool_elts (tp)); |
| 27 | |
| 28 | pool_validate (tp); |
| 29 | |
| 30 | pool_alloc (tp, NELTS); |
| 31 | |
| 32 | for (i = 0; i < NELTS; i++) |
| 33 | { |
| 34 | pool_get (tp, junk); |
| 35 | vec_add1 (indices, junk - tp); |
| 36 | *junk = i; |
| 37 | } |
| 38 | |
| 39 | for (i = 0; i < NELTS; i++) |
| 40 | { |
| 41 | junk = pool_elt_at_index (tp, indices[i]); |
| 42 | ASSERT (*junk == i); |
| 43 | } |
| 44 | |
| 45 | fformat (stdout, "%d pool elts before deletes\n", pool_elts (tp)); |
| 46 | |
| 47 | pool_put_index (tp, indices[12]); |
| 48 | pool_put_index (tp, indices[43]); |
| 49 | |
| 50 | fformat (stdout, "%d pool elts after deletes\n", pool_elts (tp)); |
| 51 | |
| 52 | pool_validate (tp); |
| 53 | |
| 54 | pool_free (tp); |
| 55 | return 0; |
| 56 | } |