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 5B9404611C; Fri, 24 Jan 2025 08:18:18 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EE6E440E1B; Fri, 24 Jan 2025 08:18:17 +0100 (CET) Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by mails.dpdk.org (Postfix) with ESMTP id A99AF40E15; Fri, 24 Jan 2025 08:18:16 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.214]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4YfTbF6VdWz1V5TK; Fri, 24 Jan 2025 15:14:49 +0800 (CST) Received: from kwepemk500009.china.huawei.com (unknown [7.202.194.94]) by mail.maildlp.com (Postfix) with ESMTPS id 11E341A016C; Fri, 24 Jan 2025 15:18:12 +0800 (CST) Received: from [10.67.121.161] (10.67.121.161) by kwepemk500009.china.huawei.com (7.202.194.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 24 Jan 2025 15:18:11 +0800 Message-ID: <0e91d822-ed10-4dae-8f0a-7169e7819517@huawei.com> Date: Fri, 24 Jan 2025 15:18:11 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] test: improve resiliency of malloc autotest To: Bruce Richardson , CC: References: <20250117125912.985475-1-bruce.richardson@intel.com> <20250117144112.2544963-1-bruce.richardson@intel.com> Content-Language: en-US From: fengchengwen In-Reply-To: <20250117144112.2544963-1-bruce.richardson@intel.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.121.161] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemk500009.china.huawei.com (7.202.194.94) 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 The new impl don't support re-test, how about add a wrap: 1. rename test_multi_alloc_statistics with do_test_multi_alloc_statistics, and make it take socket as parameter 2. create a new function test_multi_alloc_statistics { // prepare a new malloc heap ret = do_test_multi_alloc_statistics(socket); // free the heap return ret; } On 2025/1/17 22:40, Bruce Richardson wrote: > The test case "test_multi_alloc_statistics" was brittle in that it did > some allocations and frees and then checked statistics without > considering the initial state of the malloc heaps. This meant that, > depending on what allocations/frees were done beforehand, the test can > sometimes fail. > > We can improve resiliency by running the test using a new malloc heap, > which means it is unaffected by any previous allocations. > > Bugzilla ID: 1579 > Fixes: a40a1f8231b4 ("app: various tests update") > Cc: stable@dpdk.org > > Signed-off-by: Bruce Richardson > --- > v3: > * switched allocation from mmap to malloc allowing it work on windows > * use explicit alignment of the malloc return value to ensure memory > added to heap is page-aligned. > > v2: > * removed unnecessary extra include > * only added new code for non-windows, since using mmap for allocation. > --- > app/test/test_malloc.c | 35 +++++++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c > index 02a7d8ef20..9e73c0da09 100644 > --- a/app/test/test_malloc.c > +++ b/app/test/test_malloc.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include > > #define N 10000 > @@ -272,6 +273,34 @@ test_multi_alloc_statistics(void) > size_t size = 2048; > int align = 1024; > int overhead = 0; > + const size_t pgsz = rte_mem_page_size(); > + const size_t heap_size = (1 << 21); > + > + if (pgsz < heap_size) { > + printf("Page size is smaller than heap size\n"); > + return TEST_SKIPPED; > + } > + > + if (rte_malloc_heap_create(__func__) != 0) { > + printf("Failed to create test malloc heap\n"); > + return -1; > + } > + /* Allocate some memory using malloc and add it to our test heap. */ > + void *unaligned_memory = malloc(heap_size + pgsz); > + if (unaligned_memory == NULL) { > + printf("Failed to allocate memory\n"); > + return -1; > + } > + void *memory = RTE_PTR_ALIGN(unaligned_memory, pgsz); > + if (rte_malloc_heap_memory_add(__func__, memory, heap_size, NULL, 1, heap_size) != 0) { > + printf("Failed to add memory to heap\n"); > + return -1; > + } > + socket = rte_malloc_heap_get_socket(__func__); > + if (socket < 0) { > + printf("Failed to get socket for test malloc heap.\n"); > + return -1; > + } > > /* Dynamically calculate the overhead by allocating one cacheline and > * then comparing what was allocated from the heap. > @@ -371,6 +400,12 @@ test_multi_alloc_statistics(void) > printf("Malloc statistics are incorrect - freed alloc\n"); > return -1; > } > + > + /* cleanup */ > + rte_malloc_heap_memory_remove(__func__, memory, heap_size); > + rte_malloc_heap_destroy(__func__); > + free(unaligned_memory); > + > return 0; > } >