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 4212FA0542; Wed, 5 Oct 2022 06:10:13 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 55E08427EB; Wed, 5 Oct 2022 06:10:02 +0200 (CEST) Received: from out203-205-221-245.mail.qq.com (out203-205-221-245.mail.qq.com [203.205.221.245]) by mails.dpdk.org (Postfix) with ESMTP id 03EEF40041 for ; Wed, 5 Oct 2022 06:09:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1664942998; bh=rG2ZkGplRcelW1XLl2pfPrMLzFQd6n7/OgK5xTE5jeg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=gjaghcm4cUkIkakCWVVcm8UtSCbC4ysBPUH6/lVt+Q9gSugBV4uKCeLJeFvtw/PfB n3NWSxw/QhWvCMv5QPKv5RI61320IWZ0roUQ4sXo4iJ6VT5ohJbyZzdM0c/7U6qsJ/ w/c6bxJ67O1+krvWUxYkKBDtNGG2Q/+SnjvLwXhc= Received: from qq.com ([120.229.93.179]) by newxmesmtplogicsvrsza31.qq.com (NewEsmtp) with SMTP id 27598E97; Wed, 05 Oct 2022 12:09:53 +0800 X-QQ-mid: xmsmtpt1664942997t5p461miq Message-ID: X-QQ-XMAILINFO: Nkmip1FNTwAh2vQ3wRV0mnhEqwNYbzPx5G7LtHsOiavFMc81M0sm3DeKJGKxq7 DnCylKbKhClKzlwaXA4egJkAlTENxIVhQhCop50qoci4vWvuVaPWLUVV2b3GuvRTsMDwwaBoeHg0 e/xMgeG3n23x9fjf0fsUAcA9qXLOu9CzZf3N4BXjcsSDpDfVJFROE2UBrlHxG9s1V0vbQV6r+hz+ wYUPk16XFSnW6xMUe+ZC0+KtEczgccS13ALoJw0Hp+LLomg4oUGh+KCY3PFL5z5m6zjejufdPWje +C16zsgDOoRNtQdYRGUIuN3H2v00WWulIZEdaSBNt/ctfIvtqKc01aI7oQRmdTgCYhlV6LeloJ/S nc0DCIckBV7lt9Do4hGC0SyxT5PRp5CW7wpbsFEcbVT/IzxpkbQ0WrePhrD+VYNAnu2iMsWEk7wW pH7iWwX1BGm7RANk1r8k2/o+J+EV4YI/BOuCPIkTW9Oik7dYPHB7phHd+Mm2vFT3M7WNGm84TZBK gHvm8ZiXzxp9zfv7tJ3uTb4bq/lrQhj5GK64dmLXmazQ3AEpAGBMLGfqggknXh46nw88hulLonuh UCN8mTISNVYilzwCDIoxn9OWLlhEOUef5VcFOjThVpPBYJZUj0Z1mjkXpQQDbgHXn9kFnmhxzsqM DxWXSXWb+KDoxJsxXEB/RuSttQDkwzHhz5HKpSSseycbWK92ZWcRroVv3uYhnrOiPAXmC6FLinTM /b1DwV30y+iOsTNQhl7kQrkVq/Q6cn6zNTYWpKTt/LomSai2PYpu5Ur75EYpGY8kBlR2xEMfM9o5 FjOMpjVSaUcXbd8krSwk7MVllskOIY4FHhDmtRljCJ0tduICViRt9bbPjPRrPYiYm6v2Rz+ZHoaJ LNR8OLgPBrm1QaRhcxMAVZQMXAt4GgDWCC5CuG1cwStchOj4CDWgI4+DoeiY3wwQZ8zhk081tUTH dRjyhYLsITPl5Lh8hDK+dDbusqV3OUAC8DEJjPbn+ZrMVnLwd2++g1GCYV4h5j1blVpnNlXSzV0M AISwZPTP5pBprilCxS From: datshan To: david.marchand@redhat.com, mb@smartsharesystems.com, anatoly.burakov@intel.com, dmitry.kozliuk@gmail.com, jerinjacobk@gmail.com Cc: thomas@monjalon.net, dev@dpdk.org, Chengwen Feng Subject: [PATCH v5 02/10] test/memarea: support memarea test Date: Wed, 5 Oct 2022 12:09:44 +0800 X-OQ-MSGID: <20221005040952.8166-3-datshan@qq.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005040952.8166-1-datshan@qq.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20221005040952.8166-1-datshan@qq.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 From: Chengwen Feng This patch supports memarea test about API rte_memarea_create and rte_memarea_destroy. Signed-off-by: Chengwen Feng --- MAINTAINERS | 1 + app/test/meson.build | 2 + app/test/test_memarea.c | 149 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 152 insertions(+) create mode 100644 app/test/test_memarea.c diff --git a/MAINTAINERS b/MAINTAINERS index b9c638221d..bfdb36f1b5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1554,6 +1554,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 d5cad72116..778de8d65d 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', @@ -199,6 +200,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..7c3d78652d --- /dev/null +++ b/app/test/test_memarea.c @@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2022 HiSilicon Limited + */ + +#include +#include + +#include "test.h" + +#ifdef RTE_EXEC_ENV_WINDOWS +static int +test_memarea(void) +{ + printf("memarea not supported on Windows, skipping test\n"); + return TEST_SKIPPED; +} + +#else + +#include +#include + +#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); \ + else \ + printf("%s Passed\n", #test_func); \ + } while (0) + +static void +test_memarea_init_def_param(struct rte_memarea_param *init) +{ + memset(init, 0, sizeof(struct rte_memarea_param)); + sprintf(init->name, "%s", "test-memarea"); + init->source = RTE_MEMAREA_SOURCE_SYSTEM_API; + 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; + int i; + + /* 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_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_MEMAREA + 1; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + + /* test for total_sz */ + test_memarea_init_def_param(&init); + init.total_sz = 0; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + + /* test for user address NULL */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_ADDR; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + + /* test for user address align invalid */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_ADDR; + for (i = 1; i < RTE_CACHE_LINE_SIZE; i++) { + init.user_addr = (void *)((uintptr_t)i); + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + } + + /* test for user memarea NULL */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_MEMAREA; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + + /* test for alg invalid */ + test_memarea_init_def_param(&init); + init.alg = RTE_MEMAREA_ALG_DEFAULT + 1; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma == NULL, "Expected NULL"); + + return 0; +} + +static int +test_memarea_create_destroy(void) +{ + uint8_t user_buffer[MEMAREA_TEST_DEFAULT_SIZE + RTE_CACHE_LINE_SIZE]; + struct rte_memarea_param init; + struct rte_memarea *ma; + + /* test for create with RTE memory */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_RTE_MEMORY; + 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 system API */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_SYSTEM_API; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + rte_memarea_destroy(ma); + + /* test for create with user-address */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_ADDR; + init.user_addr = (void *)(((uintptr_t)user_buffer + RTE_CACHE_LINE_SIZE) & + ~(RTE_CACHE_LINE_SIZE - 1)); + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + rte_memarea_destroy(ma); + + return 0; +} + +static int +test_memarea(void) +{ + MEMAREA_TEST_API_RUN(test_memarea_create_bad_param); + MEMAREA_TEST_API_RUN(test_memarea_create_destroy); + return 0; +} + +#endif /* !RTE_EXEC_ENV_WINDOWS */ + +REGISTER_TEST_COMMAND(memarea_autotest, test_memarea); -- 2.34.1