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 70161A0542; Wed, 5 Oct 2022 06:10:31 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9EF7342B70; Wed, 5 Oct 2022 06:10:06 +0200 (CEST) Received: from out203-205-221-190.mail.qq.com (out203-205-221-190.mail.qq.com [203.205.221.190]) by mails.dpdk.org (Postfix) with ESMTP id A8E1542905 for ; Wed, 5 Oct 2022 06:10:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1664943001; bh=C8qTE6hkJgFvCGayb+54fGaSBAsMap4/fPWQb5SN1Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=KT7K9g8CBs3QKjUajpEVllHWpXDjmDvF7KEiAj8Dj3xhO2gEhFERxYcLt+uHoEVYl JQAA1U3T8FzOAkwJQCEnQIgf95I+PzBjSvslSSpoDUfRU84k3XPBE7knyJVZ3YzGJF ebGaKfaEOIHTIzM3Us8TtUF0nV19BXE8sqmg2Wg8= 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: xmsmtpt1664942999t7or9jqb2 Message-ID: X-QQ-XMAILINFO: NY3HYYTs4gYS90mIxv7t3HlAoAg1MXwa130exnqUpbh/tb8IJbRqcmup0UsBCG 2vO9DtemQEJdr2SLXHnbKgi3sInrBP5a0kJaJfHrjYMkUQvj39ZsPKhBw3h3YDPPqdNqpsraFfj5 muCtq+KstfnmKkRSUEHMIgqrIyWw5B0Loa7M8tQFtnQ1TPkhaYB40wbObj66KLmcwQSAJldXrigK L6SS3EvhFXHA1ylGVNlNQ1k67djbs37sFDzmVaxDdHg7L3cmscmtdRaUCS6s4YR22JVjLUyLW1Y1 sAhClnJW35LQZXiAjfSIIjXAq9yG/yN1RyEdHVsluxm3/DihuO9xSg38H7A4PW9zI8m/DcA7FpIZ nAJlaCupH/FR1sEhseORMekFkAzXx9WxCAilA+KJuh7oHMkjDsEWKhZiHuJa2rkHmlTqku8oRcLK I0rSDcJUxlPENUXatsY/ScpCntwd+y4PexQluXdFVaQ6nDwtg6ZCwST3hk8nb9zuBzAMkybNKuki UxqPDlYStMrg2NvaxbDgGF2f+UFLSRKJpaVnH1qDTbBtqHAG4dJEwSA79uqYQUlNYl5JEcK3apqL onon6OVQvf58aYF4Uvk1Qs81bzP49kMiujPORbM/4yS0gvNbt9857Spaa/jMFQPYEeszTdpv2gta em4n3UouZjNUzaurIm1v52zFumYYQ/AUG1uGMlhLqpUmTR22Gmp5nnZCPg8cKtHKQUfWDkUvMlRJ wdw220otf9dPK5a4S6rJ13qIHuVde2Q/jPlfGpFw1vAIkMji4J0zXPTqViN20XFrF9N7yQFQOvhq xWPPO+/kRb9C7uMtwRcDqA57NyWMq3OBF6VTiZqpfOK0GodH7IrtE8TQubO5+x/y2uMNNoyziot2 OpFjw9lBK6uPxFuu4TlUtpQGQRDl89hTGfaQIihbf2rF4Zn7M/xVNmbXOQw0uxdOePYP6yKOKO// PAW72ao0nx1PMsLVPTcG/O2x0Nv42nRUbLdcJSi7oJp1DzokaKznw4VdZvWWXeEx2zOsVI8xZG5Y TZMlfhDw== 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 04/10] test/memarea: support alloc/free/update-refcnt test Date: Wed, 5 Oct 2022 12:09:46 +0800 X-OQ-MSGID: <20221005040952.8166-5-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 rte_memarea_alloc()/rte_memarea_free()/ rte_memarea_update_refcnt() test. Signed-off-by: Chengwen Feng --- app/test/test_memarea.c | 150 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 1 deletion(-) diff --git a/app/test/test_memarea.c b/app/test/test_memarea.c index 7c3d78652d..0a54ede4c1 100644 --- a/app/test/test_memarea.c +++ b/app/test/test_memarea.c @@ -41,6 +41,12 @@ test_memarea_init_def_param(struct rte_memarea_param *init) init->mt_safe = 1; } +static void +test_memarea_fill_allocated_region(void *ptr, size_t size) +{ + memset(ptr, 0xff, size); +} + static int test_memarea_create_bad_param(void) { @@ -106,8 +112,8 @@ static int test_memarea_create_destroy(void) { uint8_t user_buffer[MEMAREA_TEST_DEFAULT_SIZE + RTE_CACHE_LINE_SIZE]; + struct rte_memarea *ma, *user_ma; struct rte_memarea_param init; - struct rte_memarea *ma; /* test for create with RTE memory */ test_memarea_init_def_param(&init); @@ -133,6 +139,145 @@ test_memarea_create_destroy(void) RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); rte_memarea_destroy(ma); + /* test for create with user-memarea */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_SYSTEM_API; + user_ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(user_ma != NULL, "Expected Non-NULL"); + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_USER_MEMAREA; + init.total_sz = init.total_sz >> 1; + init.user_memarea = user_ma; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + rte_memarea_destroy(ma); + rte_memarea_destroy(user_ma); + + return 0; +} + +static int +test_memarea_alloc_fail(void) +{ + struct rte_memarea_param init; + struct rte_memarea *ma; + void *ptr[2]; + + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_SYSTEM_API; + init.total_sz = MEMAREA_TEST_DEFAULT_SIZE; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + + /* test alloc fail with big size */ + ptr[0] = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE, 0); + RTE_TEST_ASSERT(ptr[0] == NULL, "Expected NULL"); + + /* test alloc fail because no memory */ + ptr[0] = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE - RTE_CACHE_LINE_SIZE, 0); + RTE_TEST_ASSERT(ptr[0] != NULL, "Expected Non-NULL"); + ptr[1] = rte_memarea_alloc(ma, 1, 0); + RTE_TEST_ASSERT(ptr[1] == NULL, "Expected NULL"); + rte_memarea_free(ma, ptr[0]); + + /* test alloc fail when second fail */ + ptr[0] = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr[0] != NULL, "Expected Non-NULL"); + test_memarea_fill_allocated_region(ptr[0], MEMAREA_TEST_DEFAULT_SIZE >> 1); + ptr[1] = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr[1] == NULL, "Expected NULL"); + rte_memarea_free(ma, ptr[0]); + ptr[1] = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr[1] != NULL, "Expected Non-NULL"); + test_memarea_fill_allocated_region(ptr[1], MEMAREA_TEST_DEFAULT_SIZE >> 1); + rte_memarea_free(ma, ptr[1]); + + rte_memarea_destroy(ma); + + return 0; +} + +static int +test_memarea_free_fail(void) +{ + struct rte_memarea_param init; + struct rte_memarea *ma; + void *ptr; + + /* prepare env */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_SYSTEM_API; + init.total_sz = MEMAREA_TEST_DEFAULT_SIZE; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + + /* test invalid parameters with update-refcnt */ + rte_memarea_update_refcnt(NULL, (void *)(uintptr_t)1, 0); + rte_memarea_update_refcnt(ma, NULL, 0); + rte_memarea_update_refcnt(NULL, NULL, 0); + + /* test free with refcnt fail */ + ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr != NULL, "Expected Non-NULL"); + test_memarea_fill_allocated_region(ptr, MEMAREA_TEST_DEFAULT_SIZE >> 1); + rte_memarea_free(ma, ptr); + rte_memarea_free(ma, ptr); + + /* test update refcnt with fail */ + ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr != NULL, "Expected Non-NULL"); + test_memarea_fill_allocated_region(ptr, MEMAREA_TEST_DEFAULT_SIZE >> 1); + rte_memarea_update_refcnt(ma, ptr, -2); + ptr = rte_memarea_alloc(ma, MEMAREA_TEST_DEFAULT_SIZE >> 1, 0); + RTE_TEST_ASSERT(ptr == NULL, "Expected NULL"); + + rte_memarea_destroy(ma); + + return 0; +} + +static int +test_memarea_alloc_free(void) +{ +#define ALLOC_MAX_NUM 8 + struct rte_memarea_param init; + struct rte_memarea *ma; + void *ptr[ALLOC_MAX_NUM]; + int i; + + /* prepare env */ + test_memarea_init_def_param(&init); + init.source = RTE_MEMAREA_SOURCE_SYSTEM_API; + init.total_sz = MEMAREA_TEST_DEFAULT_SIZE; + ma = rte_memarea_create(&init); + RTE_TEST_ASSERT(ma != NULL, "Expected Non-NULL"); + memset(ptr, 0, sizeof(ptr)); + + /* test random alloc and free */ + for (i = 0; i < ALLOC_MAX_NUM; i++) + ptr[i] = rte_memarea_alloc(ma, 1, 0); + + /* test merge left */ + rte_memarea_free(ma, ptr[0]); + rte_memarea_free(ma, ptr[1]); + + /* test merge right */ + rte_memarea_free(ma, ptr[7]); + rte_memarea_free(ma, ptr[6]); + + /* test merge left and right */ + rte_memarea_free(ma, ptr[3]); + rte_memarea_free(ma, ptr[2]); + + /* test merge remains */ + rte_memarea_free(ma, ptr[4]); + rte_memarea_free(ma, ptr[5]); + + /* test free NULL */ + rte_memarea_free(ma, ptr[6]); + + rte_memarea_destroy(ma); + return 0; } @@ -141,6 +286,9 @@ test_memarea(void) { MEMAREA_TEST_API_RUN(test_memarea_create_bad_param); MEMAREA_TEST_API_RUN(test_memarea_create_destroy); + MEMAREA_TEST_API_RUN(test_memarea_alloc_fail); + MEMAREA_TEST_API_RUN(test_memarea_free_fail); + MEMAREA_TEST_API_RUN(test_memarea_alloc_free); return 0; } -- 2.34.1