Paul Atkins | dfc4316 | 2022-04-06 14:51:21 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2021 Graphiant, Inc. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vppinfra/clib.h> |
| 17 | #include <vppinfra/format.h> |
| 18 | #include <vppinfra/error.h> |
| 19 | #include <vppinfra/random.h> |
| 20 | #include <vppinfra/time.h> |
| 21 | #include <vppinfra/interrupt.h> |
| 22 | |
| 23 | #define MAX_INTS 2048 |
| 24 | |
| 25 | int debug = 0; |
| 26 | |
| 27 | #define debug(format, args...) \ |
| 28 | if (debug) \ |
| 29 | { \ |
| 30 | fformat (stdout, format, ##args); \ |
| 31 | } |
| 32 | |
| 33 | void |
| 34 | set_and_check_bits (void *interrupts, int num_ints) |
| 35 | { |
| 36 | |
| 37 | int step; |
| 38 | |
| 39 | for (step = 1; step < num_ints; step++) |
| 40 | { |
| 41 | int int_num = -1; |
| 42 | int expected = 0; |
| 43 | |
| 44 | debug (" Step of %d\n", step); |
| 45 | for (int i = 0; i < num_ints; i += step) |
| 46 | { |
| 47 | debug (" Setting %d\n", i); |
| 48 | clib_interrupt_set (interrupts, i); |
| 49 | } |
| 50 | |
| 51 | while ((int_num = clib_interrupt_get_next (interrupts, int_num)) != -1) |
| 52 | { |
| 53 | debug (" Got %d, expecting %d\n", int_num, expected); |
| 54 | ASSERT (int_num == expected); |
| 55 | expected += step; |
| 56 | clib_interrupt_clear (interrupts, int_num); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | int |
| 62 | main (int argc, char *argv[]) |
| 63 | { |
| 64 | clib_mem_init (0, 3ULL << 30); |
| 65 | |
| 66 | debug = (argc > 1); |
| 67 | |
| 68 | void *interrupts = NULL; |
| 69 | |
| 70 | for (int num_ints = 0; num_ints < MAX_INTS; num_ints++) |
| 71 | { |
| 72 | clib_interrupt_resize (&interrupts, num_ints); |
| 73 | debug ("Size now %d\n", num_ints); |
| 74 | |
| 75 | set_and_check_bits (interrupts, num_ints); |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |