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 | { |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 36 | for (int step = 1; step < num_ints; step++) |
Paul Atkins | dfc4316 | 2022-04-06 14:51:21 +0100 | [diff] [blame] | 37 | { |
| 38 | int int_num = -1; |
| 39 | int expected = 0; |
| 40 | |
| 41 | debug (" Step of %d\n", step); |
| 42 | for (int i = 0; i < num_ints; i += step) |
| 43 | { |
| 44 | debug (" Setting %d\n", i); |
| 45 | clib_interrupt_set (interrupts, i); |
| 46 | } |
| 47 | |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 48 | while ((int_num = |
| 49 | clib_interrupt_get_next_and_clear (interrupts, int_num)) != -1) |
Paul Atkins | dfc4316 | 2022-04-06 14:51:21 +0100 | [diff] [blame] | 50 | { |
| 51 | debug (" Got %d, expecting %d\n", int_num, expected); |
| 52 | ASSERT (int_num == expected); |
| 53 | expected += step; |
Paul Atkins | dfc4316 | 2022-04-06 14:51:21 +0100 | [diff] [blame] | 54 | } |
Damjan Marion | 7f75e80 | 2023-11-03 21:57:42 +0000 | [diff] [blame] | 55 | int_num = clib_interrupt_get_next_and_clear (interrupts, -1); |
| 56 | ASSERT (int_num == -1); |
Paul Atkins | dfc4316 | 2022-04-06 14:51:21 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | int |
| 61 | main (int argc, char *argv[]) |
| 62 | { |
| 63 | clib_mem_init (0, 3ULL << 30); |
| 64 | |
| 65 | debug = (argc > 1); |
| 66 | |
| 67 | void *interrupts = NULL; |
| 68 | |
| 69 | for (int num_ints = 0; num_ints < MAX_INTS; num_ints++) |
| 70 | { |
| 71 | clib_interrupt_resize (&interrupts, num_ints); |
| 72 | debug ("Size now %d\n", num_ints); |
| 73 | |
| 74 | set_and_check_bits (interrupts, num_ints); |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |