Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2014 Intel Corporation
3 : : */
4 : :
5 : : #include <stdbool.h>
6 : : #include <stdio.h>
7 : : #include <stdint.h>
8 : : #include <limits.h>
9 : :
10 : : #include <rte_common.h>
11 : : #include <rte_debug.h>
12 : : #include <rte_errno.h>
13 : : #include <rte_fbarray.h>
14 : :
15 : : #include "test.h"
16 : :
17 : : struct fbarray_testsuite_params {
18 : : struct rte_fbarray arr;
19 : : int start;
20 : : int end;
21 : : };
22 : :
23 : : static struct fbarray_testsuite_params param;
24 : : static struct fbarray_testsuite_params unaligned;
25 : :
26 : : #define FBARRAY_TEST_ARR_NAME "fbarray_autotest"
27 : : #define FBARRAY_TEST_LEN 256
28 : : #define FBARRAY_UNALIGNED_TEST_ARR_NAME "fbarray_unaligned_autotest"
29 : : #define FBARRAY_UNALIGNED_TEST_LEN 60
30 : : #define FBARRAY_TEST_ELT_SZ (sizeof(int))
31 : :
32 : 1 : static int autotest_setup(void)
33 : : {
34 : : int ret;
35 : :
36 : 1 : ret = rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME,
37 : : FBARRAY_TEST_LEN, FBARRAY_TEST_ELT_SZ);
38 [ - + ]: 1 : if (ret) {
39 : : printf("Failed to initialize test array\n");
40 : 0 : return -1;
41 : : }
42 : 1 : ret = rte_fbarray_init(&unaligned.arr, FBARRAY_UNALIGNED_TEST_ARR_NAME,
43 : : FBARRAY_UNALIGNED_TEST_LEN, FBARRAY_TEST_ELT_SZ);
44 [ - + ]: 1 : if (ret) {
45 : : printf("Failed to initialize unaligned test array\n");
46 : 0 : rte_fbarray_destroy(¶m.arr);
47 : 0 : return -1;
48 : : }
49 : : return 0;
50 : : }
51 : :
52 : 1 : static void autotest_teardown(void)
53 : : {
54 : 1 : rte_fbarray_destroy(¶m.arr);
55 : 1 : rte_fbarray_destroy(&unaligned.arr);
56 : 1 : }
57 : :
58 : 10 : static int init_aligned(void)
59 : : {
60 : : int i;
61 [ + + ]: 815 : for (i = param.start; i <= param.end; i++) {
62 [ + - ]: 805 : if (rte_fbarray_set_used(¶m.arr, i))
63 : : return -1;
64 : : }
65 : : return 0;
66 : : }
67 : :
68 : 2 : static int init_unaligned(void)
69 : : {
70 : : int i;
71 [ + + ]: 121 : for (i = unaligned.start; i <= unaligned.end; i++) {
72 [ + - ]: 119 : if (rte_fbarray_set_used(&unaligned.arr, i))
73 : : return -1;
74 : : }
75 : : return 0;
76 : : }
77 : :
78 : 13 : static void reset_aligned(void)
79 : : {
80 : : int i;
81 [ + + + + ]: 3598 : for (i = 0; i < FBARRAY_TEST_LEN; i++)
82 : 3584 : rte_fbarray_set_free(¶m.arr, i);
83 : : /* reset param as well */
84 : 14 : param.start = -1;
85 : 14 : param.end = -1;
86 : 13 : }
87 : :
88 : 2 : static void reset_unaligned(void)
89 : : {
90 : : int i;
91 [ + + ]: 122 : for (i = 0; i < FBARRAY_UNALIGNED_TEST_LEN; i++)
92 : 120 : rte_fbarray_set_free(&unaligned.arr, i);
93 : : /* reset param as well */
94 : 2 : unaligned.start = -1;
95 : 2 : unaligned.end = -1;
96 : :
97 : 2 : }
98 : :
99 : 1 : static int first_msk_test_setup(void)
100 : : {
101 : : /* put all within first mask */
102 : 1 : param.start = 3;
103 : 1 : param.end = 10;
104 : 1 : return init_aligned();
105 : : }
106 : :
107 : 1 : static int contig_test_setup(void)
108 : : {
109 : : /* put all within second and third mask */
110 : 1 : param.start = 70;
111 : 1 : param.end = 160;
112 : 1 : return init_aligned();
113 : : }
114 : :
115 : 1 : static int large_contig_test_setup(void)
116 : : {
117 : : /* put all within first and last mask */
118 : 1 : param.start = 3;
119 : 1 : param.end = FBARRAY_TEST_LEN - 20;
120 : 1 : return init_aligned();
121 : : }
122 : :
123 : 1 : static int last_msk_test_setup(void)
124 : : {
125 : : /* put all within last mask */
126 : 1 : param.start = FBARRAY_TEST_LEN - 20;
127 : 1 : param.end = FBARRAY_TEST_LEN - 1;
128 : 1 : return init_aligned();
129 : : }
130 : :
131 : 1 : static int full_index_test_setup(void)
132 : : {
133 : : /* fill entire index */
134 : 1 : param.start = 0;
135 : 1 : param.end = FBARRAY_TEST_LEN - 1;
136 : 1 : return init_aligned();
137 : : }
138 : :
139 : 1 : static int full_msk_test_setup(void)
140 : : {
141 : : /* fill one mask */
142 : 1 : param.start = 0;
143 : 1 : param.end = 63;
144 : 1 : return init_aligned();
145 : : }
146 : :
147 : 1 : static int full_msk_contig_fwd_test_setup(void)
148 : : {
149 : : /* fill one mask plus one item */
150 : 1 : param.start = 64;
151 : 1 : param.end = 128;
152 : 1 : return init_aligned();
153 : : }
154 : :
155 : 1 : static int full_msk_contig_rev_test_setup(void)
156 : : {
157 : : /* fill one mask plus one item */
158 : 1 : param.start = 63;
159 : 1 : param.end = 127;
160 : 1 : return init_aligned();
161 : : }
162 : :
163 : 1 : static int cross_msk_test_setup(void)
164 : : {
165 : : /* set index 64 as used */
166 : 1 : param.start = 64;
167 : 1 : param.end = 64;
168 : 1 : return init_aligned();
169 : : }
170 : :
171 : 1 : static int cross_msk_rev_test_setup(void)
172 : : {
173 : : /* set index 63 as used */
174 : 1 : param.start = 63;
175 : 1 : param.end = 63;
176 : 1 : return init_aligned();
177 : : }
178 : :
179 : 1 : static int unaligned_test_setup(void)
180 : : {
181 : 1 : unaligned.start = 0;
182 : : /* leave one free bit at the end */
183 : 1 : unaligned.end = FBARRAY_UNALIGNED_TEST_LEN - 2;
184 : 1 : return init_unaligned();
185 : : }
186 : :
187 : 1 : static int full_unaligned_test_setup(void)
188 : : {
189 : 1 : unaligned.start = 0;
190 : 1 : unaligned.end = FBARRAY_UNALIGNED_TEST_LEN - 1;
191 : 1 : return init_unaligned();
192 : : }
193 : :
194 : 1 : static int test_invalid(void)
195 : : {
196 : : struct rte_fbarray dummy;
197 : :
198 : : /* invalid parameters */
199 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_attach(NULL),
200 : : "Call succeeded with invalid parameters\n");
201 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
202 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_detach(NULL),
203 : : "Call succeeded with invalid parameters\n");
204 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
205 : :
206 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_destroy(NULL),
207 : : "Call succeeded with invalid parameters\n");
208 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno valuey\n");
209 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_init(NULL, "fail", 16, 16),
210 : : "Call succeeded with invalid parameters\n");
211 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
212 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, NULL, 16, 16),
213 : : "Call succeeded with invalid parameters\n");
214 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
215 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", 0, 16),
216 : : "Call succeeded with invalid parameters\n");
217 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
218 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", 16, 0),
219 : : "Call succeeded with invalid parameters\n");
220 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
221 : : /* len must not be greater than INT_MAX */
222 [ - + ]: 1 : TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", INT_MAX + 1U, 16),
223 : : "Call succeeded with invalid parameters\n");
224 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
225 : :
226 [ - + ]: 1 : TEST_ASSERT_NULL(rte_fbarray_get(NULL, 0),
227 : : "Call succeeded with invalid parameters\n");
228 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
229 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_idx(NULL, 0) < 0,
230 : : "Call succeeded with invalid parameters\n");
231 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
232 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_set_free(NULL, 0),
233 : : "Call succeeded with invalid parameters\n");
234 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
235 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_set_used(NULL, 0),
236 : : "Call succeeded with invalid parameters\n");
237 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
238 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_contig_free(NULL, 0) < 0,
239 : : "Call succeeded with invalid parameters\n");
240 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
241 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_contig_used(NULL, 0) < 0,
242 : : "Call succeeded with invalid parameters\n");
243 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
244 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_rev_contig_free(NULL, 0) < 0,
245 : : "Call succeeded with invalid parameters\n");
246 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
247 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_rev_contig_used(NULL, 0) < 0,
248 : : "Call succeeded with invalid parameters\n");
249 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
250 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_free(NULL, 0) < 0,
251 : : "Call succeeded with invalid parameters\n");
252 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
253 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_used(NULL, 0) < 0,
254 : : "Call succeeded with invalid parameters\n");
255 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
256 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_free(NULL, 0) < 0,
257 : : "Call succeeded with invalid parameters\n");
258 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
259 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_used(NULL, 0) < 0,
260 : : "Call succeeded with invalid parameters\n");
261 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
262 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_free(NULL, 0, 0) < 0,
263 : : "Call succeeded with invalid parameters\n");
264 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
265 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_used(NULL, 0, 0) < 0,
266 : : "Call succeeded with invalid parameters\n");
267 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
268 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_free(NULL, 0, 0) < 0,
269 : : "Call succeeded with invalid parameters\n");
270 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
271 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_used(NULL, 0, 0) < 0,
272 : : "Call succeeded with invalid parameters\n");
273 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
274 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_is_used(NULL, 0) < 0,
275 : : "Call succeeded with invalid parameters\n");
276 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
277 : :
278 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_fbarray_init(&dummy, "success",
279 : : FBARRAY_TEST_LEN, 8),
280 : : "Failed to initialize valid fbarray\n");
281 : :
282 : : /* test API for handling invalid parameters with a valid fbarray */
283 [ - + ]: 1 : TEST_ASSERT_NULL(rte_fbarray_get(&dummy, FBARRAY_TEST_LEN),
284 : : "Call succeeded with invalid parameters\n");
285 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
286 : :
287 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_idx(&dummy, NULL) < 0,
288 : : "Call succeeded with invalid parameters\n");
289 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
290 : :
291 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_set_free(&dummy, FBARRAY_TEST_LEN),
292 : : "Call succeeded with invalid parameters\n");
293 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
294 : :
295 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_set_used(&dummy, FBARRAY_TEST_LEN),
296 : : "Call succeeded with invalid parameters\n");
297 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
298 : :
299 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_contig_free(&dummy, FBARRAY_TEST_LEN) < 0,
300 : : "Call succeeded with invalid parameters\n");
301 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
302 : :
303 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_contig_used(&dummy, FBARRAY_TEST_LEN) < 0,
304 : : "Call succeeded with invalid parameters\n");
305 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
306 : :
307 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_rev_contig_free(&dummy,
308 : : FBARRAY_TEST_LEN) < 0,
309 : : "Call succeeded with invalid parameters\n");
310 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
311 : :
312 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_rev_contig_used(&dummy,
313 : : FBARRAY_TEST_LEN) < 0,
314 : : "Call succeeded with invalid parameters\n");
315 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
316 : :
317 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_free(&dummy, FBARRAY_TEST_LEN) < 0,
318 : : "Call succeeded with invalid parameters\n");
319 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
320 : :
321 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_used(&dummy, FBARRAY_TEST_LEN) < 0,
322 : : "Call succeeded with invalid parameters\n");
323 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
324 : :
325 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_free(&dummy, FBARRAY_TEST_LEN) < 0,
326 : : "Call succeeded with invalid parameters\n");
327 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
328 : :
329 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_used(&dummy, FBARRAY_TEST_LEN) < 0,
330 : : "Call succeeded with invalid parameters\n");
331 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
332 : :
333 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy,
334 : : FBARRAY_TEST_LEN, 1) < 0,
335 : : "Call succeeded with invalid parameters\n");
336 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
337 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy, 0,
338 : : FBARRAY_TEST_LEN + 1) < 0,
339 : : "Call succeeded with invalid parameters\n");
340 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
341 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy, 0, 0) < 0,
342 : : "Call succeeded with invalid parameters\n");
343 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
344 : :
345 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy,
346 : : FBARRAY_TEST_LEN, 1) < 0,
347 : : "Call succeeded with invalid parameters\n");
348 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
349 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy, 0,
350 : : FBARRAY_TEST_LEN + 1) < 0,
351 : : "Call succeeded with invalid parameters\n");
352 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
353 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy, 0, 0) < 0,
354 : : "Call succeeded with invalid parameters\n");
355 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
356 : :
357 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy,
358 : : FBARRAY_TEST_LEN, 1) < 0,
359 : : "Call succeeded with invalid parameters\n");
360 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
361 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy, 0,
362 : : FBARRAY_TEST_LEN + 1) < 0,
363 : : "Call succeeded with invalid parameters\n");
364 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
365 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy, 0, 0) < 0,
366 : : "Call succeeded with invalid parameters\n");
367 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
368 : :
369 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy,
370 : : FBARRAY_TEST_LEN, 1) < 0,
371 : : "Call succeeded with invalid parameters\n");
372 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
373 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy, 0,
374 : : FBARRAY_TEST_LEN + 1) < 0,
375 : : "Call succeeded with invalid parameters\n");
376 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
377 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy, 0, 0) < 0,
378 : : "Call succeeded with invalid parameters\n");
379 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
380 : :
381 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_is_used(&dummy, FBARRAY_TEST_LEN) < 0,
382 : : "Call succeeded with invalid parameters\n");
383 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
384 : :
385 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_fbarray_destroy(&dummy),
386 : : "Failed to destroy valid fbarray\n");
387 : :
388 : : return TEST_SUCCESS;
389 : : }
390 : :
391 : 2 : static int check_free(void)
392 : : {
393 : : const int idx = 0;
394 : : const int last_idx = FBARRAY_TEST_LEN - 1;
395 : :
396 : : /* ensure we can find a free spot */
397 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_free(¶m.arr, idx), idx,
398 : : "Free space not found where expected\n");
399 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(¶m.arr, idx, 1), idx,
400 : : "Free space not found where expected\n");
401 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(¶m.arr, idx),
402 : : FBARRAY_TEST_LEN,
403 : : "Free space not found where expected\n");
404 : :
405 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(¶m.arr, idx), idx,
406 : : "Free space not found where expected\n");
407 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, idx, 1), idx,
408 : : "Free space not found where expected\n");
409 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr, idx), 1,
410 : : "Free space not found where expected\n");
411 : :
412 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(¶m.arr, last_idx),
413 : : last_idx, "Free space not found where expected\n");
414 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, last_idx, 1),
415 : : last_idx, "Free space not found where expected\n");
416 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr,
417 : : last_idx), FBARRAY_TEST_LEN,
418 : : "Free space not found where expected\n");
419 : :
420 : : /* ensure we can't find any used spots */
421 [ - + ]: 2 : TEST_ASSERT(rte_fbarray_find_next_used(¶m.arr, idx) < 0,
422 : : "Used space found where none was expected\n");
423 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
424 [ - + ]: 2 : TEST_ASSERT(rte_fbarray_find_next_n_used(¶m.arr, idx, 1) < 0,
425 : : "Used space found where none was expected\n");
426 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
427 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx), 0,
428 : : "Used space found where none was expected\n");
429 : :
430 [ - + ]: 2 : TEST_ASSERT(rte_fbarray_find_prev_used(¶m.arr, last_idx) < 0,
431 : : "Used space found where none was expected\n");
432 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
433 [ - + ]: 2 : TEST_ASSERT(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1) < 0,
434 : : "Used space found where none was expected\n");
435 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
436 [ - + ]: 2 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
437 : : last_idx), 0,
438 : : "Used space found where none was expected\n");
439 : :
440 : : return 0;
441 : : }
442 : :
443 : 1 : static int check_used_one(void)
444 : : {
445 : : const int idx = 0;
446 : : const int last_idx = FBARRAY_TEST_LEN - 1;
447 : :
448 : : /* check that we can find used spots now */
449 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_used(¶m.arr, idx), idx,
450 : : "Used space not found where expected\n");
451 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(¶m.arr, idx, 1), idx,
452 : : "Used space not found where expected\n");
453 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx), 1,
454 : : "Used space not found where expected\n");
455 : :
456 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(¶m.arr, last_idx), idx,
457 : : "Used space not found where expected\n");
458 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1),
459 : : idx, "Used space not found where expected\n");
460 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr, idx), 1,
461 : : "Used space not found where expected\n");
462 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
463 : : last_idx), idx,
464 : : "Used space not found where expected\n");
465 : :
466 : : /* check if further indices are still free */
467 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_used(¶m.arr, idx + 1) < 0,
468 : : "Used space not found where none was expected\n");
469 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
470 [ - + ]: 1 : TEST_ASSERT(rte_fbarray_find_next_n_used(¶m.arr, idx + 1, 1) < 0,
471 : : "Used space not found where none was expected\n");
472 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
473 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx + 1), 0,
474 : : "Used space not found where none was expected\n");
475 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(¶m.arr, idx + 1),
476 : : FBARRAY_TEST_LEN - 1,
477 : : "Used space not found where none was expected\n");
478 : :
479 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(¶m.arr, last_idx), 0,
480 : : "Used space not found where none was expected\n");
481 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1),
482 : : 0, "Used space not found where none was expected\n");
483 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
484 : : last_idx), 0,
485 : : "Used space not found where none was expected\n");
486 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr,
487 : : last_idx), FBARRAY_TEST_LEN - 1,
488 : : "Used space not found where none was expected\n");
489 : :
490 : : return 0;
491 : : }
492 : :
493 : 1 : static int test_basic(void)
494 : : {
495 : : const int idx = 0;
496 : : int i;
497 : :
498 : : /* check array count */
499 [ - + ]: 1 : TEST_ASSERT_EQUAL(param.arr.count, 0, "Wrong element count\n");
500 : :
501 : : /* ensure we can find a free spot */
502 [ + - ]: 1 : if (check_free())
503 : : return TEST_FAILED;
504 : :
505 : : /* check if used */
506 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
507 : : "Used space found where not expected\n");
508 : :
509 : : /* mark as used */
510 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_fbarray_set_used(¶m.arr, idx),
511 : : "Failed to set as used\n");
512 : :
513 : : /* check if used again */
514 [ - + ]: 1 : TEST_ASSERT_NOT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
515 : : "Used space not found where expected\n");
516 : :
517 [ + - ]: 1 : if (check_used_one())
518 : : return TEST_FAILED;
519 : :
520 : : /* check array count */
521 [ - + ]: 1 : TEST_ASSERT_EQUAL(param.arr.count, 1, "Wrong element count\n");
522 : :
523 : : /* check if getting pointers works for every element */
524 [ + + ]: 257 : for (i = 0; i < FBARRAY_TEST_LEN; i++) {
525 : 256 : void *td = rte_fbarray_get(¶m.arr, i);
526 [ - + ]: 256 : TEST_ASSERT_NOT_NULL(td, "Invalid pointer returned\n");
527 [ - + ]: 256 : TEST_ASSERT_EQUAL(rte_fbarray_find_idx(¶m.arr, td), i,
528 : : "Wrong index returned\n");
529 : : }
530 : :
531 : : /* mark as free */
532 [ - + ]: 1 : TEST_ASSERT_SUCCESS(rte_fbarray_set_free(¶m.arr, idx),
533 : : "Failed to set as free\n");
534 : :
535 : : /* check array count */
536 [ - + ]: 1 : TEST_ASSERT_EQUAL(param.arr.count, 0, "Wrong element count\n");
537 : :
538 : : /* check if used */
539 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
540 : : "Used space found where not expected\n");
541 : :
542 [ + - ]: 1 : if (check_free())
543 : : return TEST_FAILED;
544 : :
545 : : reset_aligned();
546 : :
547 : 1 : return TEST_SUCCESS;
548 : : }
549 : :
550 : 13 : static int test_biggest(struct rte_fbarray *arr, int first, int last)
551 : : {
552 : : int lo_free_space_first, lo_free_space_last, lo_free_space_len;
553 : : int hi_free_space_first, hi_free_space_last, hi_free_space_len;
554 : : int max_free_space_first, max_free_space_last, max_free_space_len;
555 : 13 : int len = last - first + 1;
556 : :
557 : : /* first and last must either be both -1, or both not -1 */
558 [ - + ]: 13 : TEST_ASSERT((first == -1) == (last == -1),
559 : : "Invalid arguments provided\n");
560 : :
561 : : /* figure out what we expect from the low chunk of free space */
562 [ + + ]: 13 : if (first == -1) {
563 : : /* special case: if there are no occupied elements at all,
564 : : * consider both free spaces to consume the entire array.
565 : : */
566 : : lo_free_space_first = 0;
567 : 1 : lo_free_space_last = arr->len - 1;
568 : 1 : lo_free_space_len = arr->len;
569 : : /* if there's no used space, length should be invalid */
570 : : len = -1;
571 [ + + ]: 12 : } else if (first == 0) {
572 : : /* if occupied items start at 0, there's no free space */
573 : : lo_free_space_first = -1;
574 : : lo_free_space_last = -1;
575 : : lo_free_space_len = 0;
576 : : } else {
577 : : lo_free_space_first = 0;
578 : 8 : lo_free_space_last = first - 1;
579 : : lo_free_space_len = lo_free_space_last -
580 : : lo_free_space_first + 1;
581 : : }
582 : :
583 : : /* figure out what we expect from the high chunk of free space */
584 [ + + ]: 13 : if (last == -1) {
585 : : /* special case: if there are no occupied elements at all,
586 : : * consider both free spaces to consume the entire array.
587 : : */
588 : : hi_free_space_first = 0;
589 : 1 : hi_free_space_last = arr->len - 1;
590 : 1 : hi_free_space_len = arr->len;
591 : : /* if there's no used space, length should be invalid */
592 : : len = -1;
593 [ + + ]: 12 : } else if (last == ((int)arr->len - 1)) {
594 : : /* if occupied items end at array len, there's no free space */
595 : : hi_free_space_first = -1;
596 : : hi_free_space_last = -1;
597 : : hi_free_space_len = 0;
598 : : } else {
599 : 9 : hi_free_space_first = last + 1;
600 : 9 : hi_free_space_last = arr->len - 1;
601 : 9 : hi_free_space_len = hi_free_space_last -
602 : : hi_free_space_first + 1;
603 : : }
604 : :
605 : : /* find which one will be biggest */
606 [ + + ]: 13 : if (lo_free_space_len > hi_free_space_len) {
607 : : max_free_space_first = lo_free_space_first;
608 : : max_free_space_last = lo_free_space_last;
609 : : max_free_space_len = lo_free_space_len;
610 : : } else {
611 : : /* if they are equal, we'll just use the high chunk */
612 : : max_free_space_first = hi_free_space_first;
613 : : max_free_space_last = hi_free_space_last;
614 : : max_free_space_len = hi_free_space_len;
615 : : }
616 : :
617 : : /* check used regions - these should produce identical results */
618 [ - + ]: 13 : TEST_ASSERT_EQUAL(rte_fbarray_find_biggest_used(arr, 0), first,
619 : : "Used space index is wrong\n");
620 [ - + ]: 13 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_biggest_used(arr, arr->len - 1),
621 : : first,
622 : : "Used space index is wrong\n");
623 : : /* len may be -1, but function will return error anyway */
624 [ - + ]: 13 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(arr, first), len,
625 : : "Used space length is wrong\n");
626 : :
627 : : /* check if biggest free region is the one we expect to find. It can be
628 : : * -1 if there's no free space - we've made sure we use one or the
629 : : * other, even if both are invalid.
630 : : */
631 [ - + ]: 13 : TEST_ASSERT_EQUAL(rte_fbarray_find_biggest_free(arr, 0),
632 : : max_free_space_first,
633 : : "Biggest free space index is wrong\n");
634 [ - + ]: 13 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_biggest_free(arr, arr->len - 1),
635 : : max_free_space_first,
636 : : "Biggest free space index is wrong\n");
637 : :
638 : : /* if biggest region exists, check its length */
639 [ + + ]: 13 : if (max_free_space_first != -1) {
640 [ - + ]: 11 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(arr,
641 : : max_free_space_first),
642 : : max_free_space_len,
643 : : "Biggest free space length is wrong\n");
644 [ - + ]: 11 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
645 : : max_free_space_last),
646 : : max_free_space_len,
647 : : "Biggest free space length is wrong\n");
648 : : }
649 : :
650 : : /* find if we see what we expect to see in the low region. if there is
651 : : * no free space, the function should still match expected value, as
652 : : * we've set it to -1. we're scanning backwards to avoid accidentally
653 : : * hitting the high free space region. if there is no occupied space,
654 : : * there's nothing to do.
655 : : */
656 [ + + ]: 13 : if (last != -1) {
657 [ - + ]: 12 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_biggest_free(arr, last),
658 : : lo_free_space_first,
659 : : "Low free space index is wrong\n");
660 : : }
661 : :
662 [ + + ]: 13 : if (lo_free_space_first != -1) {
663 : : /* if low free region exists, check its length */
664 [ - + ]: 9 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(arr,
665 : : lo_free_space_first),
666 : : lo_free_space_len,
667 : : "Low free space length is wrong\n");
668 [ - + ]: 9 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
669 : : lo_free_space_last),
670 : : lo_free_space_len,
671 : : "Low free space length is wrong\n");
672 : : }
673 : :
674 : : /* find if we see what we expect to see in the high region. if there is
675 : : * no free space, the function should still match expected value, as
676 : : * we've set it to -1. we're scanning forwards to avoid accidentally
677 : : * hitting the low free space region. if there is no occupied space,
678 : : * there's nothing to do.
679 : : */
680 [ + + ]: 13 : if (first != -1) {
681 [ - + ]: 12 : TEST_ASSERT_EQUAL(rte_fbarray_find_biggest_free(arr, first),
682 : : hi_free_space_first,
683 : : "High free space index is wrong\n");
684 : : }
685 : :
686 : : /* if high free region exists, check its length */
687 [ + + ]: 13 : if (hi_free_space_first != -1) {
688 [ - + ]: 10 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(arr,
689 : : hi_free_space_first),
690 : : hi_free_space_len,
691 : : "High free space length is wrong\n");
692 [ - + ]: 10 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
693 : : hi_free_space_last),
694 : : hi_free_space_len,
695 : : "High free space length is wrong\n");
696 : : }
697 : :
698 : : return 0;
699 : : }
700 : :
701 : 37 : static int ensure_correct(struct rte_fbarray *arr, int first, int last,
702 : : bool used)
703 : : {
704 : 37 : int i, len = last - first + 1;
705 [ + + ]: 2973 : for (i = 0; i < len; i++) {
706 : 2936 : int cur = first + i;
707 : 2936 : int cur_len = len - i;
708 : :
709 [ + + ]: 2936 : if (used) {
710 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(arr,
711 : : cur), cur_len,
712 : : "Used space length is wrong\n");
713 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(arr,
714 : : last), len,
715 : : "Used space length is wrong\n");
716 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(arr,
717 : : cur), i + 1,
718 : : "Used space length is wrong\n");
719 : :
720 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_used(arr, cur),
721 : : cur,
722 : : "Used space not found where expected\n");
723 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(arr,
724 : : cur, 1), cur,
725 : : "Used space not found where expected\n");
726 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(arr, cur,
727 : : cur_len), cur,
728 : : "Used space not found where expected\n");
729 : :
730 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(arr, cur),
731 : : cur,
732 : : "Used space not found where expected\n");
733 [ - + ]: 924 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(arr,
734 : : last, cur_len), cur,
735 : : "Used space not found where expected\n");
736 : : } else {
737 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(arr,
738 : : cur), cur_len,
739 : : "Free space length is wrong\n");
740 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
741 : : last), len,
742 : : "Free space length is wrong\n");
743 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
744 : : cur), i + 1,
745 : : "Free space length is wrong\n");
746 : :
747 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_free(arr, cur),
748 : : cur,
749 : : "Free space not found where expected\n");
750 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(arr, cur,
751 : : 1), cur,
752 : : "Free space not found where expected\n");
753 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(arr, cur,
754 : : cur_len), cur,
755 : : "Free space not found where expected\n");
756 : :
757 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(arr, cur),
758 : : cur,
759 : : "Free space not found where expected\n");
760 [ - + ]: 2012 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(arr,
761 : : last, cur_len), cur,
762 : : "Free space not found where expected\n");
763 : : }
764 : : }
765 : : return 0;
766 : : }
767 : :
768 : 10 : static int test_find(void)
769 : : {
770 [ - + ]: 10 : TEST_ASSERT_EQUAL((int)param.arr.count, param.end - param.start + 1,
771 : : "Wrong element count\n");
772 : : /* ensure space is free before start */
773 [ + - ]: 10 : if (ensure_correct(¶m.arr, 0, param.start - 1, false))
774 : : return TEST_FAILED;
775 : : /* ensure space is occupied where it's supposed to be */
776 [ + - ]: 10 : if (ensure_correct(¶m.arr, param.start, param.end, true))
777 : : return TEST_FAILED;
778 : : /* ensure space after end is free as well */
779 [ + - ]: 10 : if (ensure_correct(¶m.arr, param.end + 1, FBARRAY_TEST_LEN - 1,
780 : : false))
781 : : return TEST_FAILED;
782 : : /* test if find_biggest API's work correctly */
783 [ - + ]: 10 : if (test_biggest(¶m.arr, param.start, param.end))
784 : 0 : return TEST_FAILED;
785 : : return TEST_SUCCESS;
786 : : }
787 : :
788 : 2 : static int test_find_unaligned(void)
789 : : {
790 [ - + ]: 2 : TEST_ASSERT_EQUAL((int)unaligned.arr.count, unaligned.end - unaligned.start + 1,
791 : : "Wrong element count\n");
792 : : /* ensure space is free before start */
793 [ + - ]: 2 : if (ensure_correct(&unaligned.arr, 0, unaligned.start - 1, false))
794 : : return TEST_FAILED;
795 : : /* ensure space is occupied where it's supposed to be */
796 [ + - ]: 2 : if (ensure_correct(&unaligned.arr, unaligned.start, unaligned.end, true))
797 : : return TEST_FAILED;
798 : : /* ensure space after end is free as well */
799 [ + - ]: 2 : if (ensure_correct(&unaligned.arr, unaligned.end + 1, FBARRAY_UNALIGNED_TEST_LEN - 1,
800 : : false))
801 : : return TEST_FAILED;
802 : : /* test if find_biggest API's work correctly */
803 [ - + ]: 2 : if (test_biggest(&unaligned.arr, unaligned.start, unaligned.end))
804 : 0 : return TEST_FAILED;
805 : : return TEST_SUCCESS;
806 : : }
807 : :
808 : 1 : static int test_empty(void)
809 : : {
810 [ - + ]: 1 : TEST_ASSERT_EQUAL((int)param.arr.count, 0, "Wrong element count\n");
811 : : /* ensure space is free */
812 [ + - ]: 1 : if (ensure_correct(¶m.arr, 0, FBARRAY_TEST_LEN - 1, false))
813 : : return TEST_FAILED;
814 : : /* test if find_biggest API's work correctly */
815 [ - + ]: 1 : if (test_biggest(¶m.arr, param.start, param.end))
816 : 0 : return TEST_FAILED;
817 : : return TEST_SUCCESS;
818 : : }
819 : :
820 : 1 : static int test_cross_msk(void)
821 : : {
822 : : int ret;
823 : :
824 : : /* run regular test first */
825 : 1 : ret = test_find();
826 [ + - ]: 1 : if (ret != TEST_SUCCESS)
827 : : return ret;
828 : :
829 : : /* test if we can find free chunk while not starting with 0 */
830 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(¶m.arr, 1, param.start),
831 : : param.start + 1, "Free chunk index is wrong\n");
832 : : return TEST_SUCCESS;
833 : : }
834 : :
835 : 1 : static int test_cross_rev_msk(void)
836 : : {
837 : : int ret, free_len = 2;
838 : :
839 : : /* run regular test first */
840 : 1 : ret = test_find();
841 [ + - ]: 1 : if (ret != TEST_SUCCESS)
842 : : return ret;
843 : :
844 : : /* test if we can find free chunk while crossing mask boundary */
845 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, param.start + 1, free_len),
846 : : param.start - free_len, "Free chunk index is wrong\n");
847 : : return TEST_SUCCESS;
848 : : }
849 : :
850 : 1 : static int test_broken_run(void)
851 : : {
852 : : /*
853 : : * There is a certain type of search behavior we want to test here,
854 : : * namely starting cross-mask runs and failing to find them. This is
855 : : * achieved when these conditions happen:
856 : : *
857 : : * 0. Look for a big enough chunk of free space (say, 62 elements)
858 : : * 1. Break a run somewhere inside mask 0 (indices 0-63) but leave
859 : : * some free elements at the end of mask 0 to start a run
860 : : * 2. Break the run somewhere inside mask 1 (indices 64-127)
861 : : * 3. Ensure that we can still find a free space run right after the
862 : : * second broken run
863 : : */
864 : :
865 : : /* break run on first mask */
866 : 1 : rte_fbarray_set_used(¶m.arr, 61);
867 : : /* break run on second mask */
868 : 1 : rte_fbarray_set_used(¶m.arr, 70);
869 : :
870 : : /* we expect to find free space at 71 */
871 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(¶m.arr, 0, 62),
872 : : 71, "Free chunk index is wrong\n");
873 : : return TEST_SUCCESS;
874 : : }
875 : :
876 : 1 : static int test_rev_broken_run(void)
877 : : {
878 : : /*
879 : : * There is a certain type of search behavior we want to test here,
880 : : * namely starting cross-mask runs and failing to find them. This is
881 : : * achieved when these conditions happen:
882 : : *
883 : : * 0. Look for a big enough chunk of free space (say, 62 elements)
884 : : * 1. Break a run somewhere inside mask 2 (indices 128-191) but leave
885 : : * some free elements at the beginning of mask 2 to start a run
886 : : * 2. Break the run somewhere inside mask 1 (indices 64-127)
887 : : * 3. Ensure that we can still find free space N elements down from
888 : : * our last broken run (inside mask 0 in this case)
889 : : */
890 : :
891 : : /* break run on mask 2 */
892 : 1 : rte_fbarray_set_used(¶m.arr, 130);
893 : : /* break run on mask 1 */
894 : 1 : rte_fbarray_set_used(¶m.arr, 70);
895 : :
896 : : /* start from 190, we expect to find free space at 8 */
897 [ - + ]: 1 : TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, 190, 62),
898 : : 8, "Free chunk index is wrong\n");
899 : : return TEST_SUCCESS;
900 : : }
901 : :
902 : : static struct unit_test_suite fbarray_test_suite = {
903 : : .suite_name = "fbarray autotest",
904 : : .setup = autotest_setup,
905 : : .teardown = autotest_teardown,
906 : : .unit_test_cases = {
907 : : TEST_CASE(test_invalid),
908 : : TEST_CASE(test_basic),
909 : : TEST_CASE_ST(first_msk_test_setup, reset_aligned, test_find),
910 : : TEST_CASE_ST(contig_test_setup, reset_aligned, test_find),
911 : : TEST_CASE_ST(large_contig_test_setup, reset_aligned, test_find),
912 : : TEST_CASE_ST(last_msk_test_setup, reset_aligned, test_find),
913 : : TEST_CASE_ST(full_msk_test_setup, reset_aligned, test_find),
914 : : TEST_CASE_ST(full_msk_contig_fwd_test_setup, reset_aligned, test_find),
915 : : TEST_CASE_ST(full_msk_contig_rev_test_setup, reset_aligned, test_find),
916 : : TEST_CASE_ST(full_index_test_setup, reset_aligned, test_find),
917 : : /* empty test does not need setup */
918 : : TEST_CASE_ST(NULL, reset_aligned, test_empty),
919 : : TEST_CASE_ST(cross_msk_test_setup, reset_aligned, test_cross_msk),
920 : : TEST_CASE_ST(cross_msk_rev_test_setup, reset_aligned, test_cross_rev_msk),
921 : : /* setup for these tests is more complex so do it in test func */
922 : : TEST_CASE_ST(NULL, reset_aligned, test_broken_run),
923 : : TEST_CASE_ST(NULL, reset_aligned, test_rev_broken_run),
924 : : TEST_CASE_ST(unaligned_test_setup, reset_unaligned, test_find_unaligned),
925 : : TEST_CASE_ST(full_unaligned_test_setup, reset_unaligned, test_find_unaligned),
926 : : TEST_CASES_END()
927 : : }
928 : : };
929 : :
930 : : static int
931 : 1 : test_fbarray(void)
932 : : {
933 : 1 : return unit_test_suite_runner(&fbarray_test_suite);
934 : : }
935 : :
936 : 254 : REGISTER_FAST_TEST(fbarray_autotest, true, true, test_fbarray);
|