diff mbox series

[v5,08/10] test/memarea: support backup memory test

Message ID tencent_3C73DE72C7D749A098FE79D9EBDBD9CD9F07@qq.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers show
Series [v5,01/10] memarea: introduce memarea library | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

datshan Oct. 5, 2022, 4:09 a.m. UTC
From: Chengwen Feng <fengchengwen@huawei.com>

This patch supports backup memory mechanism test.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
---
 app/test/test_memarea.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
diff mbox series

Patch

diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c
index ab360f0265..ec3475c354 100644
--- a/app/test/test_memarea.c
+++ b/app/test/test_memarea.c
@@ -313,6 +313,46 @@  test_memarea_dump(void)
 	return 0;
 }
 
+static int
+test_memarea_backup(void)
+{
+	struct rte_memarea *ma, *bak_ma;
+	struct rte_memarea_param init;
+	void *ptr;
+
+	/* prepare env */
+	test_memarea_init_def_param(&init);
+	strcat(init.name, "_backup");
+	init.source = RTE_MEMAREA_SOURCE_SYSTEM_API;
+	init.total_sz = MEMAREA_TEST_DEFAULT_SIZE;
+	bak_ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(bak_ma != NULL, "Expected Non-NULL");
+	test_memarea_init_def_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_SYSTEM_API;
+	init.total_sz = MEMAREA_TEST_DEFAULT_SIZE >> 2;
+	init.bak_memarea = bak_ma;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL");
+
+	/* test for backup */
+	ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 3, 0);
+	RTE_TEST_ASSERT(ptr != NULL, "Expected Non-NULL");
+	ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0);
+	RTE_TEST_ASSERT(ptr != NULL, "Expected Non-NULL");
+	(void)rte_memarea_dump(ma, stderr, true);
+	(void)rte_memarea_dump(bak_ma, stderr, true);
+	rte_memarea_free(ma, ptr);
+	ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE, 0);
+	RTE_TEST_ASSERT(ptr == NULL, "Expected NULL");
+	(void)rte_memarea_dump(ma, stderr, true);
+	(void)rte_memarea_dump(bak_ma, stderr, true);
+
+	rte_memarea_destroy(ma);
+	rte_memarea_destroy(bak_ma);
+
+	return 0;
+}
+
 static int
 test_memarea(void)
 {
@@ -322,6 +362,7 @@  test_memarea(void)
 	MEMAREA_TEST_API_RUN(test_memarea_free_fail);
 	MEMAREA_TEST_API_RUN(test_memarea_alloc_free);
 	MEMAREA_TEST_API_RUN(test_memarea_dump);
+	MEMAREA_TEST_API_RUN(test_memarea_backup);
 	return 0;
 }