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 5860EA0542; Wed, 5 Oct 2022 05:39:50 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC99A42B82; Wed, 5 Oct 2022 05:39:12 +0200 (CEST) Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by mails.dpdk.org (Postfix) with ESMTP id BDF2440A7D for ; Wed, 5 Oct 2022 05:39:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s201512; t=1664941140; bh=C8qTE6hkJgFvCGayb+54fGaSBAsMap4/fPWQb5SN1Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CgLD/5JgFTr2k61HeygpUfLM2y2JCT0GBGn1ySR5M96D0T3g8piBbJoINrFvE9dYH 9QRU14TEmzszvhRpS2OfLa0X246v9vhufxo+14awVxPJKRCWoynX9bZ+LKcmxN4Ems /aVb4EhKl+X+oWIeSwc5I752NDkh667myKF0VBqM= Received: from qq.com ([120.229.93.179]) by newxmesmtplogicsvrszc13.qq.com (NewEsmtp) with SMTP id 9B40FA58; Wed, 05 Oct 2022 11:38:52 +0800 X-QQ-mid: xmsmtpt1664941138t50kguvza Message-ID: X-QQ-XMAILINFO: N7h1OCCDntujQdzF0ZavzbIJNEzzkLscRt1wO7jnT2aE+wZ36vJir2QW5LpLpA 7J7QlVQDrihdb93IPQf4W7TC1kI01eZxjbphvc6Nah1MCpYFb78W+wE6RnUQSD3KHpa2KD23euK/ A9KYSO/5qoQvPuklOmIjcQCXZvKfN/7HxVOvH08WuhXkMVux5K5tfigSGZZxdejseDEpPJ/+sftD upIqnP5ZM1bRExw610BpbWn5aFY3tfAB5ozFyz+17H/vMmR3HPP4oQbtAMR0RKMuCr/ZYBJ5PCIT 4mWCGTN9yU4y8HEBUaSirmJLxZjX/u37oSsQf1vASSZu9CbuW442DsXIzyAejQQxztDcbfnpnS5c vIuYoIoplnsIABNP6KMCgr7sZxivC/xxBkd3Zl3jUP317v5P7o9rJ+f3AHAtLEpLLQrlc/rnqYwQ pU+xhbZ9c259DivApTm0ayoYe8C0ZJFLylu9U7FfcrI1BkLL0Ji2/rXin2kn2QmXyvNA++5cPc0x Z237c4qO7Q1i8M4jITmoTmek9c8/z6lQFZDdMEiGFtOrr9iGGLV2fzNMe/L1RduxlTT72/AaZMA3 6uyB8ZGLmJz4MupNuF0dfMDyiHH7YtKZsC+rMWAjnyA8gCrVlZ83gV1783B3M8tfCKKlbbz2Ckuj hVNQCywXcGccFy4fNT9aqCuE63vXw6qbotNRDCWaH+IeInngSZ364qtVve+mbLjcSEkdoC2r1Sg9 1F7ZlmjJZ6MpgtD3f4aZQK+DJ3Rn/3UpCg3b6R+KUOU2X7Yy3/RIlRUXDUdhMBapK4gxfcIpZhjS mLSBZ0l+0/NiIfGfHaqykv3wzHGWaz63jqAq4jII8dsWRXpkzlAm5eTJ0JUZFtlswJ2hpbHX6bDd oaQ7/l6RPI+kCvmmBCEzAsciSKaAep/7F3t/MacowL1GDlvMjiMEZU2nUb3kiv3yiHJu0xPbA79s lc8coP+VEx8qUC1PlkQQ== 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 v4 04/10] test/memarea: support alloc/free/update-refcnt test Date: Wed, 5 Oct 2022 11:38:42 +0800 X-OQ-MSGID: <20221005033848.2241-5-datshan@qq.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221005033848.2241-1-datshan@qq.com> References: <20220721044648.6817-1-fengchengwen@huawei.com> <20221005033848.2241-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