Dave Barach | b7f1faa | 2017-08-29 11:43:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at: |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <vppinfra/pool.h> |
| 18 | |
| 19 | /* can be a very large size */ |
| 20 | #define NELTS 1024 |
| 21 | |
| 22 | int |
| 23 | main (int argc, char *argv[]) |
| 24 | { |
| 25 | u32 *junk = 0; |
| 26 | int i; |
| 27 | u32 *tp = 0; |
| 28 | u32 *indices = 0; |
| 29 | |
| 30 | clib_mem_init (0, 3ULL << 30); |
| 31 | |
| 32 | vec_validate (indices, NELTS - 1); |
| 33 | _vec_len (indices) = 0; |
| 34 | |
| 35 | pool_init_fixed (tp, NELTS); |
| 36 | |
| 37 | for (i = 0; i < NELTS; i++) |
| 38 | { |
| 39 | pool_get (tp, junk); |
| 40 | vec_add1 (indices, junk - tp); |
| 41 | *junk = i; |
| 42 | } |
| 43 | |
| 44 | for (i = 0; i < NELTS; i++) |
| 45 | { |
| 46 | junk = pool_elt_at_index (tp, indices[i]); |
| 47 | ASSERT (*junk == i); |
| 48 | } |
| 49 | |
| 50 | fformat (stdout, "%d pool elts before deletes\n", pool_elts (tp)); |
| 51 | |
| 52 | pool_put_index (tp, indices[12]); |
| 53 | pool_put_index (tp, indices[43]); |
| 54 | |
| 55 | fformat (stdout, "%d pool elts after deletes\n", pool_elts (tp)); |
| 56 | |
| 57 | pool_validate (tp); |
| 58 | |
| 59 | pool_free (tp); |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * fd.io coding-style-patch-verification: ON |
| 65 | * |
| 66 | * Local Variables: |
| 67 | * eval: (c-set-style "gnu") |
| 68 | * End: |
| 69 | */ |