From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (unknown [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 13F30460AD; Fri, 17 Jan 2025 14:53:07 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8C00042E50; Fri, 17 Jan 2025 14:52:48 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by mails.dpdk.org (Postfix) with ESMTP id 1964F40294; Fri, 17 Jan 2025 14:52:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737121966; x=1768657966; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5nLP9pqEKwWsEh9NbijiV3KoAIx7ChSG6nY8t5kLTO4=; b=e75Up8wDdr+SvQlg4Tor0LDrJ44iXJnp2iqkVHGOGJD/knHXkL4MC4uq ttui/ixtCGdKRQfNQ1raf65OFC4DzpDvYsLYr4gTUrh9muq9YWKZYI3KE CPOT+CCHDN9xAB7DNheoo6r656c7DUmI8xnVGHGgH3hQFTp/SsX4qKq3l 7XHECm99RvYSSXmlHrZl0iFoLdx5E+VfZcpozq/mCeA+LyOHUIomJzPDy Af7ieLreiwzyogMt4RAYGZfCOr/LWTTnDS1nNGtOibKpH/WwVhJRqLtEV GKYB2cIIgUvsrYDJm0PFuLlxWumRWEoszDOWk1u68l57Ip8ynFptWqFT6 w==; X-CSE-ConnectionGUID: s9aVF13LT+20MJbOhwMCwg== X-CSE-MsgGUID: 9a7SIrdsQNaFLBPdIDxyUw== X-IronPort-AV: E=McAfee;i="6700,10204,11318"; a="62927560" X-IronPort-AV: E=Sophos;i="6.13,212,1732608000"; d="scan'208";a="62927560" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2025 05:52:45 -0800 X-CSE-ConnectionGUID: aS9vk3S8RTKJEoLaApZnqg== X-CSE-MsgGUID: a/Z4dupHR9yy/Eih5PqbHw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.13,212,1732608000"; d="scan'208";a="110812128" Received: from silpixa00401197coob.ir.intel.com (HELO silpixa00401385.ir.intel.com) ([10.237.214.45]) by orviesa004.jf.intel.com with ESMTP; 17 Jan 2025 05:52:44 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org Subject: [PATCH v2] test: improve resiliency of malloc autotest Date: Fri, 17 Jan 2025 13:52:39 +0000 Message-ID: <20250117135239.1980838-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250117125912.985475-1-bruce.richardson@intel.com> References: <20250117125912.985475-1-bruce.richardson@intel.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 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 --- v2: * removed unnecessary extra include * only added new code for non-windows, since using mmap for allocation. --- app/test/test_malloc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c index 02a7d8ef20..62e4445ebc 100644 --- a/app/test/test_malloc.c +++ b/app/test/test_malloc.c @@ -272,6 +272,30 @@ test_multi_alloc_statistics(void) size_t size = 2048; int align = 1024; int overhead = 0; +#ifndef RTE_EXEC_ENV_WINDOWS + const size_t heap_size = (1 << 21); + + 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 *memory = mmap(NULL, heap_size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (memory == MAP_FAILED) { + printf("Failed to allocate memory\n"); + return -1; + } + 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; + } +#endif /* Dynamically calculate the overhead by allocating one cacheline and * then comparing what was allocated from the heap. @@ -371,6 +395,13 @@ test_multi_alloc_statistics(void) printf("Malloc statistics are incorrect - freed alloc\n"); return -1; } + +#ifndef RTE_EXEC_ENV_WINDOWS + /* cleanup */ + rte_malloc_heap_memory_remove(__func__, memory, heap_size); + rte_malloc_heap_destroy(__func__); + munmap(memory, heap_size); +#endif return 0; } -- 2.43.0