[PATCH] Memory Allocation: Adding a new UT for fb_array

Vipin P R vipinp at vmware.com
Fri Jan 13 14:12:47 CET 2023


add test case coverage to cover the ms_idx jump

Cc: stable at dpdk.org

Signed-off-by: Vipin P R <vipinp at vmware.com>
Acked-by: Kumara Parameshwaran <kparameshwar at vmware.com>
---
Depends-on: 0001-Memory-Allocation-Fixes-ms_idx-jump-lookahead-during.patch
Depends-on: 0002-Memory-Allocation-Fixes-ms_idx-jump-lookbehind-durin.patch
---
 app/test/test_fbarray.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/app/test/test_fbarray.c b/app/test/test_fbarray.c
index a691bf4..275449c 100644
--- a/app/test/test_fbarray.c
+++ b/app/test/test_fbarray.c
@@ -11,6 +11,7 @@
 #include <rte_debug.h>
 #include <rte_errno.h>
 #include <rte_fbarray.h>
+#include <rte_memory.h>
 
 #include "test.h"
 
@@ -402,6 +403,53 @@ static int check_used_one(void)
 	return 0;
 }
 
+/* the following test case verifies that the jump in ms_idx for an fb-array is correct. */
+static int test_jump(void)
+{
+    struct rte_fbarray test_array;
+    int input[] = {1, 1070, 1, 2, 1, 2, 4, 12, 2, 2, 1, 2, 1};
+    int ms_idx, prev_ms_idx, delta;
+    int len;
+    ms_idx = prev_ms_idx = 0;
+
+    int ret = rte_fbarray_init(&test_array, "test", 32768, sizeof(struct rte_memseg));
+    if (ret == 0) {
+        RTE_LOG(DEBUG, EAL, "FB array init success\n");
+        int k = 0;
+        for(int i=0; i < sizeof(input)/sizeof(int); i++) {
+            if (i == 0) {
+                len = input[i];
+            } else {
+                len = input[i] + 1;
+            }
+            prev_ms_idx = ms_idx;
+            ms_idx = rte_fbarray_find_next_n_free(&test_array, k, len);
+
+            if (i != 0) {
+                ms_idx++;
+            }
+
+            for (int j=0; j < input[i]; j++) {
+                RTE_LOG(DEBUG, EAL, "ms_idx:%d\n", ms_idx);
+                rte_fbarray_set_used(&test_array, ms_idx);
+                ms_idx++;
+            }
+
+            if (prev_ms_idx) {
+                /* The value of ms_idx should be monotonically increasing
+                 * given the above input sequence in test_array.
+                 * */
+                delta = ms_idx - prev_ms_idx;
+                if (!(delta > 0)) {
+                    RTE_LOG(ERR, EAL, "ms_idx jumping behind. ms_idx: %d prev_ms_idx: %d\n", ms_idx - 1, prev_ms_idx - 1);
+                    TEST_ASSERT(0, "Incorrect ms_idx jump");
+                }
+            }
+        }
+    }
+    return 0;
+}
+
 static int test_basic(void)
 {
 	const int idx = 0;
@@ -717,6 +765,7 @@ static struct unit_test_suite fbarray_test_suite = {
 	.unit_test_cases = {
 		TEST_CASE(test_invalid),
 		TEST_CASE(test_basic),
+		TEST_CASE(test_jump),
 		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),
-- 
2.7.4



More information about the dev mailing list