1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include <rte_common.h>
10 #include <rte_debug.h>
11 #include <rte_errno.h>
12 #include <rte_fbarray.h>
16 struct fbarray_testsuite_params {
17 struct rte_fbarray arr;
22 static struct fbarray_testsuite_params param;
24 #define FBARRAY_TEST_ARR_NAME "fbarray_autotest"
25 #define FBARRAY_TEST_LEN 256
26 #define FBARRAY_TEST_ELT_SZ (sizeof(int))
28 static int autotest_setup(void)
30 return rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME,
31 FBARRAY_TEST_LEN, FBARRAY_TEST_ELT_SZ);
34 static void autotest_teardown(void)
36 rte_fbarray_destroy(¶m.arr);
39 static int init_array(void)
42 for (i = param.start; i <= param.end; i++) {
43 if (rte_fbarray_set_used(¶m.arr, i))
49 static void reset_array(void)
52 for (i = 0; i < FBARRAY_TEST_LEN; i++)
53 rte_fbarray_set_free(¶m.arr, i);
56 static int first_msk_test_setup(void)
58 /* put all within first mask */
64 static int cross_msk_test_setup(void)
66 /* put all within second and third mask */
72 static int multi_msk_test_setup(void)
74 /* put all within first and last mask */
76 param.end = FBARRAY_TEST_LEN - 20;
80 static int last_msk_test_setup(void)
82 /* put all within last mask */
83 param.start = FBARRAY_TEST_LEN - 20;
84 param.end = FBARRAY_TEST_LEN - 1;
88 static int full_msk_test_setup(void)
90 /* fill entire mask */
92 param.end = FBARRAY_TEST_LEN - 1;
96 static int empty_msk_test_setup(void)
98 /* do not fill anything in */
103 static int test_invalid(void)
105 struct rte_fbarray dummy;
107 /* invalid parameters */
108 TEST_ASSERT_FAIL(rte_fbarray_attach(NULL),
109 "Call succeeded with invalid parameters\n");
110 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
111 TEST_ASSERT_FAIL(rte_fbarray_detach(NULL),
112 "Call succeeded with invalid parameters\n");
113 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
115 TEST_ASSERT_FAIL(rte_fbarray_destroy(NULL),
116 "Call succeeded with invalid parameters\n");
117 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno valuey\n");
118 TEST_ASSERT_FAIL(rte_fbarray_init(NULL, "fail", 16, 16),
119 "Call succeeded with invalid parameters\n");
120 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
121 TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, NULL, 16, 16),
122 "Call succeeded with invalid parameters\n");
123 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
124 TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", 0, 16),
125 "Call succeeded with invalid parameters\n");
126 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
127 TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", 16, 0),
128 "Call succeeded with invalid parameters\n");
129 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
130 /* len must not be greater than INT_MAX */
131 TEST_ASSERT_FAIL(rte_fbarray_init(&dummy, "fail", INT_MAX + 1U, 16),
132 "Call succeeded with invalid parameters\n");
133 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
135 TEST_ASSERT_NULL(rte_fbarray_get(NULL, 0),
136 "Call succeeded with invalid parameters\n");
137 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
138 TEST_ASSERT(rte_fbarray_find_idx(NULL, 0) < 0,
139 "Call succeeded with invalid parameters\n");
140 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
141 TEST_ASSERT(rte_fbarray_set_free(NULL, 0),
142 "Call succeeded with invalid parameters\n");
143 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
144 TEST_ASSERT(rte_fbarray_set_used(NULL, 0),
145 "Call succeeded with invalid parameters\n");
146 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
147 TEST_ASSERT(rte_fbarray_find_contig_free(NULL, 0) < 0,
148 "Call succeeded with invalid parameters\n");
149 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
150 TEST_ASSERT(rte_fbarray_find_contig_used(NULL, 0) < 0,
151 "Call succeeded with invalid parameters\n");
152 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
153 TEST_ASSERT(rte_fbarray_find_rev_contig_free(NULL, 0) < 0,
154 "Call succeeded with invalid parameters\n");
155 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
156 TEST_ASSERT(rte_fbarray_find_rev_contig_used(NULL, 0) < 0,
157 "Call succeeded with invalid parameters\n");
158 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
159 TEST_ASSERT(rte_fbarray_find_next_free(NULL, 0) < 0,
160 "Call succeeded with invalid parameters\n");
161 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
162 TEST_ASSERT(rte_fbarray_find_next_used(NULL, 0) < 0,
163 "Call succeeded with invalid parameters\n");
164 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
165 TEST_ASSERT(rte_fbarray_find_prev_free(NULL, 0) < 0,
166 "Call succeeded with invalid parameters\n");
167 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
168 TEST_ASSERT(rte_fbarray_find_prev_used(NULL, 0) < 0,
169 "Call succeeded with invalid parameters\n");
170 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
171 TEST_ASSERT(rte_fbarray_find_next_n_free(NULL, 0, 0) < 0,
172 "Call succeeded with invalid parameters\n");
173 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
174 TEST_ASSERT(rte_fbarray_find_next_n_used(NULL, 0, 0) < 0,
175 "Call succeeded with invalid parameters\n");
176 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
177 TEST_ASSERT(rte_fbarray_find_prev_n_free(NULL, 0, 0) < 0,
178 "Call succeeded with invalid parameters\n");
179 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
180 TEST_ASSERT(rte_fbarray_find_prev_n_used(NULL, 0, 0) < 0,
181 "Call succeeded with invalid parameters\n");
182 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
183 TEST_ASSERT(rte_fbarray_is_used(NULL, 0) < 0,
184 "Call succeeded with invalid parameters\n");
185 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
187 TEST_ASSERT_SUCCESS(rte_fbarray_init(&dummy, "success",
188 FBARRAY_TEST_LEN, 8),
189 "Failed to initialize valid fbarray\n");
191 /* test API for handling invalid parameters with a valid fbarray */
192 TEST_ASSERT_NULL(rte_fbarray_get(&dummy, FBARRAY_TEST_LEN),
193 "Call succeeded with invalid parameters\n");
194 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
196 TEST_ASSERT(rte_fbarray_find_idx(&dummy, NULL) < 0,
197 "Call succeeded with invalid parameters\n");
198 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
200 TEST_ASSERT(rte_fbarray_set_free(&dummy, FBARRAY_TEST_LEN),
201 "Call succeeded with invalid parameters\n");
202 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
204 TEST_ASSERT(rte_fbarray_set_used(&dummy, FBARRAY_TEST_LEN),
205 "Call succeeded with invalid parameters\n");
206 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
208 TEST_ASSERT(rte_fbarray_find_contig_free(&dummy, FBARRAY_TEST_LEN) < 0,
209 "Call succeeded with invalid parameters\n");
210 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
212 TEST_ASSERT(rte_fbarray_find_contig_used(&dummy, FBARRAY_TEST_LEN) < 0,
213 "Call succeeded with invalid parameters\n");
214 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
216 TEST_ASSERT(rte_fbarray_find_rev_contig_free(&dummy,
217 FBARRAY_TEST_LEN) < 0,
218 "Call succeeded with invalid parameters\n");
219 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
221 TEST_ASSERT(rte_fbarray_find_rev_contig_used(&dummy,
222 FBARRAY_TEST_LEN) < 0,
223 "Call succeeded with invalid parameters\n");
224 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
226 TEST_ASSERT(rte_fbarray_find_next_free(&dummy, FBARRAY_TEST_LEN) < 0,
227 "Call succeeded with invalid parameters\n");
228 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
230 TEST_ASSERT(rte_fbarray_find_next_used(&dummy, FBARRAY_TEST_LEN) < 0,
231 "Call succeeded with invalid parameters\n");
232 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
234 TEST_ASSERT(rte_fbarray_find_prev_free(&dummy, FBARRAY_TEST_LEN) < 0,
235 "Call succeeded with invalid parameters\n");
236 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
238 TEST_ASSERT(rte_fbarray_find_prev_used(&dummy, FBARRAY_TEST_LEN) < 0,
239 "Call succeeded with invalid parameters\n");
240 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
242 TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy,
243 FBARRAY_TEST_LEN, 1) < 0,
244 "Call succeeded with invalid parameters\n");
245 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
246 TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy, 0,
247 FBARRAY_TEST_LEN + 1) < 0,
248 "Call succeeded with invalid parameters\n");
249 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
250 TEST_ASSERT(rte_fbarray_find_next_n_free(&dummy, 0, 0) < 0,
251 "Call succeeded with invalid parameters\n");
252 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
254 TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy,
255 FBARRAY_TEST_LEN, 1) < 0,
256 "Call succeeded with invalid parameters\n");
257 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
258 TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy, 0,
259 FBARRAY_TEST_LEN + 1) < 0,
260 "Call succeeded with invalid parameters\n");
261 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
262 TEST_ASSERT(rte_fbarray_find_next_n_used(&dummy, 0, 0) < 0,
263 "Call succeeded with invalid parameters\n");
264 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
266 TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy,
267 FBARRAY_TEST_LEN, 1) < 0,
268 "Call succeeded with invalid parameters\n");
269 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
270 TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy, 0,
271 FBARRAY_TEST_LEN + 1) < 0,
272 "Call succeeded with invalid parameters\n");
273 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
274 TEST_ASSERT(rte_fbarray_find_prev_n_free(&dummy, 0, 0) < 0,
275 "Call succeeded with invalid parameters\n");
276 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
278 TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy,
279 FBARRAY_TEST_LEN, 1) < 0,
280 "Call succeeded with invalid parameters\n");
281 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
282 TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy, 0,
283 FBARRAY_TEST_LEN + 1) < 0,
284 "Call succeeded with invalid parameters\n");
285 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
286 TEST_ASSERT(rte_fbarray_find_prev_n_used(&dummy, 0, 0) < 0,
287 "Call succeeded with invalid parameters\n");
288 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
290 TEST_ASSERT(rte_fbarray_is_used(&dummy, FBARRAY_TEST_LEN) < 0,
291 "Call succeeded with invalid parameters\n");
292 TEST_ASSERT_EQUAL(rte_errno, EINVAL, "Wrong errno value\n");
294 TEST_ASSERT_SUCCESS(rte_fbarray_destroy(&dummy),
295 "Failed to destroy valid fbarray\n");
300 static int check_free(void)
303 const int last_idx = FBARRAY_TEST_LEN - 1;
305 /* ensure we can find a free spot */
306 TEST_ASSERT_EQUAL(rte_fbarray_find_next_free(¶m.arr, idx), idx,
307 "Free space not found where expected\n");
308 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(¶m.arr, idx, 1), idx,
309 "Free space not found where expected\n");
310 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(¶m.arr, idx),
312 "Free space not found where expected\n");
314 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(¶m.arr, idx), idx,
315 "Free space not found where expected\n");
316 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, idx, 1), idx,
317 "Free space not found where expected\n");
318 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr, idx), 1,
319 "Free space not found where expected\n");
321 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(¶m.arr, last_idx),
322 last_idx, "Free space not found where expected\n");
323 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(¶m.arr, last_idx, 1),
324 last_idx, "Free space not found where expected\n");
325 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr,
326 last_idx), FBARRAY_TEST_LEN,
327 "Free space not found where expected\n");
329 /* ensure we can't find any used spots */
330 TEST_ASSERT(rte_fbarray_find_next_used(¶m.arr, idx) < 0,
331 "Used space found where none was expected\n");
332 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
333 TEST_ASSERT(rte_fbarray_find_next_n_used(¶m.arr, idx, 1) < 0,
334 "Used space found where none was expected\n");
335 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
336 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx), 0,
337 "Used space found where none was expected\n");
339 TEST_ASSERT(rte_fbarray_find_prev_used(¶m.arr, last_idx) < 0,
340 "Used space found where none was expected\n");
341 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
342 TEST_ASSERT(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1) < 0,
343 "Used space found where none was expected\n");
344 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
345 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
347 "Used space found where none was expected\n");
352 static int check_used_one(void)
355 const int last_idx = FBARRAY_TEST_LEN - 1;
357 /* check that we can find used spots now */
358 TEST_ASSERT_EQUAL(rte_fbarray_find_next_used(¶m.arr, idx), idx,
359 "Used space not found where expected\n");
360 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(¶m.arr, idx, 1), idx,
361 "Used space not found where expected\n");
362 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx), 1,
363 "Used space not found where expected\n");
365 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(¶m.arr, last_idx), idx,
366 "Used space not found where expected\n");
367 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1),
368 idx, "Used space not found where expected\n");
369 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr, idx), 1,
370 "Used space not found where expected\n");
371 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
373 "Used space not found where expected\n");
375 /* check if further indices are still free */
376 TEST_ASSERT(rte_fbarray_find_next_used(¶m.arr, idx + 1) < 0,
377 "Used space not found where none was expected\n");
378 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
379 TEST_ASSERT(rte_fbarray_find_next_n_used(¶m.arr, idx + 1, 1) < 0,
380 "Used space not found where none was expected\n");
381 TEST_ASSERT_EQUAL(rte_errno, ENOENT, "Wrong errno value\n");
382 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(¶m.arr, idx + 1), 0,
383 "Used space not found where none was expected\n");
384 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(¶m.arr, idx + 1),
385 FBARRAY_TEST_LEN - 1,
386 "Used space not found where none was expected\n");
388 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(¶m.arr, last_idx), 0,
389 "Used space not found where none was expected\n");
390 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(¶m.arr, last_idx, 1),
391 0, "Used space not found where none was expected\n");
392 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(¶m.arr,
394 "Used space not found where none was expected\n");
395 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(¶m.arr,
396 last_idx), FBARRAY_TEST_LEN - 1,
397 "Used space not found where none was expected\n");
402 static int test_basic(void)
407 /* check array count */
408 TEST_ASSERT_EQUAL(param.arr.count, 0, "Wrong element count\n");
410 /* ensure we can find a free spot */
415 TEST_ASSERT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
416 "Used space found where not expected\n");
419 TEST_ASSERT_SUCCESS(rte_fbarray_set_used(¶m.arr, idx),
420 "Failed to set as used\n");
422 /* check if used again */
423 TEST_ASSERT_NOT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
424 "Used space not found where expected\n");
426 if (check_used_one())
429 /* check array count */
430 TEST_ASSERT_EQUAL(param.arr.count, 1, "Wrong element count\n");
432 /* check if getting pointers works for every element */
433 for (i = 0; i < FBARRAY_TEST_LEN; i++) {
434 void *td = rte_fbarray_get(¶m.arr, i);
435 TEST_ASSERT_NOT_NULL(td, "Invalid pointer returned\n");
436 TEST_ASSERT_EQUAL(rte_fbarray_find_idx(¶m.arr, td), i,
437 "Wrong index returned\n");
441 TEST_ASSERT_SUCCESS(rte_fbarray_set_free(¶m.arr, idx),
442 "Failed to set as free\n");
444 /* check array count */
445 TEST_ASSERT_EQUAL(param.arr.count, 0, "Wrong element count\n");
448 TEST_ASSERT_EQUAL(rte_fbarray_is_used(¶m.arr, idx), 0,
449 "Used space found where not expected\n");
459 static int ensure_correct(struct rte_fbarray *arr, int first, int last,
462 int i, len = last - first + 1;
463 for (i = 0; i < len; i++) {
465 int cur_len = len - i;
468 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_used(arr,
470 "Used space length is wrong\n");
471 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(arr,
473 "Used space length is wrong\n");
474 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_used(arr,
476 "Used space length is wrong\n");
478 TEST_ASSERT_EQUAL(rte_fbarray_find_next_used(arr, cur),
480 "Used space not found where expected\n");
481 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(arr,
483 "Used space not found where expected\n");
484 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_used(arr, cur,
486 "Used space not found where expected\n");
488 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_used(arr, cur),
490 "Used space not found where expected\n");
491 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_used(arr,
493 "Used space not found where expected\n");
495 TEST_ASSERT_EQUAL(rte_fbarray_find_contig_free(arr,
497 "Free space length is wrong\n");
498 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
500 "Free space length is wrong\n");
501 TEST_ASSERT_EQUAL(rte_fbarray_find_rev_contig_free(arr,
503 "Free space length is wrong\n");
505 TEST_ASSERT_EQUAL(rte_fbarray_find_next_free(arr, cur),
507 "Free space not found where expected\n");
508 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(arr, cur,
510 "Free space not found where expected\n");
511 TEST_ASSERT_EQUAL(rte_fbarray_find_next_n_free(arr, cur,
513 "Free space not found where expected\n");
515 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_free(arr, cur),
517 "Free space not found where expected\n");
518 TEST_ASSERT_EQUAL(rte_fbarray_find_prev_n_free(arr,
520 "Free space not found where expected\n");
526 static int test_find(void)
528 TEST_ASSERT_EQUAL((int)param.arr.count, param.end - param.start + 1,
529 "Wrong element count\n");
530 /* ensure space is free before start */
531 if (ensure_correct(¶m.arr, 0, param.start - 1, false))
533 /* ensure space is occupied where it's supposed to be */
534 if (ensure_correct(¶m.arr, param.start, param.end, true))
536 /* ensure space after end is free as well */
537 if (ensure_correct(¶m.arr, param.end + 1, FBARRAY_TEST_LEN - 1,
543 static int test_empty(void)
545 TEST_ASSERT_EQUAL((int)param.arr.count, 0, "Wrong element count\n");
546 /* ensure space is free */
547 if (ensure_correct(¶m.arr, 0, FBARRAY_TEST_LEN - 1, false))
553 static struct unit_test_suite fbarray_test_suite = {
554 .suite_name = "fbarray autotest",
555 .setup = autotest_setup,
556 .teardown = autotest_teardown,
558 TEST_CASE(test_invalid),
559 TEST_CASE(test_basic),
560 TEST_CASE_ST(first_msk_test_setup, reset_array, test_find),
561 TEST_CASE_ST(cross_msk_test_setup, reset_array, test_find),
562 TEST_CASE_ST(multi_msk_test_setup, reset_array, test_find),
563 TEST_CASE_ST(last_msk_test_setup, reset_array, test_find),
564 TEST_CASE_ST(full_msk_test_setup, reset_array, test_find),
565 TEST_CASE_ST(empty_msk_test_setup, reset_array, test_empty),
573 return unit_test_suite_runner(&fbarray_test_suite);
576 REGISTER_TEST_COMMAND(fbarray_autotest, test_fbarray);