blob: 133692d1bd0f4567819e17021cb8bb896a3dab94 [file] [log] [blame]
Paul Atkinsdfc43162022-04-06 14:51:21 +01001/*
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
25int debug = 0;
26
27#define debug(format, args...) \
28 if (debug) \
29 { \
30 fformat (stdout, format, ##args); \
31 }
32
33void
34set_and_check_bits (void *interrupts, int num_ints)
35{
Damjan Marion7f75e802023-11-03 21:57:42 +000036 for (int step = 1; step < num_ints; step++)
Paul Atkinsdfc43162022-04-06 14:51:21 +010037 {
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 Marion7f75e802023-11-03 21:57:42 +000048 while ((int_num =
49 clib_interrupt_get_next_and_clear (interrupts, int_num)) != -1)
Paul Atkinsdfc43162022-04-06 14:51:21 +010050 {
51 debug (" Got %d, expecting %d\n", int_num, expected);
52 ASSERT (int_num == expected);
53 expected += step;
Paul Atkinsdfc43162022-04-06 14:51:21 +010054 }
Damjan Marion7f75e802023-11-03 21:57:42 +000055 int_num = clib_interrupt_get_next_and_clear (interrupts, -1);
56 ASSERT (int_num == -1);
Paul Atkinsdfc43162022-04-06 14:51:21 +010057 }
58}
59
60int
61main (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}