LCOV - code coverage report
Current view: top level - app/test - test_fbarray.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 308 314 98.1 %
Date: 2025-01-02 22:41:34 Functions: 29 29 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 240 444 54.1 %

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

Generated by: LCOV version 1.14