@@ -21,23 +21,41 @@ struct fbarray_testsuite_params {
};
static struct fbarray_testsuite_params param;
+static struct fbarray_testsuite_params unaligned;
#define FBARRAY_TEST_ARR_NAME "fbarray_autotest"
#define FBARRAY_TEST_LEN 256
+#define FBARRAY_UNALIGNED_TEST_ARR_NAME "fbarray_unaligned_autotest"
+#define FBARRAY_UNALIGNED_TEST_LEN 60
#define FBARRAY_TEST_ELT_SZ (sizeof(int))
static int autotest_setup(void)
{
- return rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME,
+ int ret;
+
+ ret = rte_fbarray_init(¶m.arr, FBARRAY_TEST_ARR_NAME,
FBARRAY_TEST_LEN, FBARRAY_TEST_ELT_SZ);
+ if (ret) {
+ printf("Failed to initialize test array\n");
+ return -1;
+ }
+ ret = rte_fbarray_init(&unaligned.arr, FBARRAY_UNALIGNED_TEST_ARR_NAME,
+ FBARRAY_UNALIGNED_TEST_LEN, FBARRAY_TEST_ELT_SZ);
+ if (ret) {
+ printf("Failed to initialize unaligned test array\n");
+ rte_fbarray_destroy(¶m.arr);
+ return -1;
+ }
+ return 0;
}
static void autotest_teardown(void)
{
rte_fbarray_destroy(¶m.arr);
+ rte_fbarray_destroy(&unaligned.arr);
}
-static int init_array(void)
+static int init_aligned(void)
{
int i;
for (i = param.start; i <= param.end; i++) {
@@ -47,11 +65,35 @@ static int init_array(void)
return 0;
}
-static void reset_array(void)
+static int init_unaligned(void)
+{
+ int i;
+ for (i = unaligned.start; i <= unaligned.end; i++) {
+ if (rte_fbarray_set_used(&unaligned.arr, i))
+ return -1;
+ }
+ return 0;
+}
+
+static void reset_aligned(void)
{
int i;
for (i = 0; i < FBARRAY_TEST_LEN; i++)
rte_fbarray_set_free(¶m.arr, i);
+ /* reset param as well */
+ param.start = -1;
+ param.end = -1;
+}
+
+static void reset_unaligned(void)
+{
+ int i;
+ for (i = 0; i < FBARRAY_UNALIGNED_TEST_LEN; i++)
+ rte_fbarray_set_free(&unaligned.arr, i);
+ /* reset param as well */
+ unaligned.start = -1;
+ unaligned.end = -1;
+
}
static int first_msk_test_setup(void)
@@ -59,7 +101,7 @@ static int first_msk_test_setup(void)
/* put all within first mask */
param.start = 3;
param.end = 10;
- return init_array();
+ return init_aligned();
}
static int cross_msk_test_setup(void)
@@ -67,7 +109,7 @@ static int cross_msk_test_setup(void)
/* put all within second and third mask */
param.start = 70;
param.end = 160;
- return init_array();
+ return init_aligned();
}
static int multi_msk_test_setup(void)
@@ -75,7 +117,7 @@ static int multi_msk_test_setup(void)
/* put all within first and last mask */
param.start = 3;
param.end = FBARRAY_TEST_LEN - 20;
- return init_array();
+ return init_aligned();
}
static int last_msk_test_setup(void)
@@ -83,7 +125,7 @@ static int last_msk_test_setup(void)
/* put all within last mask */
param.start = FBARRAY_TEST_LEN - 20;
param.end = FBARRAY_TEST_LEN - 1;
- return init_array();
+ return init_aligned();
}
static int full_msk_test_setup(void)
@@ -91,16 +133,7 @@ static int full_msk_test_setup(void)
/* fill entire mask */
param.start = 0;
param.end = FBARRAY_TEST_LEN - 1;
- return init_array();
-}
-
-static int empty_msk_test_setup(void)
-{
- /* do not fill anything in */
- reset_array();
- param.start = -1;
- param.end = -1;
- return 0;
+ return init_aligned();
}
static int lookahead_test_setup(void)
@@ -108,7 +141,7 @@ static int lookahead_test_setup(void)
/* set index 64 as used */
param.start = 64;
param.end = 64;
- return init_array();
+ return init_aligned();
}
static int lookbehind_test_setup(void)
@@ -116,7 +149,15 @@ static int lookbehind_test_setup(void)
/* set index 63 as used */
param.start = 63;
param.end = 63;
- return init_array();
+ return init_aligned();
+}
+
+static int unaligned_test_setup(void)
+{
+ unaligned.start = 0;
+ /* leave one free bit at the end */
+ unaligned.end = FBARRAY_UNALIGNED_TEST_LEN - 2;
+ return init_unaligned();
}
static int test_invalid(void)
@@ -470,7 +511,7 @@ static int test_basic(void)
if (check_free())
return TEST_FAILED;
- reset_array();
+ reset_aligned();
return TEST_SUCCESS;
}
@@ -713,6 +754,26 @@ static int test_find(void)
return TEST_SUCCESS;
}
+static int test_find_unaligned(void)
+{
+ TEST_ASSERT_EQUAL((int)unaligned.arr.count, unaligned.end - unaligned.start + 1,
+ "Wrong element count\n");
+ /* ensure space is free before start */
+ if (ensure_correct(&unaligned.arr, 0, unaligned.start - 1, false))
+ return TEST_FAILED;
+ /* ensure space is occupied where it's supposed to be */
+ if (ensure_correct(&unaligned.arr, unaligned.start, unaligned.end, true))
+ return TEST_FAILED;
+ /* ensure space after end is free as well */
+ if (ensure_correct(&unaligned.arr, unaligned.end + 1, FBARRAY_UNALIGNED_TEST_LEN - 1,
+ false))
+ return TEST_FAILED;
+ /* test if find_biggest API's work correctly */
+ if (test_biggest(&unaligned.arr, unaligned.start, unaligned.end))
+ return TEST_FAILED;
+ return TEST_SUCCESS;
+}
+
static int test_empty(void)
{
TEST_ASSERT_EQUAL((int)param.arr.count, 0, "Wrong element count\n");
@@ -814,17 +875,19 @@ static struct unit_test_suite fbarray_test_suite = {
.unit_test_cases = {
TEST_CASE(test_invalid),
TEST_CASE(test_basic),
- TEST_CASE_ST(first_msk_test_setup, reset_array, test_find),
- TEST_CASE_ST(cross_msk_test_setup, reset_array, test_find),
- TEST_CASE_ST(multi_msk_test_setup, reset_array, test_find),
- TEST_CASE_ST(last_msk_test_setup, reset_array, test_find),
- TEST_CASE_ST(full_msk_test_setup, reset_array, test_find),
- TEST_CASE_ST(empty_msk_test_setup, reset_array, test_empty),
- TEST_CASE_ST(lookahead_test_setup, reset_array, test_lookahead),
- TEST_CASE_ST(lookbehind_test_setup, reset_array, test_lookbehind),
+ TEST_CASE_ST(first_msk_test_setup, reset_aligned, test_find),
+ TEST_CASE_ST(cross_msk_test_setup, reset_aligned, test_find),
+ TEST_CASE_ST(multi_msk_test_setup, reset_aligned, test_find),
+ TEST_CASE_ST(last_msk_test_setup, reset_aligned, test_find),
+ TEST_CASE_ST(full_msk_test_setup, reset_aligned, test_find),
+ /* empty test does not need setup */
+ TEST_CASE_ST(NULL, reset_aligned, test_empty),
+ TEST_CASE_ST(lookahead_test_setup, reset_aligned, test_lookahead),
+ TEST_CASE_ST(lookbehind_test_setup, reset_aligned, test_lookbehind),
/* setup for these tests is more complex so do it in test func */
- TEST_CASE_ST(NULL, reset_array, test_lookahead_mask),
- TEST_CASE_ST(NULL, reset_array, test_lookbehind_mask),
+ TEST_CASE_ST(NULL, reset_aligned, test_lookahead_mask),
+ TEST_CASE_ST(NULL, reset_aligned, test_lookbehind_mask),
+ TEST_CASE_ST(unaligned_test_setup, reset_unaligned, test_find_unaligned),
TEST_CASES_END()
}
};
@@ -173,7 +173,7 @@ find_next_n(const struct rte_fbarray *arr, unsigned int start, unsigned int n,
/* combine current ignore mask with last index ignore mask */
if (msk_idx == last)
- ignore_msk |= last_msk;
+ ignore_msk &= last_msk;
/* if we have an ignore mask, ignore once */
if (ignore_msk) {