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 ECADC460AB; Fri, 17 Jan 2025 13:59:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CB64E427D8; Fri, 17 Jan 2025 13:59:26 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by mails.dpdk.org (Postfix) with ESMTP id 9E8D040294; Fri, 17 Jan 2025 13:59:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1737118765; x=1768654765; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Mjch+nElcPloD1jpnfX5MVn/K/fO5h9avZ6gSmnXH+k=; b=Oe5fnEOg+N+uu++LCoPm2HvIsw37RxYjEyYtOxX9kXCTWVzVxB3L06k7 ugUK0T4j0/E3t6LINl+57d8mGGK/+XIdP7pwomE941P6WkQAYaB6FET5n kW4zFL4dN5tmnxV0uVDjBIdViRy/166T1q/W6Vs3nZmIaNELiLTqIQpYQ 6eYLACw3pTLsK8AQxoWPoHMhDfml9xOR5Rt0RHyZGTLQVBuz1lBNeesKH y+HHaySmLeQxzRZyddt+Dv12HrwF999njmBVcGxXSYNJIMlwhqIlZNHNp UtYXOjqpIFuW3VgAeSUE/AmWvMbhYA7Hz1+0vGXOPjLCzIF6uoFYFpYzl A==; X-CSE-ConnectionGUID: 8uapBtL9StmKEykr1mj6EA== X-CSE-MsgGUID: mOQA+zSRT6GumA6NBkt0Kg== X-IronPort-AV: E=McAfee;i="6700,10204,11318"; a="37430321" X-IronPort-AV: E=Sophos;i="6.13,212,1732608000"; d="scan'208";a="37430321" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2025 04:59:24 -0800 X-CSE-ConnectionGUID: vyy+nPp1QeuROsAFBR/Hag== X-CSE-MsgGUID: YV9k3XmiQ2ih8IiB3dJLvw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="110910581" Received: from silpixa00401197coob.ir.intel.com (HELO silpixa00401385.ir.intel.com) ([10.237.214.45]) by orviesa005.jf.intel.com with ESMTP; 17 Jan 2025 04:59:23 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson , stable@dpdk.org Subject: [PATCH] test: improve resiliency of malloc autotest Date: Fri, 17 Jan 2025 12:59:12 +0000 Message-ID: <20250117125912.985475-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.43.0 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 --- app/test/test_malloc.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c index 02a7d8ef20..a2f2f6f8a6 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,28 @@ test_multi_alloc_statistics(void) size_t size = 2048; int align = 1024; int overhead = 0; + 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; + } /* Dynamically calculate the overhead by allocating one cacheline and * then comparing what was allocated from the heap. @@ -371,6 +394,11 @@ 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__); + munmap(memory, heap_size); return 0; } -- 2.43.0