[v14,2/6] test/memarea: support memarea test

Message ID 20230209063610.35501-3-fengchengwen@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series introduce memarea library |

Checks

Context Check Description
ci/checkpatch warning coding style issues

Commit Message

fengchengwen Feb. 9, 2023, 6:36 a.m. UTC
  This patch supports memarea test of rte_memarea_create() and
rte_memarea_destroy() API.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 MAINTAINERS             |   1 +
 app/test/meson.build    |   2 +
 app/test/test_memarea.c | 130 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 app/test/test_memarea.c
  

Comments

Anatoly Burakov June 21, 2023, 11 a.m. UTC | #1
On 2/9/2023 6:36 AM, Chengwen Feng wrote:
> This patch supports memarea test of rte_memarea_create() and
> rte_memarea_destroy() API.
> 
> Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
> Reviewed-by: Dongdong Liu <liudongdong3@huawei.com>
> Acked-by: Morten Brørup <mb@smartsharesystems.com>
> ---

Hi,

> +
> +static int
> +test_memarea(void)
> +{
> +	test_memarea_prepare();
> +
> +	MEMAREA_TEST_API_RUN(test_memarea_create_bad_param);
> +	MEMAREA_TEST_API_RUN(test_memarea_create_destroy);

It looks a lot like you're reimplementing functionality that is already 
present in the test app, as we already have infrastructure to support 
test setup, teardown, and running different test suites (see e.g. 
fbarray or EAL flags tests for example). Is there any particular reason 
why you didn't go for this approach?
  

Patch

diff --git a/MAINTAINERS b/MAINTAINERS
index 60078ffc72..4bd47fb478 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1579,6 +1579,7 @@  Memarea - EXPERIMENTAL
 M: Chengwen Feng <fengchengwen@huawei.com>
 F: lib/memarea
 F: doc/guides/prog_guide/memarea_lib.rst
+F: app/test/test_memarea*
 
 Membership - EXPERIMENTAL
 M: Yipeng Wang <yipeng1.wang@intel.com>
diff --git a/app/test/meson.build b/app/test/meson.build
index f34d19e3c3..fde0155cf9 100644
--- a/app/test/meson.build
+++ b/app/test/meson.build
@@ -84,6 +84,7 @@  test_sources = files(
         'test_malloc.c',
         'test_malloc_perf.c',
         'test_mbuf.c',
+        'test_memarea.c',
         'test_member.c',
         'test_member_perf.c',
         'test_memcpy.c',
@@ -200,6 +201,7 @@  fast_tests = [
         ['malloc_autotest', false, true],
         ['mbuf_autotest', false, true],
         ['mcslock_autotest', false, true],
+        ['memarea_autotest', true, true],
         ['memcpy_autotest', true, true],
         ['memory_autotest', false, true],
         ['mempool_autotest', false, true],
diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c
new file mode 100644
index 0000000000..db5efc4c1b
--- /dev/null
+++ b/app/test/test_memarea.c
@@ -0,0 +1,130 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2023 HiSilicon Limited
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "test.h"
+
+#include <rte_memory.h>
+#include <rte_memarea.h>
+
+#define MEMAREA_TEST_DEFAULT_SIZE	0x1000
+
+#define MEMAREA_TEST_API_RUN(test_func) \
+	do { \
+		int ret = test_func(); \
+		if (ret < 0) { \
+			printf("%s Failed\n", #test_func); \
+			fails++; \
+		} else { \
+			printf("%s Passed\n", #test_func); \
+		} \
+	} while (0)
+
+static int fails;
+
+static void
+test_memarea_prepare(void)
+{
+	fails = 0;
+}
+
+static int
+test_memarea_retcode(void)
+{
+	return fails > 0 ? -1 : 0;
+}
+
+static void
+test_memarea_init_param(struct rte_memarea_param *init)
+{
+	memset(init, 0, sizeof(struct rte_memarea_param));
+	sprintf(init->name, "%s", "autotest");
+	init->source = RTE_MEMAREA_SOURCE_LIBC;
+	init->total_sz = MEMAREA_TEST_DEFAULT_SIZE;
+	init->mt_safe = 1;
+}
+
+static int
+test_memarea_create_bad_param(void)
+{
+	struct rte_memarea_param init;
+	struct rte_memarea *ma;
+
+	/* test for NULL */
+	ma = rte_memarea_create(NULL);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	/* test for invalid name */
+	memset(&init, 0, sizeof(init));
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+	memset(&init.name, 1, sizeof(init.name));
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	/* test for invalid source */
+	test_memarea_init_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_MEMAREA + 1;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	/* test for total_sz */
+	test_memarea_init_param(&init);
+	init.total_sz = 0;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	/* test for memarea NULL */
+	test_memarea_init_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_MEMAREA;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	/* test for algorithm invalid */
+	test_memarea_init_param(&init);
+	init.alg = RTE_MEMAREA_ALGORITHM_NEXTFIT + 1;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma == NULL, "Expected NULL");
+
+	return 0;
+}
+
+static int
+test_memarea_create_destroy(void)
+{
+	struct rte_memarea_param init;
+	struct rte_memarea *ma;
+
+	/* test for create with HEAP */
+	test_memarea_init_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_HEAP;
+	init.numa_socket = SOCKET_ID_ANY;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL");
+	rte_memarea_destroy(ma);
+
+	/* test for create with LIBC */
+	test_memarea_init_param(&init);
+	init.source = RTE_MEMAREA_SOURCE_LIBC;
+	ma = rte_memarea_create(&init);
+	RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL");
+	rte_memarea_destroy(ma);
+
+	return 0;
+}
+
+static int
+test_memarea(void)
+{
+	test_memarea_prepare();
+
+	MEMAREA_TEST_API_RUN(test_memarea_create_bad_param);
+	MEMAREA_TEST_API_RUN(test_memarea_create_destroy);
+
+	return test_memarea_retcode();
+}
+
+REGISTER_TEST_COMMAND(memarea_autotest, test_memarea);