From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0E8042EA8; Tue, 18 Jul 2023 15:54:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1056140A84; Tue, 18 Jul 2023 15:54:32 +0200 (CEST) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 9E33642D48 for ; Tue, 18 Jul 2023 15:54:26 +0200 (CEST) Received: from dggpeml100024.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4R50lL46sQzVjjH; Tue, 18 Jul 2023 21:53:02 +0800 (CST) Received: from localhost.localdomain (10.50.163.32) by dggpeml100024.china.huawei.com (7.185.36.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 18 Jul 2023 21:54:24 +0800 From: Chengwen Feng To: , CC: , , , , , , Subject: [PATCH v18 2/6] test/memarea: support memarea test Date: Tue, 18 Jul 2023 13:46:06 +0000 Message-ID: <20230718134610.32836-3-fengchengwen@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230718134610.32836-1-fengchengwen@huawei.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20230718134610.32836-1-fengchengwen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.163.32] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpeml100024.china.huawei.com (7.185.36.115) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This patch supports memarea test of rte_memarea_create() and rte_memarea_destroy() API. Signed-off-by: Chengwen Feng Reviewed-by: Dongdong Liu Acked-by: Morten Brørup Acked-by: Anatoly Burakov --- MAINTAINERS | 1 + app/test/meson.build | 2 + app/test/test_memarea.c | 139 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 app/test/test_memarea.c diff --git a/MAINTAINERS b/MAINTAINERS index 9ca665219b..b9b9ed2932 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1617,6 +1617,7 @@ Memarea - EXPERIMENTAL M: Chengwen Feng F: lib/memarea F: doc/guides/prog_guide/memarea_lib.rst +F: app/test/test_memarea* Membership - EXPERIMENTAL M: Yipeng Wang diff --git a/app/test/meson.build b/app/test/meson.build index b89cf0368f..0d9701d8c6 100644 --- a/app/test/meson.build +++ b/app/test/meson.build @@ -83,6 +83,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', @@ -201,6 +202,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..a2191eb0eb --- /dev/null +++ b/app/test/test_memarea.c @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2023 HiSilicon Limited + */ + +#include +#include + +#include +#include +#include + +#include "test.h" + +#define MEMAREA_TEST_DEFAULT_SIZE 0x1000 + +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); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for invalid name */ + memset(&init, 0, sizeof(init)); + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + memset(&init.name, 1, sizeof(init.name)); + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for invalid source */ + test_memarea_init_param(&init); + init.source = RTE_MEMAREA_SOURCE_MEMAREA + 1; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for total_sz */ + test_memarea_init_param(&init); + init.total_sz = 0; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for memarea NULL */ + test_memarea_init_param(&init); + init.source = RTE_MEMAREA_SOURCE_MEMAREA; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for algorithm invalid */ + test_memarea_init_param(&init); + init.alg = RTE_MEMAREA_ALGORITHM_NEXTFIT + 1; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + /* test for reserved field */ + test_memarea_init_param(&init); + init.reserved_bits = 1; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + test_memarea_init_param(&init); + init.reserved_64s[0] = 1; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + test_memarea_init_param(&init); + init.reserved_64s[1] = 1; + ma = rte_memarea_create(&init); + TEST_ASSERT(ma == NULL, "Expected NULL"); + TEST_ASSERT(rte_errno == EINVAL, "Expected EINVAL"); + + return TEST_SUCCESS; +} + +static int +test_memarea_create_destroy(void) +{ + struct rte_memarea *ma; + struct rte_memarea_param init; + + rte_errno = 0; + + /* test for create with HEAP */ + test_memarea_init_param(&init); + init.source = RTE_MEMAREA_SOURCE_HEAP; + init.heap.socket_id = SOCKET_ID_ANY; + ma = rte_memarea_create(&init); + 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); + TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + rte_memarea_destroy(ma); + + return TEST_SUCCESS; +} + +static struct unit_test_suite memarea_test_suite = { + .suite_name = "Memarea Unit Test Suite", + .setup = NULL, + .teardown = NULL, + .unit_test_cases = { + TEST_CASE(test_memarea_create_bad_param), + TEST_CASE(test_memarea_create_destroy), + + TEST_CASES_END() /**< NULL terminate unit test array */ + } +}; + +static int +test_memarea(void) +{ + return unit_test_suite_runner(&memarea_test_suite); +} + +REGISTER_TEST_COMMAND(memarea_autotest, test_memarea); -- 2.17.1