From patchwork Fri Feb 2 11:31:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33ECCC4828E for ; Fri, 2 Feb 2024 11:31:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C51416B0080; Fri, 2 Feb 2024 06:31:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8B056B0082; Fri, 2 Feb 2024 06:31:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A06106B0083; Fri, 2 Feb 2024 06:31:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8DC5A6B0080 for ; Fri, 2 Feb 2024 06:31:34 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3E36480EE7 for ; Fri, 2 Feb 2024 11:31:34 +0000 (UTC) X-FDA: 81746648508.04.998590F Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf09.hostedemail.com (Postfix) with ESMTP id 98690140020 for ; Fri, 2 Feb 2024 11:31:32 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=MhaCkmdq; spf=pass (imf09.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873492; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rs3JITGukBvqtMUpSjOqaaofsqqmPPqDr32jEpjdRB4=; b=Q4bMol3ecwP5SBkJjls3ifSMZjML63Gns0kwydZ+aJXzXFUqOXjz+QtgY4bFssogjQJqmb LT/UrwH2m91b19sHoY1ft18+w2vdg94+Mfrx/IQJK8K2P2Ndgt32XRxfjPiICNxyXXDrsI dnn63giNwB19C+4EERGm9SoWA13rXdw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873492; a=rsa-sha256; cv=none; b=bLKc4jQOB7Xp0lHXJpV+Cxn2+KHK/BxWMCFtwr2yjvq2DZeq66/aGOqI0y5F+pRSGE0zgd wRCr81Z9ezFQA72hQqWmni6o86mYtUU4sr93GBgvUAAmnEN9C7k4M/2WxzfA9wdw3NCKte DCcjeBdykVNq8N0zif1/E/Ez+uFBmCc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=MhaCkmdq; spf=pass (imf09.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873491; bh=C1jyyNN3WoASzPdbjbyMPpmrKLB566vijGdtqZFTW+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MhaCkmdqlAPaMKIWzcOoFyg1Zay9BqMS0mFEeyAchaqMGVRG21jicoefi69wIVvWn w3JpGvqZm7Bs0vXUH/kuKTycmoy/jDkHf+GcvXomLhf8xM/ki0N8S240OKn0/E8v8H TOjJZvOUb1Gn1X6HPMZ+PSilecNhsLUSEYIhdyTsulpavA6Adq/1bYxSTUK2x7pJn5 SyjFrMVD4dmSCFWTu/WSHV3ZNJ00DTUEQhj2hQuOaRYFDwDYO0SxT+uMWsChFxJqh3 a/3XyISDLqoVfXfj06X4XNUoX2fEIWQPVNMxBtsWYtmSZsEjleU/TkN0kcZ69/le/f 14eATrM7mh5zA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id D30C13782093; Fri, 2 Feb 2024 11:31:29 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 01/12] selftests/mm: map_fixed_noreplace: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:08 +0500 Message-ID: <20240202113119.2047740-2-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 98690140020 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: ufra8s5185d6z6zfxhz9hrdzmghcfraz X-HE-Tag: 1706873492-109666 X-HE-Meta: U2FsdGVkX19v55x2Ky3u0PlqG9lWfwCwQQkG+O40MxkqxP1aSSYYPsMD+zPfGxgNgogwq6DaHVuqRIa5DQpamM4Jym5vRYBDPqPUVOwyeAQZGphi2wocsDv+xmCUt7+vcSJmUvvkAx3JZV+YpqUGzRbKI6uh5cOZAh+gMJmbW2odtmHheUYJAg80/ZftuzR367UNRbKaCKc4t3RLaPtE4lJqrkOXbjW99VqSSHyWauowbfCMNBVaJmbyB9t2q6i4wDpOoAHfI20tGePXPW3GMWeRRhhs7hHyqJXD/UxmufC9uw3F1atPPDgKSxshd66ydI9MQWYNT0017wxH9J7K7s3WI5N2f42e7BrdLLZfxuHOYut+tzMErv0AGn2ticc6ilx4adYeAiWpH96CGqBGUCGB9eGj3wocqSbMPLREYlz8YB6mYMDoeYR+JdGR/KG7TO56loq2oxHjkzrUa+w6+yNOOlOPezmwFCKGZws+xq+aNEOzOweRC7Q63Z6yu0Al2aN4+SlNROu+l/CenjhZQVXXOs3RtZcV+GoiZ7jGATLCuziFdjxfV8lqd3jSlPziGIirdysqJOhA+yKbN1ZTFRYlOrwe4Dpm5MZSYWPbOFvR2M4pmhTk+MUGTLv92xi0QoYLRdUmSvpL6RRKThKtlUn0SNZiGY2ytZDSU4HfYJyMsIboULYerqD8ZOEIgnT2yMfb47Xgjt1n5NrASEzZPbox/AM6rYIahUQtnrF24hfy4JqR77yzoFrNBz0aW55yqeph7nFSqZpZ5FBU+pWSOAGhNixfsa36yKpwR9HRv3JUSRoVY+wvC7JxDi/k7P1rSZ17KEMLbkM6nEPTInwwm0/qJonuW9OwKXni/Dh3+GmCbHPsYDLkkCYR5ywbugr9Q+2W55uclWKVwIWfS1d2JM+zQugCeL2gbPqREfzDr+kjxpbAntQ5aawWXfvmPsKuNTYOywFvEdqMmTy9d1F hM4dPK1N bWo5HiGpL9CapGz8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. While at it, convert commenting style from // to /**/. Signed-off-by: Muhammad Usama Anjum --- .../selftests/mm/map_fixed_noreplace.c | 96 ++++++------------- 1 file changed, 31 insertions(+), 65 deletions(-) diff --git a/tools/testing/selftests/mm/map_fixed_noreplace.c b/tools/testing/selftests/mm/map_fixed_noreplace.c index 598159f3df1f2..b74813fdc9514 100644 --- a/tools/testing/selftests/mm/map_fixed_noreplace.c +++ b/tools/testing/selftests/mm/map_fixed_noreplace.c @@ -12,6 +12,7 @@ #include #include #include +#include "../kselftest.h" static void dump_maps(void) { @@ -28,15 +29,12 @@ static unsigned long find_base_addr(unsigned long size) flags = MAP_PRIVATE | MAP_ANONYMOUS; addr = mmap(NULL, size, PROT_NONE, flags, -1, 0); - if (addr == MAP_FAILED) { - printf("Error: couldn't map the space we need for the test\n"); - return 0; - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("Error: couldn't map the space we need for the test\n"); + + if (munmap(addr, size) != 0) + ksft_exit_fail_msg("Error: munmap failed\n"); - if (munmap(addr, size) != 0) { - printf("Error: couldn't map the space we need for the test\n"); - return 0; - } return (unsigned long)addr; } @@ -46,51 +44,39 @@ int main(void) unsigned long flags, addr, size, page_size; char *p; + ksft_print_header(); + ksft_set_plan(9); + page_size = sysconf(_SC_PAGE_SIZE); - //let's find a base addr that is free before we start the tests + /* let's find a base addr that is free before we start the tests */ size = 5 * page_size; base_addr = find_base_addr(size); - if (!base_addr) { - printf("Error: couldn't map the space we need for the test\n"); - return 1; - } flags = MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED_NOREPLACE; - // Check we can map all the areas we need below - errno = 0; + /* Check we can map all the areas we need below */ addr = base_addr; size = 5 * page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p == MAP_FAILED) { dump_maps(); - printf("Error: couldn't map the space we need for the test\n"); - return 1; + ksft_exit_fail_msg("Error: couldn't map the space we need for the test\n"); } - - errno = 0; if (munmap((void *)addr, 5 * page_size) != 0) { dump_maps(); - printf("Error: munmap failed!?\n"); - return 1; + ksft_exit_fail_msg("Error: munmap failed!?\n"); } - printf("unmap() successful\n"); + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - errno = 0; addr = base_addr + page_size; size = 3 * page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p == MAP_FAILED) { dump_maps(); - printf("Error: first mmap() failed unexpectedly\n"); - return 1; + ksft_exit_fail_msg("Error: first mmap() failed unexpectedly\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Exact same mapping again: @@ -100,17 +86,14 @@ int main(void) * +3 | mapped | new * +4 | free | new */ - errno = 0; addr = base_addr; size = 5 * page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p != MAP_FAILED) { dump_maps(); - printf("Error:1: mmap() succeeded when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:1: mmap() succeeded when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Second mapping contained within first: @@ -121,17 +104,14 @@ int main(void) * +3 | mapped | * +4 | free | */ - errno = 0; addr = base_addr + (2 * page_size); size = page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p != MAP_FAILED) { dump_maps(); - printf("Error:2: mmap() succeeded when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:2: mmap() succeeded when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Overlap end of existing mapping: @@ -141,17 +121,14 @@ int main(void) * +3 | mapped | new * +4 | free | new */ - errno = 0; addr = base_addr + (3 * page_size); size = 2 * page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p != MAP_FAILED) { dump_maps(); - printf("Error:3: mmap() succeeded when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:3: mmap() succeeded when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Overlap start of existing mapping: @@ -161,17 +138,14 @@ int main(void) * +3 | mapped | * +4 | free | */ - errno = 0; addr = base_addr; size = 2 * page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p != MAP_FAILED) { dump_maps(); - printf("Error:4: mmap() succeeded when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:4: mmap() succeeded when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Adjacent to start of existing mapping: @@ -181,17 +155,14 @@ int main(void) * +3 | mapped | * +4 | free | */ - errno = 0; addr = base_addr; size = page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p == MAP_FAILED) { dump_maps(); - printf("Error:5: mmap() failed when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:5: mmap() failed when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); /* * Adjacent to end of existing mapping: @@ -201,27 +172,22 @@ int main(void) * +3 | mapped | * +4 | free | new */ - errno = 0; addr = base_addr + (4 * page_size); size = page_size; p = mmap((void *)addr, size, PROT_NONE, flags, -1, 0); - printf("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); - if (p == MAP_FAILED) { dump_maps(); - printf("Error:6: mmap() failed when it shouldn't have\n"); - return 1; + ksft_exit_fail_msg("Error:6: mmap() failed when it shouldn't have\n"); } + ksft_test_result_pass("mmap() @ 0x%lx-0x%lx p=%p result=%m\n", addr, addr + size, p); addr = base_addr; size = 5 * page_size; if (munmap((void *)addr, size) != 0) { dump_maps(); - printf("Error: munmap failed!?\n"); - return 1; + ksft_exit_fail_msg("Error: munmap failed!?\n"); } - printf("unmap() successful\n"); + ksft_test_result_pass("Base Address unmap() successful\n"); - printf("OK\n"); - return 0; + ksft_finished(); } From patchwork Fri Feb 2 11:31:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4886EC48291 for ; Fri, 2 Feb 2024 11:31:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C52586B0083; Fri, 2 Feb 2024 06:31:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BDADA6B0085; Fri, 2 Feb 2024 06:31:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2DE06B0087; Fri, 2 Feb 2024 06:31:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7E26E6B0083 for ; Fri, 2 Feb 2024 06:31:36 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4D92A1A0F91 for ; Fri, 2 Feb 2024 11:31:36 +0000 (UTC) X-FDA: 81746648592.13.989ED20 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf30.hostedemail.com (Postfix) with ESMTP id 81CDF80009 for ; Fri, 2 Feb 2024 11:31:34 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Gctvpzd2; spf=pass (imf30.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873494; a=rsa-sha256; cv=none; b=PsayCFChrMByV9eoaZk7HnN4D5oaDh+LRmTKItEvRfplXWZTMxa0B1qg5eQ30sApbBGSxH gxLoeFKKy7LzHy2SPuk9eFCdaLvw3D2tgDc6Ki+SmsH5X7gNbVDV4e8viyulsD80Y7iOGV HLd5IALplTktOLP9/3kjtE3BHcVNlcU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Gctvpzd2; spf=pass (imf30.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873494; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FUJjFRsxZtoV0TJs1XWVM73qLuJ0XkK/GMGOZYBkEtc=; b=ZHbkMvC7VC/24KwX5DKM5dVYAPfNpGQ74WxqAHxxAYKjvBx9h8q5mnl3W68od9G/0kjvpM oZUewyNQimYNk4P4Q4eKWsiViwhgqgnhv0TjRTLHu3Xl7bX92WBEjthJYjUzuHqI4s6G33 e8sO1+isGMtw+AVgzIfCBla4u8bHCCs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873493; bh=svTlCA3lz9tOssty2sVCUQ4b7cMa6+0k/VLIT1J7+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gctvpzd28VBgke2Z+BXwCBrBQu1jQVsCaUleRlbQUwB7fiWabKc4N7PesugLWQUtI 1sq4+wP73NLDqs7qgWOjJl574RC2NLF3msWnLxVutqERk/OGVxInK8zIoyxNkLTdwD J5nstDTK2reP5hFbcQswwc8kV6J48STqelw5C8qKbMPDs/MHOFV+pQANANHRFx0cjS KsltlL/gJgemApo2KlWrmgBtNQ27M4sUjRaTEiCQLBDR0+EUTM5dnuqupm2SzyX9uD 20YBeMErqW/GW9fKnZ4eXWqE2IckqYxZk01TUfuqCPwGH+lxL495V9Lp3K6jq2E7Wl XpkZoyR0bEiSg== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id CDA443782099; Fri, 2 Feb 2024 11:31:31 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 02/12] selftests/mm: map_hugetlb: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:09 +0500 Message-ID: <20240202113119.2047740-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 81CDF80009 X-Stat-Signature: op5mgobuf1hr3nhd4ya5pt6z39onjp5u X-Rspam-User: X-HE-Tag: 1706873494-793458 X-HE-Meta: U2FsdGVkX19zXVYxf8TMK9BTSQ6+cYqQwCdNQqOKGhAZRFWSO7UHwIVKECSB/IYE57TZlgIPC/x7O/kgTSgQm6S6Zx8zZ970b6DE9+RqjmK4cpxYggc2SZ2vCANrKoenW1+vS09w7ub+BxT3Bvl9nZWp5rP2sh4sLRwysTJf2USHHHftAZCRuMGf7kaavxvf+UzhXHAi2uPbgax/tcBXNUsSrzlnRT51yeiItH2kDCiflSYJH+gqo7a+Lz9zTVp/EFXFU2XljthUcUDqp/D7yDLUixdWGuGOya4KY4vaCv2U4EKHPOYUM3G/JghMK96loZuN+qP+W5V6GgP1P7i0bLrCBJulZrF+bRqCwR2KcH9ofiGAgQt1XNBxgUdcdjO7cDaLBWAVrLptr8pnk0W6UpGN3sn38EysROiCXhXuoEUNRip/M757A4PXcL/frn7RNoHsaZoFMfegkLkNtR4LphZSnyduaWf90+UTKoxY0vpUpy+BjTV1aMmdElmlabDeSHWLHMvINvPDXAYvbabf/PHv+0XYRnmy5Ci5X7nRU5UXQMZt33NsahIctT4wIj53eIVPBespIiZh2Ox4MLLurSjgZf9vRCucCjVBJNwnRjreWkvquillq9PogcqbCHNjGFzWB769KUJkQN9mgYY9LPSAW298Z9lF3Nm0QHK+g6W4xHcc89QaYXLQlLPu2Lok3LwGxzYQpdRaAtqcf2gcjn5R+NhAJ3W4SIIMbz2R4PqAe49nPAULvmFz9zqbU+gdCpkWm0uMUlVsZ5TdYsvuW95PT9uYbxgln45wY7+dICOwyTIS/gwyHizR+ETp3BgZowjDfp+c/AXbm1X1fnnQ1iv1DQfYXPoFilTkbiFbEdkkGWRoQYTypNr5oOgxupWIkodNoZbYcrDnwlft+QeD4DOWf/05MEF11bMEnL/awJDcZA7Eva5vkdtT5rEsMRW4wXNDblBTOHgwiv5siul A1KhAd9B fx2liQmGDdWbT1uZVqIQ/gBjVd/npC5gmLg7yKwPqfAWsNsF1wKgRinCrqpNF9ohtzLQ1O2LSiuj3s5VDtb541KzVApqNcI1FG5nhObsZyMxnpKwXu/hPyroysNWP3zluDuuJmRhYDJ6WrABIcdfWUouynHDH22e41Q1pdeIPtlPc7RU6rHP/5jybdaZYxKQ7b96cir4OJSoSRZGgvmK/w6bk3zsaiwIU78bb6XIAmNNqFkyH8LbtM4EiCgFiSkBXJ8uaV1O1XrNVtx9UY+c5XTxsoVd+VaCXork1kAAsA6xYZo0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/map_hugetlb.c | 42 +++++++++++------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/map_hugetlb.c b/tools/testing/selftests/mm/map_hugetlb.c index 86e8f2048a409..a1f005a90a4f0 100644 --- a/tools/testing/selftests/mm/map_hugetlb.c +++ b/tools/testing/selftests/mm/map_hugetlb.c @@ -16,6 +16,7 @@ #include #include #include "vm_util.h" +#include "../kselftest.h" #define LENGTH (256UL*1024*1024) #define PROTECTION (PROT_READ | PROT_WRITE) @@ -31,7 +32,7 @@ static void check_bytes(char *addr) { - printf("First hex is %x\n", *((unsigned int *)addr)); + ksft_print_msg("First hex is %x\n", *((unsigned int *)addr)); } static void write_bytes(char *addr, size_t length) @@ -42,23 +43,21 @@ static void write_bytes(char *addr, size_t length) *(addr + i) = (char)i; } -static int read_bytes(char *addr, size_t length) +static void read_bytes(char *addr, size_t length) { unsigned long i; check_bytes(addr); for (i = 0; i < length; i++) - if (*(addr + i) != (char)i) { - printf("Mismatch at %lu\n", i); - return 1; - } - return 0; + if (*(addr + i) != (char)i) + ksft_exit_fail_msg("Mismatch at %lu\n", i); + + ksft_test_result_pass("Read correct data\n"); } int main(int argc, char **argv) { void *addr; - int ret; size_t hugepage_size; size_t length = LENGTH; int flags = FLAGS; @@ -69,6 +68,9 @@ int main(int argc, char **argv) if (hugepage_size > length) length = hugepage_size; + ksft_print_header(); + ksft_set_plan(1); + if (argc > 1) length = atol(argv[1]) << 20; if (argc > 2) { @@ -78,27 +80,23 @@ int main(int argc, char **argv) } if (shift) - printf("%u kB hugepages\n", 1 << (shift - 10)); + ksft_print_msg("%u kB hugepages\n", 1 << (shift - 10)); else - printf("Default size hugepages\n"); - printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20); + ksft_print_msg("Default size hugepages\n"); + ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20); addr = mmap(ADDR, length, PROTECTION, flags, -1, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); - printf("Returned address is %p\n", addr); + ksft_print_msg("Returned address is %p\n", addr); check_bytes(addr); write_bytes(addr, length); - ret = read_bytes(addr, length); + read_bytes(addr, length); /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ - if (munmap(addr, length)) { - perror("munmap"); - exit(1); - } + if (munmap(addr, length)) + ksft_exit_fail_msg("munmap: %s\n", strerror(errno)); - return ret; + ksft_finished(); } From patchwork Fri Feb 2 11:31:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542770 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71936C47DB3 for ; Fri, 2 Feb 2024 11:31:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 832166B0085; Fri, 2 Feb 2024 06:31:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7BA406B0087; Fri, 2 Feb 2024 06:31:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 599106B0088; Fri, 2 Feb 2024 06:31:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3DC2F6B0085 for ; Fri, 2 Feb 2024 06:31:38 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1D0621401C5 for ; Fri, 2 Feb 2024 11:31:38 +0000 (UTC) X-FDA: 81746648676.25.66DAD78 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf11.hostedemail.com (Postfix) with ESMTP id 5BBB44000C for ; Fri, 2 Feb 2024 11:31:36 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=3bmcXcIj; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf11.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873496; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wTJHNbNNuZU9yzkNFtgw/kC1FsKjxHF0kk1Dqavy8AM=; b=qLwX+Il0v+VLNzSxHvGFt0qFHVxo2RclorwPQuTZt9wmH2ddClgL7v8FH1EiF/WMEgI0wb /GPS7/WMmEi8LkJDZt2UtvnKfidU4OUrBDgN2yN0AjzzSE4urZ5uGqgVumxW0GTcBb2aJd tpYf5wUztNNWPcHcXl8Q+QQbVVjIk1M= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=3bmcXcIj; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf11.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873496; a=rsa-sha256; cv=none; b=F+bfWAi2jOXd9/2sMRx2Lu+XjI/AjbaolMiWZkZr9y4i3n8bKP6hQXsRi/JAooiD0Xv2mb au59kiZlrtoO6pRv2Lthqm/3cF5cNGpM1GTiYI6Bry3QKAHRz0cVnhb1ebDGWr6Wul2APh 0lBCCdhJaOzQshkQfLj+zd0jjlGAp3A= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873495; bh=y0GUUHT+6utzfuC41fyJPiGU8siNhU+amnQRcBTcLQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=3bmcXcIj30VRmeCmmY+Ym86LbvMLxAmsZ1+9WkprrVt3iQzevJY56wjJIWdJqBXdj 20wNXjG+lGd+mG2USfLDIr1VOhLsdnxXkAJ38OVsd6KMXNK20c36Afs6+L33edOobQ nzVnXBuVi60lDHc9VM0avrt1afmEzshkvl0htyC4cTzsQEYMF2IwSQqjBAsY32EEDN mEwE+U9lR0Ndq508JuKGGS4x0FV/4nXwlPAFU5s7pYU/LOO/tSuUmI6mzcc8mulNRy FYoEjZju5Nlf45G9RTR9Fo9Ckesjkg9pchTtJi0W8TpLpDf0F1ztxnJ7lxoDU4sBH7 0w4i1eOJv+LCA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id C238237811CF; Fri, 2 Feb 2024 11:31:33 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 03/12] selftests/mm: map_populate: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:10 +0500 Message-ID: <20240202113119.2047740-4-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: ree561ot99odjy4mf8o16n7mqk1cowbk X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5BBB44000C X-HE-Tag: 1706873496-910030 X-HE-Meta: U2FsdGVkX1/n2rAUlG4s/gIXnkIhC1fnVmVSzkKEoVIc0+5ixyOMMHP9ovwn+2Z6/bJv/LV3/6Uft41nh5WMZNwBBm6Tv056bM+3QH503tevnnqui+l4Sh9R6lZm6KYYV9kOhde6Uso8Z37vWW2Z9rFRwNe6SkE7M8y+qvqHBsHO0ZEeGO1joeQPRY7HFJMzMFVlwwmE7K5cqJoEApqWGMbRwcdJ5oRwgqOL44KzFBubXPzxRRwhUllcMX4Zqi6lsYaMC3f4ImKGPvvAOxhwSFw3+sECOeZXsjdevd3umfw0hDqmi7/Xw/joaJD0gDafuxjUijWrBDvwpsxxWIba4SfgP163EcLY26s1ekeLdjaICYAbkytyo8+ykptVkno4D7U0uQtaESxiufjbVbtforL6YNM7jNKl9UtiKBeeOtRfUnftPmv5MjAt8NjjcUYLyI7d33Ei8rFH6LgDutilu6fCCAGuRknX6J0YjARHU34ygHzp5h9kbmLAJiEuClstwzhu79z+85XPl7sRKNLLkLGGFuEjGuus9JEdISekiZjSB8IWW7HneA8QRSF3dv3Y8eM9IcEQtLIY9JZjkNRRqwdAyZWzcrJME2gGkLCqdQbHZ3yX5smmDLY/VLScrAoFII1jhSqakfsZvVcdO8i6Mtr8a/h7Q3o3PVdKLaf86M7fN/5THhGzwqQtEqjsDo+rRZv3STlUuUSaOy8SF4skX/8aqPBJqra7r8lvZAOsLDRkT+eTZ1ZXp+hAq1s0hzI9/agXD4fHU2iCE6H5I4JPsnrL4bJI0v8zoQZ02w3B4cS5fB4r72UW4vaMUtoHxcHeBA5qlr4tTZYp3evQYK+J44sD861kOfu73zKBclQXzHeyZhdj10qjnBBk3yOpEmzJtB0ODbjVzzNhNHz4Kpugay/Gk3aL4aB0y2bbpgk1K8vzgGZA2rEg85AyZxzowqhEnOSZr4rHPIZXo3/F9zV lSU2MY4k JL14QLnIbTklxqExHJTFOVkFl7glHF4cMOtuylReSnZdxZZthhnCWVdUYItHBUADhRa+DcCCmAXtlNGZpFDMTGsof+eoBvccE4y5pskjkyK72g88uHtYZKf/dgDBrou/vw55jk6bxIXKcTZPvAMiwIA4/b/4c0UHWTOAzr1EXC+I+aQ79bhl7qgWy+K9y/eaZojjfJ1gOj0rLafrxdVL3Ar8f8BGOxdAW1hF3NO1oH34CsrxWr5W9Rxvz5fDixmCRZ06eDzr3JPsme2mC5WwzKZR5v+CYWCnsbaDcK/1Y2T+egVE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Minor cleanups have also been included. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/map_populate.c | 37 ++++++++++++++--------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/tools/testing/selftests/mm/map_populate.c b/tools/testing/selftests/mm/map_populate.c index 7945d07548751..5c8a53869b1bd 100644 --- a/tools/testing/selftests/mm/map_populate.c +++ b/tools/testing/selftests/mm/map_populate.c @@ -16,19 +16,21 @@ #include #include #include +#include "../kselftest.h" #define MMAP_SZ 4096 -#define BUG_ON(condition, description) \ - do { \ - if (condition) { \ - fprintf(stderr, "[FAIL]\t%s:%d\t%s:%s\n", __func__, \ - __LINE__, (description), strerror(errno)); \ - exit(1); \ - } \ +#define BUG_ON(condition, description) \ + do { \ + if (condition) \ + ksft_exit_fail_msg("[FAIL]\t%s:%d\t%s:%s\n", \ + __func__, __LINE__, (description), \ + strerror(errno)); \ } while (0) -static int parent_f(int sock, unsigned long *smap, int child) +#define TESTS_IN_CHILD 2 + +static void parent_f(int sock, unsigned long *smap, int child) { int status, ret; @@ -43,9 +45,10 @@ static int parent_f(int sock, unsigned long *smap, int child) BUG_ON(ret <= 0, "write(sock)"); waitpid(child, &status, 0); - BUG_ON(!WIFEXITED(status), "child in unexpected state"); - return WEXITSTATUS(status); + /* The ksft macros don't keep counters between processes */ + ksft_cnt.ksft_pass = WEXITSTATUS(status); + ksft_cnt.ksft_fail = TESTS_IN_CHILD - WEXITSTATUS(status); } static int child_f(int sock, unsigned long *smap, int fd) @@ -64,10 +67,11 @@ static int child_f(int sock, unsigned long *smap, int fd) ret = read(sock, &buf, sizeof(int)); BUG_ON(ret <= 0, "read(sock)"); - BUG_ON(*smap == 0x22222BAD, "MAP_POPULATE didn't COW private page"); - BUG_ON(*smap != 0xdeadbabe, "mapping was corrupted"); + ksft_test_result(*smap != 0x22222BAD, "MAP_POPULATE COW private page\n"); + ksft_test_result(*smap == 0xdeadbabe, "The mapping state\n"); - return 0; + /* The ksft macros don't keep counters between processes */ + return ksft_cnt.ksft_pass; } int main(int argc, char **argv) @@ -76,6 +80,9 @@ int main(int argc, char **argv) FILE *ftmp; unsigned long *smap; + ksft_print_header(); + ksft_set_plan(TESTS_IN_CHILD); + ftmp = tmpfile(); BUG_ON(!ftmp, "tmpfile()"); @@ -101,7 +108,9 @@ int main(int argc, char **argv) ret = close(sock[0]); BUG_ON(ret, "close()"); - return parent_f(sock[1], smap, child); + parent_f(sock[1], smap, child); + + ksft_finished(); } ret = close(sock[1]); From patchwork Fri Feb 2 11:31:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC3F7C4828E for ; Fri, 2 Feb 2024 11:31:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 992ED6B0088; Fri, 2 Feb 2024 06:31:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FFCF6B0089; Fri, 2 Feb 2024 06:31:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D0416B008A; Fri, 2 Feb 2024 06:31:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 57E386B0088 for ; Fri, 2 Feb 2024 06:31:40 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2580D1C0C8F for ; Fri, 2 Feb 2024 11:31:40 +0000 (UTC) X-FDA: 81746648760.11.334DC4C Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf28.hostedemail.com (Postfix) with ESMTP id 60A6BC001C for ; Fri, 2 Feb 2024 11:31:38 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=RJGO4CcD; spf=pass (imf28.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873498; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=zC9deBSzBvQhFpqhMGfW9RBTwzX3aAvzRrlDrMeN7Xk=; b=rZZR84MPyDh0f2sVHSlNhlS/uniMUr6CblqKTquTW9eOhXp9cgLto5RK55OHYMQULDO8GM XlRpbXGrnTWt5ouN7Or5936c+kO3a4eQ9QLetfTpHGoGTfdBXp6tMH/Mu1vA5ZZFGpRw38 JPybm2OYBCqXEFaOeXxGjHl8DUd22oo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873498; a=rsa-sha256; cv=none; b=hxouPebvFSuSU/HEAOC8QomqS7ZTKv5J/7JugWDtYBYylGsNjRFNcawY6DGNDYA9MeDeHo /Ch7YLDEl/h3L9TvnJ4HmET+09go6whcU8+4e+zYBUQWTv74eiIb5DvGjMuL+iEC+uhOqo H9GbvSb83qPzGF/8B6Sni7xkSLnrbNU= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=RJGO4CcD; spf=pass (imf28.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873497; bh=AYYPiG5/eQFpT9F2zXPDgcKcsgIGjoY5wyEFVeBzakA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RJGO4CcD7qBypx0XPWGzodj+QsiNluMbBrSE3wKfpaJVC5UrP+j+an6I5E/J+ozLh M61M+eypv0Q9t6aK0sW8w03g4Uv2gc9dnyTK/LDDQ/CiU/VAyTEjJ/w52VvTJRif39 La9eQV7+WBJrH8IX/WOGMGqMZoSULHlsZ7388FRWDtKeE7WOGkanB5PWE0FfCX8PeY UUlYUnLTJ+O7sBnUNy9i7GyUjIaf1eVtqzROiuOtYexpNgirsiKLc2jK3CUKYurTwp qBfwm6YH5yLokGkX53y0jVk7nVIWoz/+fDNfp1h6uzjs+sEyRbZiEeN9//T8mt/+9c QaveJTXG/73yA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B6F5F378209A; Fri, 2 Feb 2024 11:31:35 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/12] selftests/mm: mlock-random-test: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:11 +0500 Message-ID: <20240202113119.2047740-5-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Stat-Signature: 8m4bfap5xpoayap1ayom6zj3zubphfpy X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 60A6BC001C X-Rspam-User: X-HE-Tag: 1706873498-920370 X-HE-Meta: U2FsdGVkX1/VCXldOdb+awOUaR16L/eyr/ug//KWR8+FJFLYCk6+pSU05yoPdm3jVlXl40ZBjfKjFZm+Tc6iz2ofkyr6edeHjJ8anTeHhuX5cKa+fNbbs0noj16ucIC7oo57SEa+sdKomRPt0IVJleEl0zBLDZM+oy30cyo3z7aF7aDbbOdQwops+jweZIYSWihST4p9i8ojHAOMVBUCEG7CEslWWIuRP81o3gs9fHw/eFC6zTyKTjiKGFXRAbrzYysIvC5bjIXWvWx58fmSAXchljEBmPj2+gbHlXZhD2rFEHHzXrGBFoApw+8LE+1mD5KNC05vhBQ+RInYOo3b2UUGdDMcyzz1Em4D0XsDYxkke4Qyn3VP/VCeHplFAcO+3t5VQjsl3ngfM+iFbjBn1gTvSjgHmwFtTVKhPeeO8mZXsf4HnTOVoXwdZLKXHsNkZmklPPA3vVkp3h3TfcVxTQXirI7wcCMqAvBVgu6RU9NbwyIfc0BPeA6+T4hc1/Sks1Wq101Ha8OsOhaBVwlaSEjcJX/du3c9iJCS5jb+wrpcK25C4+/4DaxOBkoTMp3uwhK4hkJGKO8bk8ankduhbieOTvaSPf3KTqIzBHiyFOHhmcR/dpd7VZN/s45ynJCjSONaIFDIEccq42+/HSMCnX81j/RPd0Io9ZOw5GsLbMzReYT84/duAuDMuqHDz5LuBS/u6dyIPXR9hrqPqzgRrzmZ7z3hFyTQihbhycSqXVu7moB0Njvl3R8A12r86qOuVlPgvAzvSQymsor3hiCmCQO0LL63SmCeTYSc/fT1s1eBPocDtmXMMk5mp5rRKL7HHGkVF/KaHwzIote1K6RISzueUS7x1TuIPV53J30hC2yoAytOwkHux5RgU6cwgpBgFhIfLdIyRj2P6qc03n/EA7ZmGuUyIlV8Pks3hnuzluCMvw+EQiNWbtKb4n++UB3aAPlT+C//alL3gGjbvSt 8rCfIXAy JbeECjzGKSAbFHFfSs+4V7BLG4Ha945OVUTgYxyoi0knjcu38KF0Gexvx+fWk49/l1hbd7Zl2PjjztW7QCw74TSznPrTnq0rN7qPMcoOMJnL3AdEU8DgFTAI186MPSWTh+F1Uz2DytmG0Lw4mzA1bjWiIf2uEEP5D55aDYYlveyLSBooFrUi66K94BeVyfvI1K85qt6UPyK+ZYhPzgwXih1Bw9+F/vL7gEja6f983LhLUKe8FFU4Ouf5YdQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- .../testing/selftests/mm/mlock-random-test.c | 136 +++++++----------- 1 file changed, 54 insertions(+), 82 deletions(-) diff --git a/tools/testing/selftests/mm/mlock-random-test.c b/tools/testing/selftests/mm/mlock-random-test.c index 1fba77df7f628..1cd80b0f76c33 100644 --- a/tools/testing/selftests/mm/mlock-random-test.c +++ b/tools/testing/selftests/mm/mlock-random-test.c @@ -13,6 +13,7 @@ #include #include #include +#include "../kselftest.h" #include "mlock2.h" #define CHUNK_UNIT (128 * 1024) @@ -31,14 +32,14 @@ int set_cap_limits(rlim_t max) new.rlim_cur = max; new.rlim_max = max; if (setrlimit(RLIMIT_MEMLOCK, &new)) { - perror("setrlimit() returns error\n"); + ksft_perror("setrlimit() returns error\n"); return -1; } /* drop capabilities including CAP_IPC_LOCK */ if (cap_set_proc(cap)) { - perror("cap_set_proc() returns error\n"); - return -2; + ksft_perror("cap_set_proc() returns error\n"); + return -1; } return 0; @@ -52,27 +53,24 @@ int get_proc_locked_vm_size(void) unsigned long lock_size = 0; f = fopen("/proc/self/status", "r"); - if (!f) { - perror("fopen"); - return -1; - } + if (!f) + ksft_exit_fail_msg("fopen: %s\n", strerror(errno)); while (fgets(line, 1024, f)) { if (strstr(line, "VmLck")) { ret = sscanf(line, "VmLck:\t%8lu kB", &lock_size); if (ret <= 0) { - printf("sscanf() on VmLck error: %s: %d\n", - line, ret); fclose(f); - return -1; + ksft_exit_fail_msg("sscanf() on VmLck error: %s: %d\n", + line, ret); } fclose(f); return (int)(lock_size << 10); } } - perror("cannot parse VmLck in /proc/self/status\n"); fclose(f); + ksft_exit_fail_msg("cannot parse VmLck in /proc/self/status: %s\n", strerror(errno)); return -1; } @@ -91,10 +89,8 @@ int get_proc_page_size(unsigned long addr) size_t size; smaps = seek_to_smaps_entry(addr); - if (!smaps) { - printf("Unable to parse /proc/self/smaps\n"); - return 0; - } + if (!smaps) + ksft_exit_fail_msg("Unable to parse /proc/self/smaps\n"); while (getline(&line, &size, smaps) > 0) { if (!strstr(line, "MMUPageSize")) { @@ -105,12 +101,9 @@ int get_proc_page_size(unsigned long addr) } /* found the MMUPageSize of this section */ - if (sscanf(line, "MMUPageSize: %8lu kB", - &mmupage_size) < 1) { - printf("Unable to parse smaps entry for Size:%s\n", - line); - break; - } + if (sscanf(line, "MMUPageSize: %8lu kB", &mmupage_size) < 1) + ksft_exit_fail_msg("Unable to parse smaps entry for Size:%s\n", + line); } free(line); @@ -136,7 +129,7 @@ int get_proc_page_size(unsigned long addr) * return value: 0 - success * else: failure */ -int test_mlock_within_limit(char *p, int alloc_size) +static void test_mlock_within_limit(char *p, int alloc_size) { int i; int ret = 0; @@ -145,11 +138,9 @@ int test_mlock_within_limit(char *p, int alloc_size) int page_size = 0; getrlimit(RLIMIT_MEMLOCK, &cur); - if (cur.rlim_cur < alloc_size) { - printf("alloc_size[%d] < %u rlimit,lead to mlock failure\n", - alloc_size, (unsigned int)cur.rlim_cur); - return -1; - } + if (cur.rlim_cur < alloc_size) + ksft_exit_fail_msg("alloc_size[%d] < %u rlimit,lead to mlock failure\n", + alloc_size, (unsigned int)cur.rlim_cur); srand(time(NULL)); for (i = 0; i < TEST_LOOP; i++) { @@ -169,13 +160,11 @@ int test_mlock_within_limit(char *p, int alloc_size) ret = mlock2_(p + start_offset, lock_size, MLOCK_ONFAULT); - if (ret) { - printf("%s() failure at |%p(%d)| mlock:|%p(%d)|\n", - is_mlock ? "mlock" : "mlock2", - p, alloc_size, - p + start_offset, lock_size); - return ret; - } + if (ret) + ksft_exit_fail_msg("%s() failure at |%p(%d)| mlock:|%p(%d)|\n", + is_mlock ? "mlock" : "mlock2", + p, alloc_size, + p + start_offset, lock_size); } /* @@ -183,18 +172,12 @@ int test_mlock_within_limit(char *p, int alloc_size) */ locked_vm_size = get_proc_locked_vm_size(); page_size = get_proc_page_size((unsigned long)p); - if (page_size == 0) { - printf("cannot get proc MMUPageSize\n"); - return -1; - } - if (locked_vm_size > PAGE_ALIGN(alloc_size, page_size) + page_size) { - printf("test_mlock_within_limit() left VmLck:%d on %d chunk\n", - locked_vm_size, alloc_size); - return -1; - } + if (locked_vm_size > PAGE_ALIGN(alloc_size, page_size) + page_size) + ksft_exit_fail_msg("%s left VmLck:%d on %d chunk\n", + __func__, locked_vm_size, alloc_size); - return 0; + ksft_test_result_pass("%s\n", __func__); } @@ -213,7 +196,7 @@ int test_mlock_within_limit(char *p, int alloc_size) * return value: 0 - success * else: failure */ -int test_mlock_outof_limit(char *p, int alloc_size) +static void test_mlock_outof_limit(char *p, int alloc_size) { int i; int ret = 0; @@ -221,11 +204,9 @@ int test_mlock_outof_limit(char *p, int alloc_size) struct rlimit cur; getrlimit(RLIMIT_MEMLOCK, &cur); - if (cur.rlim_cur >= alloc_size) { - printf("alloc_size[%d] >%u rlimit, violates test condition\n", - alloc_size, (unsigned int)cur.rlim_cur); - return -1; - } + if (cur.rlim_cur >= alloc_size) + ksft_exit_fail_msg("alloc_size[%d] >%u rlimit, violates test condition\n", + alloc_size, (unsigned int)cur.rlim_cur); old_locked_vm_size = get_proc_locked_vm_size(); srand(time(NULL)); @@ -240,56 +221,47 @@ int test_mlock_outof_limit(char *p, int alloc_size) else ret = mlock2_(p + start_offset, lock_size, MLOCK_ONFAULT); - if (ret == 0) { - printf("%s() succeeds? on %p(%d) mlock%p(%d)\n", - is_mlock ? "mlock" : "mlock2", - p, alloc_size, - p + start_offset, lock_size); - return -1; - } + if (ret == 0) + ksft_exit_fail_msg("%s() succeeds? on %p(%d) mlock%p(%d)\n", + is_mlock ? "mlock" : "mlock2", + p, alloc_size, p + start_offset, lock_size); } locked_vm_size = get_proc_locked_vm_size(); - if (locked_vm_size != old_locked_vm_size) { - printf("tests leads to new mlocked page: old[%d], new[%d]\n", - old_locked_vm_size, - locked_vm_size); - return -1; - } + if (locked_vm_size != old_locked_vm_size) + ksft_exit_fail_msg("tests leads to new mlocked page: old[%d], new[%d]\n", + old_locked_vm_size, + locked_vm_size); - return 0; + ksft_test_result_pass("%s\n", __func__); } int main(int argc, char **argv) { char *p = NULL; - int ret = 0; + + ksft_print_header(); if (set_cap_limits(MLOCK_RLIMIT_SIZE)) - return -1; + ksft_finished(); + + ksft_set_plan(2); p = malloc(MLOCK_WITHIN_LIMIT_SIZE); - if (p == NULL) { - perror("malloc() failure\n"); - return -1; - } - ret = test_mlock_within_limit(p, MLOCK_WITHIN_LIMIT_SIZE); - if (ret) - return ret; + if (p == NULL) + ksft_exit_fail_msg("malloc() failure: %s\n", strerror(errno)); + + test_mlock_within_limit(p, MLOCK_WITHIN_LIMIT_SIZE); munlock(p, MLOCK_WITHIN_LIMIT_SIZE); free(p); - p = malloc(MLOCK_OUTOF_LIMIT_SIZE); - if (p == NULL) { - perror("malloc() failure\n"); - return -1; - } - ret = test_mlock_outof_limit(p, MLOCK_OUTOF_LIMIT_SIZE); - if (ret) - return ret; + if (p == NULL) + ksft_exit_fail_msg("malloc() failure: %s\n", strerror(errno)); + + test_mlock_outof_limit(p, MLOCK_OUTOF_LIMIT_SIZE); munlock(p, MLOCK_OUTOF_LIMIT_SIZE); free(p); - return 0; + ksft_finished(); } From patchwork Fri Feb 2 11:31:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542772 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D539C48291 for ; Fri, 2 Feb 2024 11:31:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF5FD6B0089; Fri, 2 Feb 2024 06:31:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9431B6B008C; Fri, 2 Feb 2024 06:31:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 720EA6B0092; Fri, 2 Feb 2024 06:31:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5A79B6B0089 for ; Fri, 2 Feb 2024 06:31:42 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3C10AC0F17 for ; Fri, 2 Feb 2024 11:31:42 +0000 (UTC) X-FDA: 81746648844.14.C7FB283 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf16.hostedemail.com (Postfix) with ESMTP id 6444818000B for ; Fri, 2 Feb 2024 11:31:40 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=VmnKlYaa; spf=pass (imf16.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873500; a=rsa-sha256; cv=none; b=jcVtvUE9gq/bVhQs21SP7Ow6/fBYvrnYjKRTqkWQC7RQ5BH+sjaqIurCmVKQT5mVuPLzQL AO/hLiARKYdy6YMshrfXVMM17EhKeCFdl7cj1hhcTybh5yy3leNvl9bt7AzGfm0IMhYjBS J9cn9qR2RJsuE9zar1+69RAcj3krmLs= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=VmnKlYaa; spf=pass (imf16.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873500; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kX4EQtxprT0RCkt1xldAsBBlgcc0Z966qT/McR1y+2Y=; b=aO/2xje37LlG7z3sTUXAYt/UQIhVoDXarBx1gyG24iQC1lHfVemTacSNb37UjY0nvyIJZd nkPIVDLxHL62jqB2nWRb1UdasXV20yr+rZbVOamU3f9wfqeAOTHfMduuZUVE5E1uKL4P2l 7QLu4cKPGyHakLIboflGVqDIs9Hm+YM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873499; bh=/wNqMM3jESWbi0B8UMhy6VskAZTZSdGLdkXtnfOduUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VmnKlYaaN7iHjJyHdVxs6DAU1PbRTxyuTN7EWKAIl0uUMbaTO9FgrADeAPJhFntqk ZiTooyxO4xDiUBIpU3z46hL6WG0TwXzV+tjPKQmuh4oY7K42JqWYn3HQKZtlNh40ci M0v2jXbp8Jw+hMmBI+WKfHZT3vdQZEMlrcNJEPaMzOQYcmjS0SN66Bc5NzorZmdlD9 Rbjp9HJCVfzriK2e6VFkm7+VwavbcQY9K0VrR+LeoPD4A7x6icfivUywMd9gItOYgs aEmm4lNhJiLzKmi0cFzFQ4ROjv3052tc/WcXLWGkp7rNNa2l6gZ+Z3FD1ldyD1pNFN G1No0kSnuF9yQ== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id B3B523782099; Fri, 2 Feb 2024 11:31:37 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 05/12] selftests/mm: mlock2-tests: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:12 +0500 Message-ID: <20240202113119.2047740-6-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6444818000B X-Stat-Signature: iychty7fdehwz9dm9fqzm33proe9gojj X-Rspam-User: X-HE-Tag: 1706873500-636899 X-HE-Meta: U2FsdGVkX1/EY+F6h2UXLr4Fhtm/L6WUsGI4sGUqDlZdPM8RKd4/fEi4fnzglMY1HICDs6Ij/Gl/SYtBPJ5uA23PIGvWct9Znt8TL0ox55P4j5Xo+voPJAelijjQ70YKOc43xDTk9PDWxJyI1JfQiSEpFQRSJnxEwH/Zzok49c9oFJkm+VSu7IyIelV0C8b3Daus54ETVnDnjIrX425UhPmJLILr5ugP5WKbAhJRUMhEZZcW7muSiv6xOwSguXhHT6saRm4RNSfg5TeA1NO7Jsy2WgtDTVqJmGsg2zKOQj3krbjJ9FbH7KHUueG+7+0HvnN3Qst3fX/tOeY/I5dapamI/cPLdM06+uWLW4zowjuFywt2ysq9W4PDOVzrptfIVDgX0rkx8Qnrxy8Y0UtDBvnT8lPyDcH1smEmh2LqQS3rLTqCGh5V07xFiuBeeAvv9DYpiEB4M9hXFJXsJkFunE2k0jI9FuE2djp3/u/gowaTMNQxvQlIRD0zVJtw67HbcB7DjbpNtJgfl5AALESTLyaktWwNnYZ36uitroN6LJNg+XUjgsvIFCiUIFv23LzJwkfMg5RkK/sQGFABg/++FcZvask9pDHlAk7MCypnC6yZGLrxHwcN49+3wvEwMZl7bJMG8l1Msuq3JgfkKQUqrQrAt0tF3SDCD/vGvaiQBAO7d/63+ZvWzviHhICOHkg3DH3GkZ+FBC3mwPv8ut8TPvmdo6c2h/lngGc2f8DlT5Qg1yaY66fZyghl0RedkfZDmplEQw016C8e9o4z1fJfjdk/JpDQYeS6mq5skH8ZqdAu6zl0kjvjigmzEbK44M9t9LHfXKWScvoXKre8Hlp6PGA92GOBmlTkaQ8W2sGitU2LdJCbq8QKE/0rYjKbEDawXZibU84Sgld+lYqRbJ1KL8e0iYr6Nk0wlteqndKmJaCyBV0ku9Xk2ij6iOsiEIzd/QN7W7O58JRIq1qBZw9 G9PwDj8j Vg5ZCA7OR74F63k7gaZfKf9hzXhaj2zhTnGpBPQFiB0hOkI1rGxwb6lasWymlEYrZPh0qjFzcNQEunYIX5BQH1Ly5Bm6EIkeOtYew+ZOZ320/FJQBrpy23f+sxpYtjP9ORFpPIuVkoSH1LwLEqnJqgGANQF2Qw+33wPMCGw08zieNvGJlaKbIT4jVGXWKaAZuPyd7NJY1+/vcKtbZJp89PjTUiswx2QIuigY/Mx3a7xgh0cg4etmc/pwu5A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. I've done some cleanups as well. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/mlock2-tests.c | 282 +++++++++------------- tools/testing/selftests/mm/mlock2.h | 11 +- 2 files changed, 118 insertions(+), 175 deletions(-) diff --git a/tools/testing/selftests/mm/mlock2-tests.c b/tools/testing/selftests/mm/mlock2-tests.c index 80cddc0de2061..26f744188ad0c 100644 --- a/tools/testing/selftests/mm/mlock2-tests.c +++ b/tools/testing/selftests/mm/mlock2-tests.c @@ -7,9 +7,8 @@ #include #include #include -#include "mlock2.h" - #include "../kselftest.h" +#include "mlock2.h" struct vm_boundaries { unsigned long start; @@ -40,14 +39,14 @@ static int get_vm_area(unsigned long addr, struct vm_boundaries *area) while(fgets(line, 1024, file)) { end_addr = strchr(line, '-'); if (!end_addr) { - printf("cannot parse /proc/self/maps\n"); + ksft_print_msg("cannot parse /proc/self/maps\n"); goto out; } *end_addr = '\0'; end_addr++; stop = strchr(end_addr, ' '); if (!stop) { - printf("cannot parse /proc/self/maps\n"); + ksft_print_msg("cannot parse /proc/self/maps\n"); goto out; } @@ -78,7 +77,7 @@ static bool is_vmflag_set(unsigned long addr, const char *vmflag) smaps = seek_to_smaps_entry(addr); if (!smaps) { - printf("Unable to parse /proc/self/smaps\n"); + ksft_print_msg("Unable to parse /proc/self/smaps\n"); goto out; } @@ -115,7 +114,7 @@ static unsigned long get_value_for_name(unsigned long addr, const char *name) smaps = seek_to_smaps_entry(addr); if (!smaps) { - printf("Unable to parse /proc/self/smaps\n"); + ksft_print_msg("Unable to parse /proc/self/smaps\n"); goto out; } @@ -129,7 +128,7 @@ static unsigned long get_value_for_name(unsigned long addr, const char *name) value_ptr = line + strlen(name); if (sscanf(value_ptr, "%lu kB", &value) < 1) { - printf("Unable to parse smaps entry for Size\n"); + ksft_print_msg("Unable to parse smaps entry for Size\n"); goto out; } break; @@ -180,57 +179,45 @@ static int lock_check(unsigned long addr) static int unlock_lock_check(char *map) { if (is_vmflag_set((unsigned long)map, LOCKED)) { - printf("VMA flag %s is present on page 1 after unlock\n", LOCKED); + ksft_print_msg("VMA flag %s is present on page 1 after unlock\n", LOCKED); return 1; } return 0; } -static int test_mlock_lock() +static void test_mlock_lock(void) { char *map; - int ret = 1; unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (map == MAP_FAILED) { - perror("test_mlock_locked mmap"); - goto out; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); if (mlock2_(map, 2 * page_size, 0)) { - if (errno == ENOSYS) { - printf("Cannot call new mlock family, skipping test\n"); - _exit(KSFT_SKIP); - } - perror("mlock2(0)"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlock2(0): %s\n", strerror(errno)); } - if (!lock_check((unsigned long)map)) - goto unmap; + ksft_test_result(lock_check((unsigned long)map), "%s: Locked\n", __func__); /* Now unlock and recheck attributes */ if (munlock(map, 2 * page_size)) { - perror("munlock()"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlock(): %s\n", strerror(errno)); } - ret = unlock_lock_check(map); - -unmap: + ksft_test_result(!unlock_lock_check(map), "%s: Locked\n", __func__); munmap(map, 2 * page_size); -out: - return ret; } static int onfault_check(char *map) { *map = 'a'; if (!is_vma_lock_on_fault((unsigned long)map)) { - printf("VMA is not marked for lock on fault\n"); + ksft_print_msg("VMA is not marked for lock on fault\n"); return 1; } @@ -243,172 +230,131 @@ static int unlock_onfault_check(char *map) if (is_vma_lock_on_fault((unsigned long)map) || is_vma_lock_on_fault((unsigned long)map + page_size)) { - printf("VMA is still lock on fault after unlock\n"); + ksft_print_msg("VMA is still lock on fault after unlock\n"); return 1; } return 0; } -static int test_mlock_onfault() +static void test_mlock_onfault(void) { char *map; - int ret = 1; unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (map == MAP_FAILED) { - perror("test_mlock_locked mmap"); - goto out; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); if (mlock2_(map, 2 * page_size, MLOCK_ONFAULT)) { - if (errno == ENOSYS) { - printf("Cannot call new mlock family, skipping test\n"); - _exit(KSFT_SKIP); - } - perror("mlock2(MLOCK_ONFAULT)"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlock2(MLOCK_ONFAULT): %s\n", strerror(errno)); } - if (onfault_check(map)) - goto unmap; + ksft_test_result(!onfault_check(map), "%s: VMA marked for lock on fault\n", __func__); /* Now unlock and recheck attributes */ if (munlock(map, 2 * page_size)) { - if (errno == ENOSYS) { - printf("Cannot call new mlock family, skipping test\n"); - _exit(KSFT_SKIP); - } - perror("munlock()"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlock(): %s\n", strerror(errno)); } - ret = unlock_onfault_check(map); -unmap: + ksft_test_result(!unlock_onfault_check(map), "VMA open lock after fault\n"); munmap(map, 2 * page_size); -out: - return ret; } -static int test_lock_onfault_of_present() +static void test_lock_onfault_of_present(void) { char *map; - int ret = 1; unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (map == MAP_FAILED) { - perror("test_mlock_locked mmap"); - goto out; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); *map = 'a'; if (mlock2_(map, 2 * page_size, MLOCK_ONFAULT)) { - if (errno == ENOSYS) { - printf("Cannot call new mlock family, skipping test\n"); - _exit(KSFT_SKIP); - } - perror("mlock2(MLOCK_ONFAULT)"); - goto unmap; + munmap(map, 2 * page_size); + ksft_test_result_fail("mlock2(MLOCK_ONFAULT) error: %s", strerror(errno)); } - if (!is_vma_lock_on_fault((unsigned long)map) || - !is_vma_lock_on_fault((unsigned long)map + page_size)) { - printf("VMA with present pages is not marked lock on fault\n"); - goto unmap; - } - ret = 0; -unmap: + ksft_test_result(is_vma_lock_on_fault((unsigned long)map) || + is_vma_lock_on_fault((unsigned long)map + page_size), + "VMA with present pages is not marked lock on fault\n"); munmap(map, 2 * page_size); -out: - return ret; } -static int test_munlockall() +static void test_munlockall0(void) { char *map; - int ret = 1; unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (map == MAP_FAILED) { - perror("test_munlockall mmap"); - goto out; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s\n", strerror(errno)); if (mlockall(MCL_CURRENT)) { - perror("mlockall(MCL_CURRENT)"); - goto out; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlockall(MCL_CURRENT): %s\n", strerror(errno)); } - if (!lock_check((unsigned long)map)) - goto unmap; + ksft_test_result(lock_check((unsigned long)map), "%s: Locked memory area\n", __func__); if (munlockall()) { - perror("munlockall()"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlockall(): %s\n", strerror(errno)); } - if (unlock_lock_check(map)) - goto unmap; - + ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__); munmap(map, 2 * page_size); +} + +static void test_munlockall1(void) +{ + char *map; + unsigned long page_size = getpagesize(); map = mmap(NULL, 2 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - - if (map == MAP_FAILED) { - perror("test_munlockall second mmap"); - goto out; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); if (mlockall(MCL_CURRENT | MCL_ONFAULT)) { - perror("mlockall(MCL_CURRENT | MCL_ONFAULT)"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_ONFAULT): %s\n", strerror(errno)); } - if (onfault_check(map)) - goto unmap; + ksft_test_result(!onfault_check(map), "%s: VMA marked for lock on fault\n", __func__); if (munlockall()) { - perror("munlockall()"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlockall(): %s\n", strerror(errno)); } - if (unlock_onfault_check(map)) - goto unmap; + ksft_test_result(!unlock_onfault_check(map), "%s: Unlocked\n", __func__); if (mlockall(MCL_CURRENT | MCL_FUTURE)) { - perror("mlockall(MCL_CURRENT | MCL_FUTURE)"); - goto out; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("mlockall(MCL_CURRENT | MCL_FUTURE): %s\n", strerror(errno)); } - if (!lock_check((unsigned long)map)) - goto unmap; + ksft_test_result(lock_check((unsigned long)map), "%s: Locked\n", __func__); if (munlockall()) { - perror("munlockall()"); - goto unmap; + munmap(map, 2 * page_size); + ksft_exit_fail_msg("munlockall() %s\n", strerror(errno)); } - ret = unlock_lock_check(map); - -unmap: + ksft_test_result(!unlock_lock_check(map), "%s: No locked memory\n", __func__); munmap(map, 2 * page_size); -out: - munlockall(); - return ret; } -static int test_vma_management(bool call_mlock) +static void test_vma_management(bool call_mlock) { - int ret = 1; void *map; unsigned long page_size = getpagesize(); struct vm_boundaries page1; @@ -417,25 +363,19 @@ static int test_vma_management(bool call_mlock) map = mmap(NULL, 3 * page_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); - if (map == MAP_FAILED) { - perror("mmap()"); - return ret; - } + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); if (call_mlock && mlock2_(map, 3 * page_size, MLOCK_ONFAULT)) { - if (errno == ENOSYS) { - printf("Cannot call new mlock family, skipping test\n"); - _exit(KSFT_SKIP); - } - perror("mlock(ONFAULT)\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("mlock error: %s", strerror(errno)); } if (get_vm_area((unsigned long)map, &page1) || get_vm_area((unsigned long)map + page_size, &page2) || get_vm_area((unsigned long)map + page_size * 2, &page3)) { - printf("couldn't find mapping in /proc/self/maps\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("couldn't find mapping in /proc/self/maps"); } /* @@ -444,76 +384,86 @@ static int test_vma_management(bool call_mlock) * not a failure) */ if (page1.start != page2.start || page2.start != page3.start) { - printf("VMAs are not merged to start, aborting test\n"); - ret = 0; - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("VMAs are not merged to start, aborting test"); } if (munlock(map + page_size, page_size)) { - perror("munlock()"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("munlock(): %s", strerror(errno)); } if (get_vm_area((unsigned long)map, &page1) || get_vm_area((unsigned long)map + page_size, &page2) || get_vm_area((unsigned long)map + page_size * 2, &page3)) { - printf("couldn't find mapping in /proc/self/maps\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("couldn't find mapping in /proc/self/maps"); } /* All three VMAs should be different */ if (page1.start == page2.start || page2.start == page3.start) { - printf("failed to split VMA for munlock\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("failed to split VMA for munlock"); } /* Now unlock the first and third page and check the VMAs again */ if (munlock(map, page_size * 3)) { - perror("munlock()"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("munlock(): %s", strerror(errno)); } if (get_vm_area((unsigned long)map, &page1) || get_vm_area((unsigned long)map + page_size, &page2) || get_vm_area((unsigned long)map + page_size * 2, &page3)) { - printf("couldn't find mapping in /proc/self/maps\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("couldn't find mapping in /proc/self/maps"); } /* Now all three VMAs should be the same */ if (page1.start != page2.start || page2.start != page3.start) { - printf("failed to merge VMAs after munlock\n"); - goto out; + munmap(map, 3 * page_size); + ksft_test_result_fail("failed to merge VMAs after munlock"); } - ret = 0; -out: + ksft_test_result_pass("%s call_mlock %d\n", __func__, call_mlock); munmap(map, 3 * page_size); - return ret; } -static int test_mlockall(int (test_function)(bool call_mlock)) +static void test_mlockall(void) { - int ret = 1; + if (mlockall(MCL_CURRENT | MCL_ONFAULT | MCL_FUTURE)) + ksft_exit_fail_msg("mlockall failed: %s\n", strerror(errno)); - if (mlockall(MCL_CURRENT | MCL_ONFAULT | MCL_FUTURE)) { - perror("mlockall"); - return ret; - } - - ret = test_function(false); + test_vma_management(false); munlockall(); - return ret; } int main(int argc, char **argv) { - int ret = 0; - ret += test_mlock_lock(); - ret += test_mlock_onfault(); - ret += test_munlockall(); - ret += test_lock_onfault_of_present(); - ret += test_vma_management(true); - ret += test_mlockall(test_vma_management); - return ret; + int ret, size = 3 * getpagesize(); + void *map; + + ksft_print_header(); + + map = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap error: %s", strerror(errno)); + + ret = mlock2_(map, size, MLOCK_ONFAULT); + if (ret && errno == ENOSYS) + ksft_finished(); + + munmap(map, size); + + ksft_set_plan(13); + + test_mlock_lock(); + test_mlock_onfault(); + test_munlockall0(); + test_munlockall1(); + test_lock_onfault_of_present(); + test_vma_management(true); + test_mlockall(); + + ksft_finished(); } diff --git a/tools/testing/selftests/mm/mlock2.h b/tools/testing/selftests/mm/mlock2.h index 8e02991b313c8..4417eaa5cfb78 100644 --- a/tools/testing/selftests/mm/mlock2.h +++ b/tools/testing/selftests/mm/mlock2.h @@ -6,12 +6,7 @@ static int mlock2_(void *start, size_t len, int flags) { -#ifdef __NR_mlock2 return syscall(__NR_mlock2, start, len, flags); -#else - errno = ENOSYS; - return -1; -#endif } static FILE *seek_to_smaps_entry(unsigned long addr) @@ -27,10 +22,8 @@ static FILE *seek_to_smaps_entry(unsigned long addr) char path[BUFSIZ]; file = fopen("/proc/self/smaps", "r"); - if (!file) { - perror("fopen smaps"); - _exit(1); - } + if (!file) + ksft_exit_fail_msg("fopen smaps: %s\n", strerror(errno)); while (getline(&line, &size, file) > 0) { if (sscanf(line, "%lx-%lx %s %lx %s %lu %s\n", From patchwork Fri Feb 2 11:31:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB617C4828E for ; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2D116B008C; Fri, 2 Feb 2024 06:31:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB35D6B0093; Fri, 2 Feb 2024 06:31:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A071D6B0095; Fri, 2 Feb 2024 06:31:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 73C586B008C for ; Fri, 2 Feb 2024 06:31:44 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1C51C120E8F for ; Fri, 2 Feb 2024 11:31:44 +0000 (UTC) X-FDA: 81746648928.28.BDB8B48 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf03.hostedemail.com (Postfix) with ESMTP id 57A0B20002 for ; Fri, 2 Feb 2024 11:31:42 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=0lfqji+e; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf03.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873502; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NBGcD6igMjkCr462TPdDWbNTfEPOvbMajBGZreLeDwU=; b=JGLBs459vp9WiOtD5/W4tG4tMqfOzsS8gfDlRClM0wBgtL6s5x7CfFM0EtoHXPpUbE7wOm J8lyMR5Hv28Dpr6kUNodiXCoEHno5nI0qSc6xPW2nYLQgR1kYScaWLwZHctrBmvt8e1MXK 39f6f5K4t2L2ULtfJ+BiccGWO+kuA7s= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=0lfqji+e; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf03.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873502; a=rsa-sha256; cv=none; b=G0vzEy0Kg5rQdUPDY6WyvfyjLgUwaxCGXTxyW2a7964cAKnm0hRkxtgi20cb0rOcJ4W94h PTZkpotZFnz7PKUmpWMz/o4ppXufdQcGjnMIaqEVDI5q+JavDuAX5kaQp0jQMyqkgwqfC0 nx6Rq7EeCZyqOvhzbfbkrdNaSzxhPVk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873501; bh=CPJegAn2jct8qTIbcEKKHIZ5byMY8HScpq2uBuAZ1YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0lfqji+eLlBS5e+wEw7FViQVc/F4HiU2UzSDgYsDCtUrLKYO4xfGq1b0zlJ7y6DQo 936S7ZEbazYvahmRV/khY9mhLfY7436WPsk3goRckXKRe4/1OcvSLkxbUdAIvBpPKg ACArrnKoof3qb5Gum32J6lS8YBRDJVELyv93YNlBJxZkf7BP8phc0BkR/8A35/iiPt 7pzulvjDSQruyOIJOIqJVqAW8hzDhWhZd5UTksWOdAxCm4sH2L5zkR695jneIhmytb Mu6MKAsSh7+deOUe2T/xy/a1z7bxHpSrih4Cr0BubJTB0ckHcLNZMfDre+0RY5bWqN WoWLsxJigKP4Q== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id AB6F137811CF; Fri, 2 Feb 2024 11:31:39 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/12] selftests/mm: mrelease_test: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:13 +0500 Message-ID: <20240202113119.2047740-7-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hd3u35mit1k316etowk4wh5tn31y1bpn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 57A0B20002 X-HE-Tag: 1706873502-453222 X-HE-Meta: U2FsdGVkX1/3MINlm4d795Ljdh7v3bhamPPTl9YqICM4cYvS2zm29S3I/KWaZ/kTNi88b7xelv6rb0CukCx6kjrIJIllQdNbsEcWTAJ6Xqi2pmIwKT6t7jRjLffYjpOwVrII3Su8q+z6X5YM3YsEy4OuZ1k9i7wK89jSyrtoLTC/V/O4nPVem9qZJk/9V5qUmHDS7IWbB4v/n9pe//Ab3J5FXWdoVjh/vfFxgImOtADhrTQdB9CmVAcC2xhf0N6lZmzdyeuwOYuXDxVu5UglzlA/2MSf/Wr52e2+8anPXUE13womgFMSLUpaGl6SkOqsOL9wL/9+zGhI3rcG6++zC37g4Ada71qqCtoEhhVf5tH+95EkSeiwG6pzosvTWBwtpbVD+uMHQaca3zljSBt1yJeSab0gSfzFoaNDBFzEFjabxCd+TZ/Ps0JefM+YnQhoYe3n+cUGJShbZKJE7+bc+4BLJQ4Sf8kieyoy1lRQKDFaypIzWTRWsup+pHDEQH4NWdqQydAE6gVwYhW0zxWTP0ByY9a1bp87sVyUxRaH7kWXmUSB1OXWklux9Qd0zB1TvZZXLBeQNCntrmtqemylxrEQq0PwzTzob0X/zoP9hXG2gCB2+v41I860Xho03elT8tedG2OLCj+uR6bBZBKa13mR6VznmhK+NuZvcBaII2Ag751sEiBMFmtUq92OgP1kDeOAItolI+8Vkl3XvwnXr3coNlEWsvim1Jj1X/Ts82dVe1+mfiDHV+ahgHnNvdt0E3ry2oz+VGXZVxuOPcquqCrRtXwph/zgubE4Q3h8iZv6uZCcFqCze+uqomweqZUQSpdw0C+2s3Jkr3aCFMzysVy7VxPS7YZB+jd9Pl2RBiW+MyzLLY0yElv7/IiFiuYlkjjAvGahgAUUt+cBKNP+jeGTjyio9Owd3/QSaBAQExHHGUslOyUpQbAlT5De2RDv+euRe6eCzRDHsBXhhYn nXxewoR3 9TqCjbZ2kF8EN8Eu7kQkoDYMOWcvlhvwkRXYEbeok9RT2GQnunVZZHZhUmZvy6xpYP485hf8wLFpczBcIQOwYa87t9qFD2dv/ENytEkapIPJxGyVRNdScUT6q4eH1vLAfH340SAWEjr9cAXqvFXYy7IuC2KGEPObCygW63VpDAa/N+3uyr8Ymr5JA+SkRoPClQEqlJSrzAQVuhZJYrAUUU8t+I4tSxZ2JJBFO8LNtojWhHCq/UzIkxKmazTOEIYNBboRONgRdhpRxbwB1vWJNwaaMrNlO+fcOb/g1uolnumotKXs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/mrelease_test.c | 80 +++++++++------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/mm/mrelease_test.c b/tools/testing/selftests/mm/mrelease_test.c index d822004a374e9..100370a7111df 100644 --- a/tools/testing/selftests/mm/mrelease_test.c +++ b/tools/testing/selftests/mm/mrelease_test.c @@ -26,19 +26,15 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) buf = (char *)mmap(NULL, nr_pages * psize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0); - if (buf == MAP_FAILED) { - perror("mmap failed, halting the test"); - return KSFT_FAIL; - } + if (buf == MAP_FAILED) + ksft_exit_fail_msg("mmap failed, halting the test: %s\n", strerror(errno)); for (i = 0; i < nr_pages; i++) *((unsigned long *)(buf + (i * psize()))) = i; /* Signal the parent that the child is ready */ - if (write(pipefd, "", 1) < 0) { - perror("write"); - return KSFT_FAIL; - } + if (write(pipefd, "", 1) < 0) + ksft_exit_fail_msg("write: %s\n", strerror(errno)); /* Wait to be killed (when reparenting happens) */ while (getppid() == ppid && timeout > 0) { @@ -54,23 +50,17 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) /* The process_mrelease calls in this test are expected to fail */ static void run_negative_tests(int pidfd) { - int res; /* Test invalid flags. Expect to fail with EINVAL error code. */ if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) || errno != EINVAL) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease with wrong flags"); - exit(res); + ksft_exit_fail_msg("process_mrelease with wrong flags: %s\n", strerror(errno)); } /* * Test reaping while process is alive with no pending SIGKILL. * Expect to fail with EINVAL error code. */ - if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease on a live process"); - exit(res); - } + if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) + ksft_exit_fail_msg("process_mrelease on a live process: %s\n", strerror(errno)); } static int child_main(int pipefd[], size_t size) @@ -93,11 +83,18 @@ int main(void) char byte; int res; + ksft_print_header(); + ksft_set_plan(1); + /* Test a wrong pidfd */ if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease with wrong pidfd"); - exit(res); + if (errno == ENOSYS) { + ksft_test_result_skip("process_mrelease not implemented\n"); + ksft_finished(); + } else { + ksft_exit_fail_msg("process_mrelease with wrong pidfd: %s", + strerror(errno)); + } } /* Start the test with 1MB child memory allocation */ @@ -107,16 +104,14 @@ int main(void) * Pipe for the child to signal when it's done allocating * memory */ - if (pipe(pipefd)) { - perror("pipe"); - exit(KSFT_FAIL); - } + if (pipe(pipefd)) + ksft_exit_fail_msg("pipe: %s\n", strerror(errno)); + pid = fork(); if (pid < 0) { - perror("fork"); close(pipefd[0]); close(pipefd[1]); - exit(KSFT_FAIL); + ksft_exit_fail_msg("fork: %s\n", strerror(errno)); } if (pid == 0) { @@ -134,28 +129,23 @@ int main(void) res = read(pipefd[0], &byte, 1); close(pipefd[0]); if (res < 0) { - perror("read"); if (!kill(pid, SIGKILL)) waitpid(pid, NULL, 0); - exit(KSFT_FAIL); + ksft_exit_fail_msg("read: %s\n", strerror(errno)); } pidfd = syscall(__NR_pidfd_open, pid, 0); if (pidfd < 0) { - perror("pidfd_open"); if (!kill(pid, SIGKILL)) waitpid(pid, NULL, 0); - exit(KSFT_FAIL); + ksft_exit_fail_msg("pidfd_open: %s\n", strerror(errno)); } /* Run negative tests which require a live child */ run_negative_tests(pidfd); - if (kill(pid, SIGKILL)) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("kill"); - exit(res); - } + if (kill(pid, SIGKILL)) + ksft_exit_fail_msg("kill: %s\n", strerror(errno)); success = (syscall(__NR_process_mrelease, pidfd, 0) == 0); if (!success) { @@ -169,18 +159,15 @@ int main(void) if (errno == ESRCH) { retry = (size <= MAX_SIZE_MB); } else { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease"); waitpid(pid, NULL, 0); - exit(res); + ksft_exit_fail_msg("process_mrelease: %s\n", strerror(errno)); } } /* Cleanup to prevent zombies */ - if (waitpid(pid, NULL, 0) < 0) { - perror("waitpid"); - exit(KSFT_FAIL); - } + if (waitpid(pid, NULL, 0) < 0) + ksft_exit_fail_msg("waitpid: %s\n", strerror(errno)); + close(pidfd); if (!success) { @@ -188,11 +175,10 @@ int main(void) size *= 2; goto retry; } - printf("All process_mrelease attempts failed!\n"); - exit(KSFT_FAIL); + ksft_exit_fail_msg("All process_mrelease attempts failed!\n"); } - printf("Success reaping a child with %zuMB of memory allocations\n", - size); - return KSFT_PASS; + ksft_test_result_pass("Success reaping a child with %zuMB of memory allocations\n", + size); + ksft_finished(); } From patchwork Fri Feb 2 11:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542774 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 571FBC47DB3 for ; Fri, 2 Feb 2024 11:31:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB9F46B0095; Fri, 2 Feb 2024 06:31:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3CD06B0096; Fri, 2 Feb 2024 06:31:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 859FF6B0098; Fri, 2 Feb 2024 06:31:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 65C9F6B0095 for ; Fri, 2 Feb 2024 06:31:46 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 42399A1D96 for ; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) X-FDA: 81746649012.03.E252257 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf29.hostedemail.com (Postfix) with ESMTP id 88E42120035 for ; Fri, 2 Feb 2024 11:31:44 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=XDgeClVE; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf29.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Uk8uTo2TIUryKtMLHhHC26r2ctIxy/ilY9lo8z8D1nc=; b=Du4lXxOk489s1uOUhdz2+BlXwLk0cqyyOQ2NSh6N/Nheo5LXJteFys/oLOSOutcs1VVpua ZeqjUmWrkkm0ITvVpjNe/PLgNuBC+U7Vqrr1WfP7SIxCV/yEVMW0JqglURc+jXg5NaYlhA poNfYWFnGCWyXhib2AHHyHf6UdZYJ3Q= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=XDgeClVE; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf29.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873504; a=rsa-sha256; cv=none; b=56GqErvxWFBkFfKMPZ6OIzYnZcjN1PUpMznBfNKNeYbHs/anaSPdZoWPgai9qjtBjMVMDA oRN3vnjUagOGLIJhzgZsgHwjuerPn36pXs5lqS39Hv4Jrr0Z77vMVO2TyYd6eGFmuKd3Q1 JECLGjEhZgJrgKudA17BNzSSQoccIlo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873503; bh=SKE8pMm9wj80+Eluj9OfOxnVYjWtsY8duRngXOEJh3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XDgeClVEVe8aFmyX6ZG0LNsjD6DIm4Co1wCBY44huyVlp8Z8IOoz7PHJG94tXpyrs ojEFVkVSg2Z8We2lMlYANwczm7K4D3D775Qorey38Xdd+i7LGcJK11xpFsC2CuL/PH 3Uw7HERuRZ2Y0g5cC+w1iLRE0oYbmwyIgOBgcAGzLioPyO1uJzIqt/YnDo//B2jtWK lpBVV6iwTGzmZHilpC4eAxIzqyoBqT6E2uO9C3TKGwW7tFZgQOq4anua7SZYU5La0R WDhcXlAhtK34YdgQC9+ORwoCgn4XbfPJcGyGwX8jZwKVdpuMUTa2VHRlIAflCIuNFw p1E4k/bv/R07Q== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A4D383782098; Fri, 2 Feb 2024 11:31:41 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 07/12] selftests/mm: mremap_dontunmap: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:14 +0500 Message-ID: <20240202113119.2047740-8-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 88E42120035 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ngywtgt6yhwuyp96ajfq986nzqdzahkr X-HE-Tag: 1706873504-376410 X-HE-Meta: U2FsdGVkX18xWMKCMEL0/R0CYXJasP+/MElfikihwoOaJfOqP8gFh7KU96/ip/7YpLWbcVn5+7oOI83jUCS9Mcqa2y/ScmMYHE9wg34Lt/B9jt9uzDDCG/AkoQ/S/B/XwC/IKJdZbiJHgCvGxfhQUnz5Le1wRYEOHkGOpiTdlze48HRwrXqgjxQahifkbwhjRcrv1ZHFUR2Nyr8xje/XQQuNFjTl9+S+7wAV7yxDSGVlBRsT/JPZhk/ITeGXzr0Tw3cbmqL7k30gCIIIdQ6E6ExSKY/XDa6lOp6tZAWDeb9JSbLzrkDT4TmeH8a909h3B1iTbs7uvRn/ZovOAty9aHpTikkwDCI6IJbS1/DAy66frPB5O8IjnrQ/lQUNBg8h1+fpXOh+Jx5oMAJ1FqHwhp9iH7Zh+XNu7SWOGZJDOacVv7DG9MzOexo8DKqDdc0GXyZWBZXEfG9flR8bwD0HPwNOeUpWAYAxvUs9JtWeTojVGODcLSQDd6V7051DPoG+fNkkekrZ85w2/X+QoaevZdcvkfoNwYqkz3AbAIIKJUuRAJkxsjmQclKaNFdJ9NFSX8KU/1w6TRDsSe+xk2H3WoBY2mXwgTANAmw1tprHDkZJ7hzyqSLjTHPFYU71c2Ulj2+fllgGL2oofrPkKDCzGVkF1gVdfOyAp3XDG/b8Y3FUX2lFriPZ15RIM6aSVrU1g2nTyB4OxBLKSuMyvhxRz05sevdZRZzgatL4i4+UutpaOX5JF20agAY9RcEpNkoCTaaF4+KCLvhlqQtF/hCK+EAJb1vCKYxuVsnMY3vlwc73Bo/ywCoeGxhkZVk4ZLetmDn++P/FBCIdY6au1tMVoelPm8oVGl8UE40ex0UoxZuMgBrv3Odq8vped39Do51zfvs6OZfix4yklbUrN6vKnbio4Xx2ecjiPWymPTU5k0CZJ2ORdcvNbP6KImYLkDm12kXwhD14OdpZVPs0JJd XKpHxlxk IQ5WNRkXkxhCn1CvUyOfwfaWrnEsfldu9c0OkljIdakCgt0TXd8k01kI3f815AyCKo9y2KHerUYPSS1kVJPQoC+6t2fcBvQjl4RA6mqy/CvLxNJ8c8vwbwRxe/v3t/JmQ6IbymMA8CYMsHbKHnLu2WNwyzTEoLNFWixYSZgF/PK5aUYDh19cUG5trJf/jKzEVPwO+ycWufqxUIG47QkBFSbbOVF8z881ARWoTgJak7tNMG41xjbpUXxBCEBREFtScD+InH6uWlEyeOxbvjSHkPxvWNEfvAyAyUCbC1CVFR+CvojY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/mremap_dontunmap.c | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/mremap_dontunmap.c b/tools/testing/selftests/mm/mremap_dontunmap.c index a06e73ec85682..1d75084b9ca56 100644 --- a/tools/testing/selftests/mm/mremap_dontunmap.c +++ b/tools/testing/selftests/mm/mremap_dontunmap.c @@ -27,14 +27,14 @@ static void dump_maps(void) system(cmd); } -#define BUG_ON(condition, description) \ - do { \ - if (condition) { \ - fprintf(stderr, "[FAIL]\t%s():%d\t%s:%s\n", __func__, \ - __LINE__, (description), strerror(errno)); \ - dump_maps(); \ - exit(1); \ - } \ +#define BUG_ON(condition, description) \ + do { \ + if (condition) { \ + dump_maps(); \ + ksft_exit_fail_msg("[FAIL]\t%s:%d\t%s:%s\n", \ + __func__, __LINE__, (description), \ + strerror(errno)); \ + } \ } while (0) // Try a simple operation for to "test" for kernel support this prevents @@ -122,6 +122,7 @@ static void mremap_dontunmap_simple() "unable to unmap destination mapping"); BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); } // This test validates that MREMAP_DONTUNMAP on a shared mapping works as expected. @@ -173,6 +174,7 @@ static void mremap_dontunmap_simple_shmem() "unable to unmap destination mapping"); BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); } // This test validates MREMAP_DONTUNMAP will move page tables to a specific @@ -219,6 +221,7 @@ static void mremap_dontunmap_simple_fixed() "unable to unmap destination mapping"); BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); } // This test validates that we can MREMAP_DONTUNMAP for a portion of an @@ -269,6 +272,7 @@ static void mremap_dontunmap_partial_mapping() "unable to unmap destination mapping"); BUG_ON(munmap(source_mapping, num_pages * page_size) == -1, "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); } // This test validates that we can remap over only a portion of a mapping. @@ -328,19 +332,24 @@ static void mremap_dontunmap_partial_mapping_overwrite(void) "unable to unmap destination mapping"); BUG_ON(munmap(source_mapping, 5 * page_size) == -1, "unable to unmap source mapping"); + ksft_test_result_pass("%s\n", __func__); } int main(void) { + ksft_print_header(); + page_size = sysconf(_SC_PAGE_SIZE); // test for kernel support for MREMAP_DONTUNMAP skipping the test if // not. if (kernel_support_for_mremap_dontunmap() != 0) { - printf("No kernel support for MREMAP_DONTUNMAP\n"); - return KSFT_SKIP; + ksft_print_msg("No kernel support for MREMAP_DONTUNMAP\n"); + ksft_finished(); } + ksft_set_plan(5); + // Keep a page sized buffer around for when we need it. page_buffer = mmap(NULL, page_size, PROT_READ | PROT_WRITE, @@ -356,6 +365,5 @@ int main(void) BUG_ON(munmap(page_buffer, page_size) == -1, "unable to unmap page buffer"); - printf("OK\n"); - return 0; + ksft_finished(); } From patchwork Fri Feb 2 11:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D35CC47DB3 for ; Fri, 2 Feb 2024 11:31:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12FA26B009A; Fri, 2 Feb 2024 06:31:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 091C26B0099; Fri, 2 Feb 2024 06:31:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DB0FF6B009A; Fri, 2 Feb 2024 06:31:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BABC36B0098 for ; Fri, 2 Feb 2024 06:31:48 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 97B07A0F57 for ; Fri, 2 Feb 2024 11:31:48 +0000 (UTC) X-FDA: 81746649096.14.126909C Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf28.hostedemail.com (Postfix) with ESMTP id D693FC000D for ; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ipHgTHIb; spf=pass (imf28.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873507; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Mz3EsDsw8nPMbDQAntEpYOut6QcZrDqAC3201u29i7A=; b=FYD68dvAPB4Jz2rSL6eH9NGzfQRgheKC6S40lwTT+WDGTRSoX1zcAeibZgjgDPoBR7Pm75 LZT/THvsSzHO9ah9PP2igsVTc1Xp0M6yIdLLgPShyMzH80OiPG+zVtm2PVG/FCe88uGbSX w1Uk0ge7ia/Q2wIjdUfyhe0aaOHmUK4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873507; a=rsa-sha256; cv=none; b=LZzewoEFtfQFNPTfLrYiQqT6Z73f7oCUCL1M11VHhGPTC5O02QdL3mtMbxg8KT49DqeaJ0 0wK66YupQO4ykDQUN8oRmJJuugEgGI/97uhpZyxOj3cd6zDcataTOGTaxp6kt26Dgyxsfw f4Bbn6nSOOgC1auvNvL3US9gUpISowo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ipHgTHIb; spf=pass (imf28.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873505; bh=phqEauq7xpk8vLg2PWuGHTlhwPPAnujnoDVOr8o/G5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ipHgTHIbiZtL9GHnLkuHFSqUSjrI8mA7oZH118h7U07iSgQcWvmLRz2JL5vFbzeoa CxvrBadDugg7yifOh6jgaW7EJ7PLl6Pb++JGSvDaEKNwT1Z2jOt2WWHPooMXhUaXsR uKLORI0Cb7tfrSU37m8l0Fi4QVkC8H/Ym/rwqI8WZZPsY9V45hoWj/Lf81awLqvx3h iI+l2xlw7BRq9Rs0o1axoKjTgsU8ItkQ4LpyLY4pheyL7HIuBd3p5SGc+rRaFk6UPi j+a8XUYvPIhvp3odA1NCsfV6CtUjAL6R9dOJVweVBPLxJF/9gCxXBthA58qsqcYYkN 40uffs/rX6xLA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id D80D53782099; Fri, 2 Feb 2024 11:31:43 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 08/12] selftests/mm: split_huge_page_test: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:15 +0500 Message-ID: <20240202113119.2047740-9-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Stat-Signature: qdkeeqxk8ioonobf8cjpgoes7cfrddfm X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D693FC000D X-Rspam-User: X-HE-Tag: 1706873506-669494 X-HE-Meta: U2FsdGVkX1+QuCsNakCfsLL0YYWv/u24/eZlTlIZqGHItD8UDL9xLECxYEvwcOHyTpgQF8ObuHY98LL6fiGp9HpPfwo8xqjtqFhLtbZApHbIigkdcQJfT4Xaj8vIQA1UCTXhru9H+nyqd64CEuIj+Dxw5/3t48HPnM69y5dOilYDHlrSFL9i/XdsIryKl4Njg864aiOSeI9XiJAJPpAKS/HT/5/5CgGsOZybtNvb2KHrm/i2cjpWNt9XQyMSsH8PN8cEf2deDweckmjsu2hk0G4Za1YXYLOHKgBMHCLTIyi0mTlyZQgX3dglXWqb4BqwZrSrptU85xT4dl/Tljkac65PKI/hNRycepTxphbtlXzhmI3LMIqNKqPhSqcvgCyvOENm3S9IfsHLY4rapk2owkoD725WF2bVyLT7gScbiQdHOj9jq7P/HLEOcqEgi+Q46qUB+SGJIM99Ej/PjZj8h5ztIYVPiApSo7UbVrJTxfMEhZhrBwI1LBbSrCnEQWtBjjPM+8OjotA4rqnXSnJV3GgVkKynGNhoPvyYZA2K2KXq/btBpzGFaE4+v84PVTmD6P4poity+g4Tg61OXuGiwOARjnA/Ldf4/c75WbHB6b+28uQjXsL3AVMMNYrNXaLm65cIW32ZUc5JPtHKYUnKpYMMTHg1TfCzLOhRXS3Oe0JEh96aDEm6I7Fvx4XbDyuD8II2tiCjYHkKA+y2AelSCIXurFlNMAgrMWy2ummbupdp4mgCZ0Hg1gRSrSkW2HiuLTxHbK3j5zXetht3G6Q2LC5/Q7ltB4C7Z7lDARGIkx868LLbGi3moXyGpDtWtL3XJai4qGsCDg26LkOvZxSfajTCjlOht9/TZTAJXZ4JRsP9mHfpffF33Xn/XySgT1i4TumzLfr1RezpQxkmkzyySH/TpoiccmyJwVigxO3OS09CpppOhpcUydNTc4wnLbQd2buSib0AUKw9beRNViF xXOmSixh TcJi5+aSPYTp4R5nTMORHxYItlQX+uWYLlS5xGXybx78ZjLtXWeBYnNjCV6yoxwCdIDbHKGMIee1klsFLHgsBidb48uaS0Qq4KuCw61ac3DadM8+DqQNnEPtrwYLninyKagq5LYTbvrk8aiiEa/F4KJKlidDT5qkD0G6/YlTKnUsUZH3uL5ZnZf2uvYPjE88NT8ofIXAPwIfYx5MQawS11cUz/imaPU4SpEPNP4bEIO6EfGIqBDlgNJwwbQdd8SsRcsXSK0A8Bu/DCh4SrvtyiIlyqb0uQex+4Vx9WCmAOmcbGic= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- .../selftests/mm/split_huge_page_test.c | 161 ++++++++---------- 1 file changed, 69 insertions(+), 92 deletions(-) diff --git a/tools/testing/selftests/mm/split_huge_page_test.c b/tools/testing/selftests/mm/split_huge_page_test.c index 0e74635c8c3d9..7b698a848babf 100644 --- a/tools/testing/selftests/mm/split_huge_page_test.c +++ b/tools/testing/selftests/mm/split_huge_page_test.c @@ -17,6 +17,7 @@ #include #include #include "vm_util.h" +#include "../kselftest.h" uint64_t pagesize; unsigned int pageshift; @@ -50,21 +51,19 @@ int is_backed_by_thp(char *vaddr, int pagemap_file, int kpageflags_file) return 0; } -static int write_file(const char *path, const char *buf, size_t buflen) +static void write_file(const char *path, const char *buf, size_t buflen) { int fd; ssize_t numwritten; fd = open(path, O_WRONLY); if (fd == -1) - return 0; + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); numwritten = write(fd, buf, buflen - 1); close(fd); if (numwritten < 1) - return 0; - - return (unsigned int) numwritten; + ksft_exit_fail_msg("Write failed\n"); } static void write_debugfs(const char *fmt, ...) @@ -77,15 +76,10 @@ static void write_debugfs(const char *fmt, ...) ret = vsnprintf(input, INPUT_MAX, fmt, argp); va_end(argp); - if (ret >= INPUT_MAX) { - printf("%s: Debugfs input is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= INPUT_MAX) + ksft_exit_fail_msg("%s: Debugfs input is too long\n", __func__); - if (!write_file(SPLIT_DEBUGFS, input, ret + 1)) { - perror(SPLIT_DEBUGFS); - exit(EXIT_FAILURE); - } + write_file(SPLIT_DEBUGFS, input, ret + 1); } void split_pmd_thp(void) @@ -95,39 +89,30 @@ void split_pmd_thp(void) size_t i; one_page = memalign(pmd_pagesize, len); - - if (!one_page) { - printf("Fail to allocate memory\n"); - exit(EXIT_FAILURE); - } + if (!one_page) + ksft_exit_fail_msg("Fail to allocate memory: %s\n", strerror(errno)); madvise(one_page, len, MADV_HUGEPAGE); for (i = 0; i < len; i++) one_page[i] = (char)i; - if (!check_huge_anon(one_page, 4, pmd_pagesize)) { - printf("No THP is allocated\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 4, pmd_pagesize)) + ksft_exit_fail_msg("No THP is allocated\n"); /* split all THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)one_page, (uint64_t)one_page + len); for (i = 0; i < len; i++) - if (one_page[i] != (char)i) { - printf("%ld byte corrupted\n", i); - exit(EXIT_FAILURE); - } + if (one_page[i] != (char)i) + ksft_exit_fail_msg("%ld byte corrupted\n", i); - if (!check_huge_anon(one_page, 0, pmd_pagesize)) { - printf("Still AnonHugePages not split\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 0, pmd_pagesize)) + ksft_exit_fail_msg("Still AnonHugePages not split\n"); - printf("Split huge pages successful\n"); + ksft_test_result_pass("Split huge pages successful\n"); free(one_page); } @@ -143,36 +128,29 @@ void split_pte_mapped_thp(void) int pagemap_fd; int kpageflags_fd; - if (snprintf(pagemap_proc, 255, pagemap_template, getpid()) < 0) { - perror("get pagemap proc error"); - exit(EXIT_FAILURE); - } - pagemap_fd = open(pagemap_proc, O_RDONLY); + if (snprintf(pagemap_proc, 255, pagemap_template, getpid()) < 0) + ksft_exit_fail_msg("get pagemap proc error: %s\n", strerror(errno)); - if (pagemap_fd == -1) { - perror("read pagemap:"); - exit(EXIT_FAILURE); - } + pagemap_fd = open(pagemap_proc, O_RDONLY); + if (pagemap_fd == -1) + ksft_exit_fail_msg("read pagemap: %s\n", strerror(errno)); kpageflags_fd = open(kpageflags_proc, O_RDONLY); - - if (kpageflags_fd == -1) { - perror("read kpageflags:"); - exit(EXIT_FAILURE); - } + if (kpageflags_fd == -1) + ksft_exit_fail_msg("read kpageflags: %s\n", strerror(errno)); one_page = mmap((void *)(1UL << 30), len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + if (one_page == MAP_FAILED) + ksft_exit_fail_msg("Fail to allocate memory: %s\n", strerror(errno)); madvise(one_page, len, MADV_HUGEPAGE); for (i = 0; i < len; i++) one_page[i] = (char)i; - if (!check_huge_anon(one_page, 4, pmd_pagesize)) { - printf("No THP is allocated\n"); - exit(EXIT_FAILURE); - } + if (!check_huge_anon(one_page, 4, pmd_pagesize)) + ksft_exit_fail_msg("No THP is allocated\n"); /* remap the first pagesize of first THP */ pte_mapped = mremap(one_page, pagesize, pagesize, MREMAP_MAYMOVE); @@ -183,10 +161,8 @@ void split_pte_mapped_thp(void) pagesize, pagesize, MREMAP_MAYMOVE|MREMAP_FIXED, pte_mapped + pagesize * i); - if (pte_mapped2 == (char *)-1) { - perror("mremap failed"); - exit(EXIT_FAILURE); - } + if (pte_mapped2 == MAP_FAILED) + ksft_exit_fail_msg("mremap failed: %s\n", strerror(errno)); } /* smap does not show THPs after mremap, use kpageflags instead */ @@ -196,10 +172,8 @@ void split_pte_mapped_thp(void) is_backed_by_thp(&pte_mapped[i], pagemap_fd, kpageflags_fd)) thp_size++; - if (thp_size != 4) { - printf("Some THPs are missing during mremap\n"); - exit(EXIT_FAILURE); - } + if (thp_size != 4) + ksft_exit_fail_msg("Some THPs are missing during mremap\n"); /* split all remapped THPs */ write_debugfs(PID_FMT, getpid(), (uint64_t)pte_mapped, @@ -208,21 +182,18 @@ void split_pte_mapped_thp(void) /* smap does not show THPs after mremap, use kpageflags instead */ thp_size = 0; for (i = 0; i < pagesize * 4; i++) { - if (pte_mapped[i] != (char)i) { - printf("%ld byte corrupted\n", i); - exit(EXIT_FAILURE); - } + if (pte_mapped[i] != (char)i) + ksft_exit_fail_msg("%ld byte corrupted\n", i); + if (i % pagesize == 0 && is_backed_by_thp(&pte_mapped[i], pagemap_fd, kpageflags_fd)) thp_size++; } - if (thp_size) { - printf("Still %ld THPs not split\n", thp_size); - exit(EXIT_FAILURE); - } + if (thp_size) + ksft_exit_fail_msg("Still %ld THPs not split\n", thp_size); - printf("Split PTE-mapped huge pages successful\n"); + ksft_test_result_pass("Split PTE-mapped huge pages successful\n"); munmap(one_page, len); close(pagemap_fd); close(kpageflags_fd); @@ -238,24 +209,21 @@ void split_file_backed_thp(void) char testfile[INPUT_MAX]; uint64_t pgoff_start = 0, pgoff_end = 1024; - printf("Please enable pr_debug in split_huge_pages_in_file() if you need more info.\n"); + ksft_print_msg("Please enable pr_debug in split_huge_pages_in_file() for more info.\n"); status = mount("tmpfs", tmpfs_loc, "tmpfs", 0, "huge=always,size=4m"); - if (status) { - printf("Unable to create a tmpfs for testing\n"); - exit(EXIT_FAILURE); - } + if (status) + ksft_exit_fail_msg("Unable to create a tmpfs for testing\n"); status = snprintf(testfile, INPUT_MAX, "%s/thp_file", tmpfs_loc); if (status >= INPUT_MAX) { - printf("Fail to create file-backed THP split testing file\n"); - goto cleanup; + ksft_exit_fail_msg("Fail to create file-backed THP split testing file\n"); } fd = open(testfile, O_CREAT|O_WRONLY); if (fd == -1) { - perror("Cannot open testing file\n"); + ksft_perror("Cannot open testing file"); goto cleanup; } @@ -264,7 +232,7 @@ void split_file_backed_thp(void) close(fd); if (num_written < 1) { - printf("Fail to write data to testing file\n"); + ksft_perror("Fail to write data to testing file"); goto cleanup; } @@ -272,42 +240,51 @@ void split_file_backed_thp(void) write_debugfs(PATH_FMT, testfile, pgoff_start, pgoff_end); status = unlink(testfile); - if (status) - perror("Cannot remove testing file\n"); + if (status) { + ksft_perror("Cannot remove testing file"); + goto cleanup; + } -cleanup: status = umount(tmpfs_loc); if (status) { - printf("Unable to umount %s\n", tmpfs_loc); - exit(EXIT_FAILURE); + rmdir(tmpfs_loc); + ksft_exit_fail_msg("Unable to umount %s\n", tmpfs_loc); } + status = rmdir(tmpfs_loc); - if (status) { - perror("cannot remove tmp dir"); - exit(EXIT_FAILURE); - } + if (status) + ksft_exit_fail_msg("cannot remove tmp dir: %s\n", strerror(errno)); - printf("file-backed THP split test done, please check dmesg for more information\n"); + ksft_print_msg("Please check dmesg for more information\n"); + ksft_test_result_pass("File-backed THP split test done\n"); + return; + +cleanup: + umount(tmpfs_loc); + rmdir(tmpfs_loc); + ksft_exit_fail_msg("Error occurred\n"); } int main(int argc, char **argv) { + ksft_print_header(); + if (geteuid() != 0) { - printf("Please run the benchmark as root\n"); - exit(EXIT_FAILURE); + ksft_print_msg("Please run the benchmark as root\n"); + ksft_finished(); } + ksft_set_plan(3); + pagesize = getpagesize(); pageshift = ffs(pagesize) - 1; pmd_pagesize = read_pmd_pagesize(); - if (!pmd_pagesize) { - printf("Reading PMD pagesize failed\n"); - exit(EXIT_FAILURE); - } + if (!pmd_pagesize) + ksft_exit_fail_msg("Reading PMD pagesize failed\n"); split_pmd_thp(); split_pte_mapped_thp(); split_file_backed_thp(); - return 0; + ksft_finished(); } From patchwork Fri Feb 2 11:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542776 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0627BC47DB3 for ; Fri, 2 Feb 2024 11:31:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15BCE6B0099; Fri, 2 Feb 2024 06:31:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B7756B009B; Fri, 2 Feb 2024 06:31:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD7D46B009C; Fri, 2 Feb 2024 06:31:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BC66E6B0099 for ; Fri, 2 Feb 2024 06:31:51 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 950F8120E69 for ; Fri, 2 Feb 2024 11:31:51 +0000 (UTC) X-FDA: 81746649222.15.7A7CB4C Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf24.hostedemail.com (Postfix) with ESMTP id 7C83A18001F for ; Fri, 2 Feb 2024 11:31:49 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=4iURJocn; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf24.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873509; a=rsa-sha256; cv=none; b=Phk6gnkKA5Uk3kp7oasZ17fB5zDC9D4jzD/Cc+cnt1XK2t6ZyJ1/+NbNoB5tpkavRhzK7/ el9tsTKkUMaDYqIQsZAkyrhKTMrjXZLzh2sHEkgIgBAGCCh9V6dCDWP4vJpfXoZSq2OGEK x1y3cF12B3TIVuVyzcS8Pod/OrD3ie0= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=4iURJocn; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf24.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873509; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=d6PKfMgckuxTwcBG16wC0ctq4RNtAQR5cQVEk/u50mQ=; b=k3dku6HcFRiZpVCJFXrGINfoV6w2q0nuHGkD8VdAeVD0M0ttQHEmvaIOBFkaglEdA4JWmV 271ZTBod5clVxR6OgKacQgIvJ/Y9VD01jzeDK52lBR4/bB0eSciGpq5yoZAGvcnDwuPUj7 /dz7aU1NYeP5UBM9WzoL3NLSc81afCc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873508; bh=Qz1hYpXZ0ZArWwJNMRoiOZt8O4/weesIABzDbZYxCC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=4iURJocnM0xIVlqP6lwnTgvP82VuqAWxM8CR5SMY9umKeiZMf+O641vLLvn4F9zVJ 0MCSIbL3dSV3Sdjefjzk8+pSzUgQU81mbDOekSG8RofKbOpDqwpjht66/FWqefPu8L tdbJRJ93MCoWbUWR8BxYzeWYCEHRT1GeEK1E6ygOlho2sW9g7IYvuknu0vFq62dxZh mp6wQotluB5pkXvZ8WQa+D7ZHiG3Mu5cPqjKq6+dI8d+8NgIHhSN/Ran+gadjQK6Wh TNsK6kLqZ7cI7qtN52hJN4RY/ypjQo1S/0wEb36trA41XeWHHGnD9C/2SpvjvPsVyp 2sLw1JjFkAcjA== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 3A5DE37811CF; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 09/12] selftests/mm: thp_settings: conform to TAP format output Date: Fri, 2 Feb 2024 16:31:16 +0500 Message-ID: <20240202113119.2047740-10-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 7C83A18001F X-Stat-Signature: rragcsqo13f8emyuwccb94ns71fd9fgm X-HE-Tag: 1706873509-357820 X-HE-Meta: U2FsdGVkX18XkHnH1L8XmwuQae+y1WUExJGSC1S/Z5XvH7HYMPVAlW8H1KQzP322XDK1PWlfd7Vg7wmj5j0NgG22XeS3GGFS/C/yD3Db5RRH1+BRgkFpHtO5q4d/7Db8yKl9Cd+AeoFe+jr0uUbKA909RTHKnBnVkxs86uw2WOdnFafqIp+BnyAIHkwRHek3KdN1mFvAGqJRqxifO0IroyDyaCR8oZ046C2MlFC6eug66/Qr5Zb54vBMKejUKttBsMGFS06YJKDGMIOfDs7tsrCbAszXuUinIj723Epr3ZWFudAIf9C1i7n67Chp6eyOl3ZY5gzj93Tw2epWbDJyoe+GpU/P0old17NtP5KgfxL3orFXBujoaKdIbwdStFlg14zDyXSAwqIZv284uyXiHk4Y3Qk2/dTL5WXqFzO8NUXByn6XyKNcG7FxPbF1WAmltQCX5I+Wm1HYUiHwQcfP+Xb2o5Qy67IfjF1NTHuNXP4si9OdDttJb9rtjJdZrE4JZURRmcR/G7AFBH6AkL/8SEj0PEDJu4gaY+toKBLxjXKtBE54SLWPrHsIs9efNKG6S6lIIb4Cxido1r8/vZnnXbx83ZgOvcBA4iNNMF1dJXaf6fNYgS+uowrPFVMBDBdZaU1KhmBGFeYm+7pMUFtd5aoPxAW1GKJKg/5WtpVAt8NE1AZ5CQqtSqBPCa6NIypwpQzS6Ys8HNqVyPCeYsRGGtOPqVayYHbs9QFYV4TdFFqyl1tkUJiXd25VpiBYC7dxhkWWhgUsqn03JgZx4sJfPTpWUoQydYE7S8jv8lgvAFqkMucGDWO4DQWIUg/PjPEo6hN2sMeQyK3khAVf56os2vUT7RmoxbggpqBKsuUdng1EoRXqHln7uemelg+YaysI6Wi7ziGZsxKgHqlJ6t+vdeffCWmmobvx0OTR4KqDXi+6iDtL0C+pldjI3W4JbamUhImAoDfv7ELXTDtFvIV qxYADDzJ 8Ry3PUeK/zK/lmVM/hNYf/edcqCpkDM8Oy9GPFStvvLCoEPIxz8P35bJIFAUNVWlu2jzvQYVSfYALQvqVemMSmBXp3yVX0uBN14pKQ0VEJLkyeWq6cWBJrsm9W0DCeHArWTBzBinGivnPRL46wkHjFm1A0B865aLh6ejxPn5fVoIRwknl3tH2OCNwYmxoewVx6eOrhxOpCmf0rsK2Lu98DWJFVBD0JjQQGa4+162SAK8gvieCKuWOE1iV3zqHpjzh2L75khADj/OVXOIJUAkwgt7G3yZ87iqKpeKL4PHIj72U6CE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/khugepaged.c | 3 +- tools/testing/selftests/mm/thp_settings.c | 123 ++++++++-------------- tools/testing/selftests/mm/thp_settings.h | 4 +- 3 files changed, 47 insertions(+), 83 deletions(-) diff --git a/tools/testing/selftests/mm/khugepaged.c b/tools/testing/selftests/mm/khugepaged.c index d51fdaee7dc6a..3f202da0867c5 100644 --- a/tools/testing/selftests/mm/khugepaged.c +++ b/tools/testing/selftests/mm/khugepaged.c @@ -152,8 +152,7 @@ static void get_finfo(const char *dir) major(path_stat.st_dev), minor(path_stat.st_dev)) >= sizeof(path)) ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (read_file(path, buf, sizeof(buf)) < 0) - ksft_exit_fail_msg("read_file(read_num): %s\n", strerror(errno)); + read_file(path, buf, sizeof(buf)); if (strstr(buf, "DEVTYPE=disk")) { /* Found it */ diff --git a/tools/testing/selftests/mm/thp_settings.c b/tools/testing/selftests/mm/thp_settings.c index a4163438108ec..273a95d025285 100644 --- a/tools/testing/selftests/mm/thp_settings.c +++ b/tools/testing/selftests/mm/thp_settings.c @@ -5,7 +5,9 @@ #include #include #include +#include +#include "../kselftest.h" #include "thp_settings.h" #define THP_SYSFS "/sys/kernel/mm/transparent_hugepage/" @@ -42,58 +44,45 @@ static const char * const shmem_enabled_strings[] = { NULL }; -int read_file(const char *path, char *buf, size_t buflen) +void read_file(const char *path, char *buf, size_t buflen) { int fd; ssize_t numread; fd = open(path, O_RDONLY); if (fd == -1) - return 0; + ksft_exit_fail_msg("%s open failed: %s\n", path, strerror(errno)); numread = read(fd, buf, buflen - 1); if (numread < 1) { close(fd); - return 0; + ksft_exit_fail_msg("No data read\n"); } buf[numread] = '\0'; close(fd); - - return (unsigned int) numread; } -int write_file(const char *path, const char *buf, size_t buflen) +void write_file(const char *path, const char *buf, size_t buflen) { int fd; ssize_t numwritten; fd = open(path, O_WRONLY); - if (fd == -1) { - printf("open(%s)\n", path); - exit(EXIT_FAILURE); - return 0; - } + if (fd == -1) + ksft_exit_fail_msg("%s open failed\n", path); numwritten = write(fd, buf, buflen - 1); close(fd); - if (numwritten < 1) { - printf("write(%s)\n", buf); - exit(EXIT_FAILURE); - return 0; - } - - return (unsigned int) numwritten; + if (numwritten < 1) + ksft_exit_fail_msg("write failed (%s)\n", buf); } const unsigned long read_num(const char *path) { char buf[21]; - if (read_file(path, buf, sizeof(buf)) < 0) { - perror("read_file()"); - exit(EXIT_FAILURE); - } + read_file(path, buf, sizeof(buf)); return strtoul(buf, NULL, 10); } @@ -103,10 +92,7 @@ void write_num(const char *path, unsigned long num) char buf[21]; sprintf(buf, "%ld", num); - if (!write_file(path, buf, strlen(buf) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, buf, strlen(buf) + 1); } int thp_read_string(const char *name, const char * const strings[]) @@ -117,30 +103,22 @@ int thp_read_string(const char *name, const char * const strings[]) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (!read_file(path, buf, sizeof(buf))) { - perror(path); - exit(EXIT_FAILURE); - } + read_file(path, buf, sizeof(buf)); c = strchr(buf, '['); - if (!c) { - printf("%s: Parse failure\n", __func__); - exit(EXIT_FAILURE); - } + if (!c) + ksft_exit_fail_msg("%s: Parse failure\n", __func__); c++; memmove(buf, c, sizeof(buf) - (c - buf)); c = strchr(buf, ']'); - if (!c) { - printf("%s: Parse failure\n", __func__); - exit(EXIT_FAILURE); - } + if (!c) + ksft_exit_fail_msg("%s: Parse failure\n", __func__); + *c = '\0'; ret = 0; @@ -150,8 +128,8 @@ int thp_read_string(const char *name, const char * const strings[]) ret++; } - printf("Failed to parse %s\n", name); - exit(EXIT_FAILURE); + ksft_exit_fail_msg("Failed to parse %s\n", name); + return -1; } void thp_write_string(const char *name, const char *val) @@ -160,15 +138,10 @@ void thp_write_string(const char *name, const char *val) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - if (!write_file(path, val, strlen(val) + 1)) { - perror(path); - exit(EXIT_FAILURE); - } + write_file(path, val, strlen(val) + 1); } const unsigned long thp_read_num(const char *name) @@ -177,10 +150,9 @@ const unsigned long thp_read_num(const char *name) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + return read_num(path); } @@ -190,10 +162,9 @@ void thp_write_num(const char *name, unsigned long num) int ret; ret = snprintf(path, PATH_MAX, THP_SYSFS "%s", name); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); + write_num(path, num); } @@ -275,29 +246,26 @@ void thp_write_settings(struct thp_settings *settings) struct thp_settings *thp_current_settings(void) { - if (!settings_index) { - printf("Fail: No settings set"); - exit(EXIT_FAILURE); - } + if (!settings_index) + ksft_exit_fail_msg("Fail: No settings set\n"); + return settings_stack + settings_index - 1; } void thp_push_settings(struct thp_settings *settings) { - if (settings_index >= MAX_SETTINGS_DEPTH) { - printf("Fail: Settings stack exceeded"); - exit(EXIT_FAILURE); - } + if (settings_index >= MAX_SETTINGS_DEPTH) + ksft_exit_fail_msg("Fail: Settings stack exceeded\n"); + settings_stack[settings_index++] = *settings; thp_write_settings(thp_current_settings()); } void thp_pop_settings(void) { - if (settings_index <= 0) { - printf("Fail: Settings stack empty"); - exit(EXIT_FAILURE); - } + if (settings_index <= 0) + ksft_exit_fail_msg("Fail: Settings stack empty\n"); + --settings_index; thp_write_settings(thp_current_settings()); } @@ -335,14 +303,11 @@ unsigned long thp_supported_orders(void) for (i = 0; i < NR_ORDERS; i++) { ret = snprintf(path, PATH_MAX, THP_SYSFS "hugepages-%ukB/enabled", (getpagesize() >> 10) << i); - if (ret >= PATH_MAX) { - printf("%s: Pathname is too long\n", __func__); - exit(EXIT_FAILURE); - } + if (ret >= PATH_MAX) + ksft_exit_fail_msg("%s: Pathname is too long\n", __func__); - ret = read_file(path, buf, sizeof(buf)); - if (ret) - orders |= 1UL << i; + read_file(path, buf, sizeof(buf)); + orders |= 1UL << i; } return orders; diff --git a/tools/testing/selftests/mm/thp_settings.h b/tools/testing/selftests/mm/thp_settings.h index 71cbff05f4c7f..04a6a7bbd08f8 100644 --- a/tools/testing/selftests/mm/thp_settings.h +++ b/tools/testing/selftests/mm/thp_settings.h @@ -56,8 +56,8 @@ struct thp_settings { struct hugepages_settings hugepages[NR_ORDERS]; }; -int read_file(const char *path, char *buf, size_t buflen); -int write_file(const char *path, const char *buf, size_t buflen); +void read_file(const char *path, char *buf, size_t buflen); +void write_file(const char *path, const char *buf, size_t buflen); const unsigned long read_num(const char *path); void write_num(const char *path, unsigned long num); From patchwork Fri Feb 2 11:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C76E8C4828E for ; Fri, 2 Feb 2024 11:31:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B18206B009B; Fri, 2 Feb 2024 06:31:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A7E706B009C; Fri, 2 Feb 2024 06:31:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8CED46B009D; Fri, 2 Feb 2024 06:31:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 739636B009B for ; Fri, 2 Feb 2024 06:31:53 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 147CD80EE7 for ; Fri, 2 Feb 2024 11:31:53 +0000 (UTC) X-FDA: 81746649306.03.F68028B Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf16.hostedemail.com (Postfix) with ESMTP id 565E5180007 for ; Fri, 2 Feb 2024 11:31:51 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=WEAjLbWa; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf16.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873511; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=JqsXsqCJsYmUXKuLrKWWOhAOIXpLGdY9KIga4HqM8Ug=; b=U++TNurZZnQ02imLBN9BTQVyWOzqD87K8yyqwwHvE1r8WPJytGuKOZepPvzqz9tI3ZoXUo RsWLN9/F5oYQMrxwv4xy7+h7LIuhIDeBxyHn+hS48cehjpJ6/lEaWTnlgjUscyiW3ySAB5 wz1OAIYB0o1DhWBHz2E9BCIQcK2b/ko= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=WEAjLbWa; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf16.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873511; a=rsa-sha256; cv=none; b=lv4G7zDkXD8dVP95oUzdsVrkQlIfIGJy0n9GjmCL3CRBUik5FEZvPAX6gAkk716WoFxPQe 3URGDk4YECH6UqA0cZhHvvmscCSGUuxAczx0Eb7WGoUNVOm9MsQ3knNYGhm/Bh0Nmju/Cj ja0AlHd7V8sQh2dIt/5k1uL48QXr3YI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873510; bh=phT1qh4JSwaGJfIJ4Mc7ECbFwdGcURcGclR3lGXRi70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WEAjLbWayzjN6Pxwfewo5zbvo+TqxcG9RBVlIOFiIsocjc0v5NWc4vhbNRXRja6ju sOZ0vy51FvzZJV0SMW08/uheGsKGfdWfYexBzLXRRfD5y6f96TCc+Bzj86yaysA4Pn HyI3E+jVC7ra46aqIzIojEC29d+6BTOGX1FV0S4A46ImS+N7sIbHk5+kpwRdaHlpMz cO9OjnJhPWkLt6t8AITDwX+C6NR6T4b5Ncd0EfqisX48hc4Y+Md5Evvq0+EPf+mXhG pcG0mqkq9O1tKVEasvlyoiIsahSoDlWUU8OSiqQJ9PGJEmAjIoG65/NWIz1jHQnAAm AAvnrWIgqkGGw== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 9B12B3782093; Fri, 2 Feb 2024 11:31:48 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 10/12] selftests/mm: thuge-gen: conform to TAP format output Date: Fri, 2 Feb 2024 16:31:17 +0500 Message-ID: <20240202113119.2047740-11-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hxhfkbijaumukm93w45w7nexuqt17w55 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 565E5180007 X-HE-Tag: 1706873511-926156 X-HE-Meta: U2FsdGVkX18sfDJ2an//SL/4I5CSK4Lqc7HEiYDSqkeJMZU5/Ioe+QaIHe1oMjNK5Ro4FXRdMtJxSA+jT9ySI4o16f+xeZh2eW1vWfEcdTqcTDDPMB/WGgS8a0yZVWh8KHGAH3mr6l1+4okZuRvT7arDnsHIo9+RT2zafRQjPTDa2utcRROhhMbNDwruVBXlWfc23doHiS160inCWLB3jguO56YNtz8QUK+Lu+fgaBTpiQoPQgJVnnUHZGXUnap6womoO9e7EWYdflQ05EMfQ8YbT3hpYmswvHb/iuNlghsJEryx5oU7StsPaBoStmlATxC1apl+OEvntASFScVU3w1n44gATaBOS84253k7JBNP4ZHKnlTrE1WkUACNpJRmcs+KnlQEzL8GPdY+mjZIqURLLc6zrA51Dzxfw/FAjQ39w1cibulylQKmKoHxb8aZyQ2Ox8YArQLFO4zN2JNzNIQNxWFHfUrlgiOw1qTk1cI3RdMtoSEM9l/rRuSKLDbWEwujpQSNSZH//sEzLPKbCGAt6Jgh88rSr95l7JrXuim5EPWS8BewUbjGTBUINnFiNzMJakqhmpmCkkE4zVVCk3HasJsYmUIgDOWGhCnXOf+P+Z7W3oajlkhso+pnpxZJLQ8X6FLGzB22xyshwDX5XevZBB732SNQ7hjwRmUlKu3vuxdo2S80l64hvanCppSA7JX6XwFZsUcrPXZ51E9aAQSslV+WNHGKh9CU5f0BwaYtn6l7YYADQ3ziT1Cejnwri8OzPF1mAjeIOxG+yXL2GbVeuMAVYugbfKsTqX5n+OYuTI6fan6J/qD5Wcrb5uPRJ3j1kEkZzuoz0Hf0ciHb74Mw138dFgI3zjbKXcH9RVN8Y4PhK7h96UoT0wK+rEbUF2rNvzcpjQC9zdk3A1OlbnVfHP+ioOUrMfs1631/MMeD0elJE1EUISvazuCw0nDYAPwUuIGaiXI22W8QJZQ sxwrpVi1 ozRSOKwQiP5BE3reYar2dTyLtXKnHUfyOUxPn+aTn5Mufg5LkD3hB76Le/2O7mWnkUT+2TxxB8jdYL0WXK9d5lY444zy+gamvM6RsntEjUOGTKKb3tht1af5gx/KTwXYtNSPjJ20xRpp5M/NH2kSNtOB14HJiebz9yFbaaGhCGaaFDQNQjFPSS/yFXgmKKZqR4Bb9s9Hdd36Pss9qqDeMYDN7mlv2RWj3ayT3Psgmp1yFCEsmzQQ7DV09Ww== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Also remove un-needed logging which isn't enabled. Skip a hugepage size if it has less free pages to avoid unnecessary failures. For examples, some systems may not have 1GB hugepage free. So skip 1GB for testing in this test instead of failing the entire test. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/thuge-gen.c | 147 +++++++++++++------------ 1 file changed, 75 insertions(+), 72 deletions(-) diff --git a/tools/testing/selftests/mm/thuge-gen.c b/tools/testing/selftests/mm/thuge-gen.c index 622987f12c89a..ea7fd8fe28763 100644 --- a/tools/testing/selftests/mm/thuge-gen.c +++ b/tools/testing/selftests/mm/thuge-gen.c @@ -4,7 +4,7 @@ Before running this huge pages for each huge page size must have been reserved. For large pages beyond MAX_PAGE_ORDER (like 1GB on x86) boot options must - be used. + be used. 1GB wouldn't be tested if it isn't available. Also shmmax must be increased. And you need to run as root to work around some weird permissions in shm. And nothing using huge pages should run in parallel. @@ -26,8 +26,7 @@ #include #include #include "vm_util.h" - -#define err(x) perror(x), exit(1) +#include "../kselftest.h" #define MAP_HUGE_2MB (21 << MAP_HUGE_SHIFT) #define MAP_HUGE_1GB (30 << MAP_HUGE_SHIFT) @@ -44,11 +43,8 @@ #define SHM_HUGE_1GB (30 << SHM_HUGE_SHIFT) #define NUM_PAGESIZES 5 - #define NUM_PAGES 4 -#define Dprintf(fmt...) // printf(fmt) - unsigned long page_sizes[NUM_PAGESIZES]; int num_page_sizes; @@ -60,28 +56,15 @@ int ilog2(unsigned long v) return l; } -void find_pagesizes(void) -{ - glob_t g; - int i; - glob("/sys/kernel/mm/hugepages/hugepages-*kB", 0, NULL, &g); - assert(g.gl_pathc <= NUM_PAGESIZES); - for (i = 0; i < g.gl_pathc; i++) { - sscanf(g.gl_pathv[i], "/sys/kernel/mm/hugepages/hugepages-%lukB", - &page_sizes[i]); - page_sizes[i] <<= 10; - printf("Found %luMB\n", page_sizes[i] >> 20); - } - num_page_sizes = g.gl_pathc; - globfree(&g); -} - void show(unsigned long ps) { char buf[100]; + if (ps == getpagesize()) return; - printf("%luMB: ", ps >> 20); + + ksft_print_msg("%luMB: ", ps >> 20); + fflush(stdout); snprintf(buf, sizeof buf, "cat /sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages", @@ -105,7 +88,7 @@ unsigned long read_sysfs(int warn, char *fmt, ...) f = fopen(buf, "r"); if (!f) { if (warn) - printf("missing %s\n", buf); + ksft_print_msg("missing %s\n", buf); return 0; } if (getline(&line, &linelen, f) > 0) { @@ -119,123 +102,143 @@ unsigned long read_sysfs(int warn, char *fmt, ...) unsigned long read_free(unsigned long ps) { return read_sysfs(ps != getpagesize(), - "/sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages", - ps >> 10); + "/sys/kernel/mm/hugepages/hugepages-%lukB/free_hugepages", + ps >> 10); } void test_mmap(unsigned long size, unsigned flags) { char *map; unsigned long before, after; - int err; before = read_free(size); map = mmap(NULL, size*NUM_PAGES, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_HUGETLB|flags, -1, 0); + if (map == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); - if (map == (char *)-1) err("mmap"); memset(map, 0xff, size*NUM_PAGES); after = read_free(size); - Dprintf("before %lu after %lu diff %ld size %lu\n", - before, after, before - after, size); - assert(size == getpagesize() || (before - after) == NUM_PAGES); + show(size); - err = munmap(map, size * NUM_PAGES); - assert(!err); + ksft_test_result(size == getpagesize() || (before - after) == NUM_PAGES, + "%s mmap\n", __func__); + + if (munmap(map, size * NUM_PAGES)) + ksft_exit_fail_msg("%s: unmap %s\n", __func__, strerror(errno)); } void test_shmget(unsigned long size, unsigned flags) { int id; unsigned long before, after; - int err; + struct shm_info i; + char *map; before = read_free(size); id = shmget(IPC_PRIVATE, size * NUM_PAGES, IPC_CREAT|0600|flags); - if (id < 0) err("shmget"); - - struct shm_info i; - if (shmctl(id, SHM_INFO, (void *)&i) < 0) err("shmctl"); - Dprintf("alloc %lu res %lu\n", i.shm_tot, i.shm_rss); + if (id < 0) { + if (errno == EPERM) { + ksft_test_result_skip("shmget requires root privileges: %s\n", + strerror(errno)); + return; + } + ksft_exit_fail_msg("shmget: %s\n", strerror(errno)); + } + if (shmctl(id, SHM_INFO, (void *)&i) < 0) + ksft_exit_fail_msg("shmctl: %s\n", strerror(errno)); - Dprintf("id %d\n", id); - char *map = shmat(id, NULL, 0600); - if (map == (char*)-1) err("shmat"); + map = shmat(id, NULL, 0600); + if (map == MAP_FAILED) + ksft_exit_fail_msg("shmat: %s\n", strerror(errno)); shmctl(id, IPC_RMID, NULL); memset(map, 0xff, size*NUM_PAGES); after = read_free(size); - Dprintf("before %lu after %lu diff %ld size %lu\n", - before, after, before - after, size); - assert(size == getpagesize() || (before - after) == NUM_PAGES); show(size); - err = shmdt(map); - assert(!err); + ksft_test_result(size == getpagesize() || (before - after) == NUM_PAGES, + "%s: mmap\n", __func__); + if (shmdt(map)) + ksft_exit_fail_msg("%s: shmdt: %s\n", __func__, strerror(errno)); } -void sanity_checks(void) +void find_pagesizes(void) { - int i; unsigned long largest = getpagesize(); + int i; + glob_t g; - for (i = 0; i < num_page_sizes; i++) { - if (page_sizes[i] > largest) + glob("/sys/kernel/mm/hugepages/hugepages-*kB", 0, NULL, &g); + assert(g.gl_pathc <= NUM_PAGESIZES); + for (i = 0; (i < g.gl_pathc) && (num_page_sizes < NUM_PAGESIZES); i++) { + sscanf(g.gl_pathv[i], "/sys/kernel/mm/hugepages/hugepages-%lukB", + &page_sizes[num_page_sizes]); + page_sizes[num_page_sizes] <<= 10; + ksft_print_msg("Found %luMB\n", page_sizes[i] >> 20); + + if (page_sizes[num_page_sizes] > largest) largest = page_sizes[i]; - if (read_free(page_sizes[i]) < NUM_PAGES) { - printf("Not enough huge pages for page size %lu MB, need %u\n", - page_sizes[i] >> 20, - NUM_PAGES); - exit(0); - } + if (read_free(page_sizes[num_page_sizes]) >= NUM_PAGES) + num_page_sizes++; + else + ksft_print_msg("SKIP for size %lu MB as not enough huge pages, need %u\n", + page_sizes[num_page_sizes] >> 20, NUM_PAGES); } + globfree(&g); - if (read_sysfs(0, "/proc/sys/kernel/shmmax") < NUM_PAGES * largest) { - printf("Please do echo %lu > /proc/sys/kernel/shmmax", largest * NUM_PAGES); - exit(0); - } + if (read_sysfs(0, "/proc/sys/kernel/shmmax") < NUM_PAGES * largest) + ksft_exit_fail_msg("Please do echo %lu > /proc/sys/kernel/shmmax", + largest * NUM_PAGES); #if defined(__x86_64__) if (largest != 1U<<30) { - printf("No GB pages available on x86-64\n" - "Please boot with hugepagesz=1G hugepages=%d\n", NUM_PAGES); - exit(0); + ksft_exit_fail_msg("No GB pages available on x86-64\n" + "Please boot with hugepagesz=1G hugepages=%d\n", NUM_PAGES); } #endif } int main(void) { - int i; unsigned default_hps = default_huge_page_size(); + int i; + + ksft_print_header(); find_pagesizes(); - sanity_checks(); + if (!num_page_sizes) + ksft_finished(); + + ksft_set_plan(2 * num_page_sizes + 3); for (i = 0; i < num_page_sizes; i++) { unsigned long ps = page_sizes[i]; int arg = ilog2(ps) << MAP_HUGE_SHIFT; - printf("Testing %luMB mmap with shift %x\n", ps >> 20, arg); + + ksft_print_msg("Testing %luMB mmap with shift %x\n", ps >> 20, arg); test_mmap(ps, MAP_HUGETLB | arg); } - printf("Testing default huge mmap\n"); + + ksft_print_msg("Testing default huge mmap\n"); test_mmap(default_hps, MAP_HUGETLB); - puts("Testing non-huge shmget"); + ksft_print_msg("Testing non-huge shmget\n"); test_shmget(getpagesize(), 0); for (i = 0; i < num_page_sizes; i++) { unsigned long ps = page_sizes[i]; int arg = ilog2(ps) << SHM_HUGE_SHIFT; - printf("Testing %luMB shmget with shift %x\n", ps >> 20, arg); + ksft_print_msg("Testing %luMB shmget with shift %x\n", ps >> 20, arg); test_shmget(ps, SHM_HUGETLB | arg); } - puts("default huge shmget"); + + ksft_print_msg("default huge shmget\n"); test_shmget(default_hps, SHM_HUGETLB); - return 0; + ksft_finished(); } From patchwork Fri Feb 2 11:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46259C48291 for ; Fri, 2 Feb 2024 11:32:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8CEF76B009C; Fri, 2 Feb 2024 06:31:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 857356B009E; Fri, 2 Feb 2024 06:31:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D13B6B009F; Fri, 2 Feb 2024 06:31:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 550C76B009C for ; Fri, 2 Feb 2024 06:31:55 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 19DB6140F7E for ; Fri, 2 Feb 2024 11:31:55 +0000 (UTC) X-FDA: 81746649390.15.92E101E Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf22.hostedemail.com (Postfix) with ESMTP id 5C677C0017 for ; Fri, 2 Feb 2024 11:31:53 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=sc6gSPnh; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf22.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873513; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VFQwNGH05nCWaWpiZ45L92UGGZtWmAJBYHuhIMWMRD8=; b=IzJeDDhnSlSVbvQVI4+/OqkCPWP6oHhZJJMhusOk3HOhVXafGhVcEyR3pnqjIvq8jHGjz8 kjxM8i6QukYlvC/nQowa+MsdzHDjqXzGjwMxcV2xm/QKjienWzyxoAV7dFn64D8sIWydPH UwGhXwcdw2nSZZ+7cBcEgzcm+x8enFY= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=sc6gSPnh; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf22.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873513; a=rsa-sha256; cv=none; b=BmIg32Dob+t62h+r8N0KqWSQbttlPXnk8Zljx8EHPNUglhdAQ2EB1aPCxKAwC+QqCjC006 urFTBxDAJLNW/HNbBlEcNdM6uR4vGbVyrMj/J5lbc2XoB0yhd3LA5/TYjLXgHXQXa391PM fZJjZl0sap9B0jrbKFaylFTfC/kCwsw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873512; bh=oFf1K2mfeMM9jrFoVwJzVfcP3pmuBYS1DF+vRN85jqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sc6gSPnhufWChQCgxwcEbOOu/Du/qXW/u+TPIiVMNp7XW2u7+5upVn8UhbSSeuUpP ATxUV7JSZ3Rtsag3QYOM4ljOu30AN8qbD+x8zdx9rb716WEZyXagLEXLEEQRJzmOCj XM5mZEq/7KTTiC5c+iD8Sgaa+rxqb7B4wbUmWVD+5y90qCpgDQy3BM37J4IBRRVuys fIiJSWbCYMiNadJj39aDIIXV5e9xbRFIMixEDQNIjjPS3bThDkUpvwT/6nodBvPvcy mgn1KhGX9rncuDvQ2Ys6L3Ma5HpYf5iWa5z95npJrD585PQ2i6tTTMgjGh2ArFWEem hXRnN4wJW0F+Q== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A2D9D3782098; Fri, 2 Feb 2024 11:31:50 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 11/12] selftests/mm: transhuge-stress: conform to TAP format output Date: Fri, 2 Feb 2024 16:31:18 +0500 Message-ID: <20240202113119.2047740-12-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5C677C0017 X-Stat-Signature: 1d5ej4gujo4byw5ni8y18ben3hfygibz X-Rspam-User: X-HE-Tag: 1706873513-409343 X-HE-Meta: U2FsdGVkX19FWX7pnybvFdDb2I99m+7V3w2xIbHLR0YoJ+ioDWXxdMmOoikafMtlxi+plTTjl2doWx/ZmYVwnwCvDlxOjJnrJURTD6Iciabwr4I4Yb2cED6sKfvj5HfpK87B4bWD/hJPEPghf8ZlrFiLOWt0fXQDsfpD1dunWTykJFkbTGRGtjNj8DiLRpQGz8Ex08Z0DZe+VB+zAKBLZ/8MUotMz4Gh1O7KzhNpPAcOo/8gx+DA3tYJ4xsyOnLmaoOgvmmkT1Cv8Dm8aEkMbYgywup0f+M4Wnx3qCLGYxAhuPLQ+zZCVU3tGy/asb2P+ZOx5KyawRk2mNh1Y8KLAaKwiWbaxTN72lHtzqwW4LpLojaBoq59mqHWws7bAFWbZHpimEd52RzvrkvFEiafxAp+dpg5v93XZzAZUUPWF/XTdFStTczxQy1wylKuGAo6ypfR6mn/hCwY7Y9ZBqP5/InZwcvUyXQBV8Qde+zbYdxySx3ziAM4U34wopotoiDri1mPi7Z3vmFQtZdiJvNrPqn0DVNAw6ABL0Uiq5YeBPnBMbBKat7cTAvnSreQfbICS5wmeEUPD9JsAuLPVG54pJI0qd+CmVbhSeaqpG6TnlnrF3LJhGJsvY2Cc7aBz6thZCpHaVb/COgo7Su8G87Cz4VCDVcN1/ou8nnbCPsF66iL1stllZ9fGKt//71ad0H3PZ+X2l4AcuZDtSMZyFBzZJDo1tH+D2E8OBGo6jnfcSuukHDVeQQgvIQFohfcSUPmfy7b3o2MgRMPnkAb1qHk2CBWPHoHK41GFv5cOD2Pe2G70SxgnVVyRePYqYtXiVcMAwM712zinMbCJXKfZdhq6Qn7i0SsUdQ2TYEwXsjmTIKnV27NCBpDt7ew+o7mz8EOIlMkfiBK9kKLl5+9hQPNOnMpn7WmqRFBvNvxa6LQ1aCCMjgZJSARpPI/I3Hor9E3mnKRZpR38nl7HkOpcfR sUmPKmdo DA2KYr+/j4BKU8J1MEzp6iQoadkA8Y162CPoGegKmYD+tcjl//5aSpeVvWDXSRu0vvLe8rOnOYQRDJ0Ab/+M3Mb3pxYYt33pRKpryedvHc6VZu++jIyHuxCWqzDH0fkQ2OFe97+DThhedRhJ2jkZXaS86EA8zcNE3vDBUrqJFwEE0lWnnMfeaw9SBvl6/R7WPQhuGVgaPsq6IV0rui0sZrgRXXMvH5lxCQPiAy6yXZFG7+5CLU5sOcOCVaw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/transhuge-stress.c | 36 +++++++++++-------- tools/testing/selftests/mm/vm_util.c | 6 ++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/tools/testing/selftests/mm/transhuge-stress.c b/tools/testing/selftests/mm/transhuge-stress.c index c61fb9350b8c2..68201192e37c8 100644 --- a/tools/testing/selftests/mm/transhuge-stress.c +++ b/tools/testing/selftests/mm/transhuge-stress.c @@ -16,6 +16,7 @@ #include #include #include "vm_util.h" +#include "../kselftest.h" int backing_fd = -1; int mmap_flags = MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE; @@ -34,6 +35,8 @@ int main(int argc, char **argv) int pagemap_fd; int duration = 0; + ksft_print_header(); + ram = sysconf(_SC_PHYS_PAGES); if (ram > SIZE_MAX / psize() / 4) ram = SIZE_MAX / 4; @@ -43,7 +46,8 @@ int main(int argc, char **argv) while (++i < argc) { if (!strcmp(argv[i], "-h")) - errx(1, "usage: %s [-f ] [-d ] [size in MiB]", argv[0]); + ksft_exit_fail_msg("usage: %s [-f ] [-d ] [size in MiB]\n", + argv[0]); else if (!strcmp(argv[i], "-f")) name = argv[++i]; else if (!strcmp(argv[i], "-d")) @@ -52,10 +56,12 @@ int main(int argc, char **argv) len = atoll(argv[i]) << 20; } + ksft_set_plan(1); + if (name) { backing_fd = open(name, O_RDWR); if (backing_fd == -1) - errx(2, "open %s", name); + ksft_exit_fail_msg("open %s\n", name); mmap_flags = MAP_SHARED; } @@ -65,21 +71,21 @@ int main(int argc, char **argv) pagemap_fd = open("/proc/self/pagemap", O_RDONLY); if (pagemap_fd < 0) - err(2, "open pagemap"); + ksft_exit_fail_msg("open pagemap\n"); len -= len % HPAGE_SIZE; ptr = mmap(NULL, len + HPAGE_SIZE, PROT_RW, mmap_flags, backing_fd, 0); if (ptr == MAP_FAILED) - err(2, "initial mmap"); + ksft_exit_fail_msg("initial mmap"); ptr += HPAGE_SIZE - (uintptr_t)ptr % HPAGE_SIZE; if (madvise(ptr, len, MADV_HUGEPAGE)) - err(2, "MADV_HUGEPAGE"); + ksft_exit_fail_msg("MADV_HUGEPAGE"); map_len = ram >> (HPAGE_SHIFT - 1); map = malloc(map_len); if (!map) - errx(2, "map malloc"); + ksft_exit_fail_msg("map malloc\n"); clock_gettime(CLOCK_MONOTONIC, &start); @@ -103,7 +109,7 @@ int main(int argc, char **argv) if (idx >= map_len) { map = realloc(map, idx + 1); if (!map) - errx(2, "map realloc"); + ksft_exit_fail_msg("map realloc\n"); memset(map + map_len, 0, idx + 1 - map_len); map_len = idx + 1; } @@ -114,17 +120,19 @@ int main(int argc, char **argv) /* split transhuge page, keep last page */ if (madvise(p, HPAGE_SIZE - psize(), MADV_DONTNEED)) - err(2, "MADV_DONTNEED"); + ksft_exit_fail_msg("MADV_DONTNEED"); } clock_gettime(CLOCK_MONOTONIC, &b); s = b.tv_sec - a.tv_sec + (b.tv_nsec - a.tv_nsec) / 1000000000.; - warnx("%.3f s/loop, %.3f ms/page, %10.3f MiB/s\t" - "%4d succeed, %4d failed, %4d different pages", - s, s * 1000 / (len >> HPAGE_SHIFT), len / s / (1 << 20), - nr_succeed, nr_failed, nr_pages); + ksft_print_msg("%.3f s/loop, %.3f ms/page, %10.3f MiB/s\t" + "%4d succeed, %4d failed, %4d different pages\n", + s, s * 1000 / (len >> HPAGE_SHIFT), len / s / (1 << 20), + nr_succeed, nr_failed, nr_pages); - if (duration > 0 && b.tv_sec - start.tv_sec >= duration) - return 0; + if (duration > 0 && b.tv_sec - start.tv_sec >= duration) { + ksft_test_result_pass("Completed\n"); + ksft_finished(); + } } } diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index 05736c615734f..5a62530da3b56 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -232,17 +232,17 @@ int64_t allocate_transhuge(void *ptr, int pagemap_fd) if (mmap(ptr, HPAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE, -1, 0) != ptr) - errx(2, "mmap transhuge"); + ksft_exit_fail_msg("mmap transhuge\n"); if (madvise(ptr, HPAGE_SIZE, MADV_HUGEPAGE)) - err(2, "MADV_HUGEPAGE"); + ksft_exit_fail_msg("MADV_HUGEPAGE\n"); /* allocate transparent huge page */ *(volatile void **)ptr = ptr; if (pread(pagemap_fd, ent, sizeof(ent), (uintptr_t)ptr >> (pshift() - 3)) != sizeof(ent)) - err(2, "read pagemap"); + ksft_exit_fail_msg("read pagemap\n"); if (PAGEMAP_PRESENT(ent[0]) && PAGEMAP_PRESENT(ent[1]) && PAGEMAP_PFN(ent[0]) + 1 == PAGEMAP_PFN(ent[1]) && From patchwork Fri Feb 2 11:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A14A3C47DB3 for ; Fri, 2 Feb 2024 11:32:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AA666B009F; Fri, 2 Feb 2024 06:31:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 831CA6B00A0; Fri, 2 Feb 2024 06:31:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65E736B00A1; Fri, 2 Feb 2024 06:31:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 428506B009F for ; Fri, 2 Feb 2024 06:31:57 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 18BA3C0EAB for ; Fri, 2 Feb 2024 11:31:57 +0000 (UTC) X-FDA: 81746649474.30.C3F38DE Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf04.hostedemail.com (Postfix) with ESMTP id 4D5584000C for ; Fri, 2 Feb 2024 11:31:55 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=5jrbRNKk; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf04.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873515; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=asUANzFqAgLjH6ZwJV82sNijZ4nVe9PH98JXMjUtul4=; b=NyFWnxZa2iyY5zGdtaBTuulGETlEf19MXQ/4NAO+tme4Dhi+FdlQk67R24wslDHTz5krEh XC46E5ZIKBp1RYVg/OVqaUJcQJAgNI7mfQzP9+JeEXO0vJn1pX84UcW9mbrDFXKu7eT1CY B7YFZwcLDEtqR7LgdfNLV/+4/cUWeZQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=5jrbRNKk; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf04.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873515; a=rsa-sha256; cv=none; b=jUKb+zF4RR8YfNCAkjzgLbJLna/spGDxLobPqFBaXKFlB3TzE1lfwv9dnnl07l2fh5xqWy v5+Rvg0CorEo2rV7pNxkajcvQK6cDzpG67uHRdVPjnd1ennTOKyzP7KLAlm6HeRur7nmQa EsAyo1rObpabKiWmBaKCSM4Kp41HA9I= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873514; bh=2kIkJOhTpv8Q3QiyGfqRKh0McTWdwjht00wQfRsByJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=5jrbRNKk2culQ7Kp1jvUG6aqXkgZGNOc8qXtU/77rVinmrrbF6j5UzkcypE4v7SzV 1sO8jFCGmlohyfABEMbYhlNulnL3KlfpqyHBfy8y1i/Zysv5SY2cws+zuUO7/7EH5n b2y3r6zBw0bwETOeTG23b0P5VWzHBbFVkVGy9K+INzWMymN+6GtiTyy02TbgBLQeSP uleeXDj31LR55nOzdR8Mn620o4NbUmjDKcMDn+Y4a9dbP5SDECDwTpSO8SYRdlJoPm eS/hqInMh9SclMZCxfJsspNL0xSJctOq5MgTF/S9RMtyVOTL8wSS2vZpuLE/04MbBD Q5sERtgWJq9Pw== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A3C913782099; Fri, 2 Feb 2024 11:31:52 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 12/12] selftests/mm: virtual_address_range: conform to TAP format output Date: Fri, 2 Feb 2024 16:31:19 +0500 Message-ID: <20240202113119.2047740-13-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4D5584000C X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: mxswqsf8b9ororef65uegj6sgudjzixd X-HE-Tag: 1706873515-12123 X-HE-Meta: U2FsdGVkX1/9rmEMbnAJ7xi2J/c4cEwH26LNiSP2PFW63KxBq2m3iktH0To8O/MdJVNFDbHHrgF1WaEobvjACi6Yoy0bJp85HHY1g0jwfiXdFqfT8qgkAxWweUq8tuHAv5eoAKvmTt6UwMQCDv3GGkXy+gzddAta+MlKhWtMm/H1uFphsApWd9+JqR1TmlFcJLz/flT9O1EA2hAFOoLHV2bfLWLFMps8lTLCFejyaKDgaT1pKRn7UoudNitTztjAV5j7HyXbxLVamRev/pXu6RVcbSJ8JfZGJmKtCQ2QZAj3BigcKxQsKU+TuODrqttPr410ez7dq+9zv13P2V5FxVRuasiMCCb6RWarU509D+jVkOeb56RAYXM/9l+0ZzIolnA5bSPDwVllXbntgrg3iL2xD0D7fXMUkbp9cI+1gQgOGr7jUGf2lN1IW13THCpWqTsZwonfOX6YTjXKt8LugZk74lC70jf+ARY3o91SLpPChEK0oUe7E8lu3LOdUbHAQiqYT6t8LS2Q65cmRXU4UQ6gBSPuoPNM9nFO0ozAciG+WWXK2tgtRfkYoj8G4wwrttbYA5BF+n4Ot9x1pWvI51KeTrwPcSVN3FOMV+8XKVvYXvPPalDuSHwuAJwxQ3JWgUbvBq23JBN9qxFFnivafizmCvtyFB/aGZZHvb4T9ciuPpf23Ym5mukDhQXOIMk61YR4T5UpcKUUT8pomszt/OIpNi1Vh28wj5Yx3cLkV5cz9Rziq5Wj6+rPNp32lKTgG3mKkbJPmHwQGddyyUgd0J2trPClk0Tbp2kxItAsYVNWn2PkMtXeJVbJZVxEdA99kr3nq+mW87niVeJUeDeRzTBbkKA3/WYrmESB/wRrIjUy8mQ7Uo07kJ4MFmr7N8GwQkMIzyAzWWbcj7N2riKbOEPpkF0YUZkXdT4/P+ShvpB3+tR93SKZ2ILDx9+T+Yk80h5YRGYyZLEoNbVvJMs MdnujepL GdRYFZycZw1JMdIZ0Y9T4FE1jBEzQEOLgJdARkE0wmxCFgE6bfs9WApaE1WBg1s6Ij8XZymgzjyTIX8Nv35HOr/Wa/GyJxXrehnr071U16ErUCv/xmIsmuxDJ3vrrV+uArIXoX+aAfacdCSjJngJUoukoAqJYROYiIHhpl0btsWJ5KGqcjGFiww6tcdYkIejsglGLTqcry2SCAz6aZOUrUe7ZtXONlTP/vIzW8Lcd+kwl6JO5huFnYOUyKiFjhQgRQ8lIdpb8ybCGipbUVbUoVIdSGW2YOb/vBRID1bLNdagZGAI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- .../selftests/mm/virtual_address_range.c | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index bae0ceaf95b13..7bcf8d48256a6 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -12,6 +12,7 @@ #include #include #include +#include "../kselftest.h" /* * Maximum address range mapped with a single mmap() @@ -68,23 +69,15 @@ static char *hind_addr(void) return (char *) (1UL << bits); } -static int validate_addr(char *ptr, int high_addr) +static void validate_addr(char *ptr, int high_addr) { unsigned long addr = (unsigned long) ptr; - if (high_addr) { - if (addr < HIGH_ADDR_MARK) { - printf("Bad address %lx\n", addr); - return 1; - } - return 0; - } + if (high_addr && addr < HIGH_ADDR_MARK) + ksft_exit_fail_msg("Bad address %lx\n", addr); - if (addr > HIGH_ADDR_MARK) { - printf("Bad address %lx\n", addr); - return 1; - } - return 0; + if (addr > HIGH_ADDR_MARK) + ksft_exit_fail_msg("Bad address %lx\n", addr); } static int validate_lower_address_hint(void) @@ -107,23 +100,29 @@ int main(int argc, char *argv[]) char *hint; unsigned long i, lchunks, hchunks; + ksft_print_header(); + ksft_set_plan(1); + for (i = 0; i < NR_CHUNKS_LOW; i++) { ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ptr[i] == MAP_FAILED) { - if (validate_lower_address_hint()) - return 1; + if (validate_lower_address_hint()) { + ksft_test_result_skip("Memory constraint not fulfilled\n"); + ksft_finished(); + } break; } - if (validate_addr(ptr[i], 0)) - return 1; + validate_addr(ptr[i], 0); } lchunks = i; hptr = (char **) calloc(NR_CHUNKS_HIGH, sizeof(char *)); - if (hptr == NULL) - return 1; + if (hptr == NULL) { + ksft_test_result_skip("Memory constraint not fulfilled\n"); + ksft_finished(); + } for (i = 0; i < NR_CHUNKS_HIGH; i++) { hint = hind_addr(); @@ -133,8 +132,7 @@ int main(int argc, char *argv[]) if (hptr[i] == MAP_FAILED) break; - if (validate_addr(hptr[i], 1)) - return 1; + validate_addr(hptr[i], 1); } hchunks = i; @@ -145,5 +143,7 @@ int main(int argc, char *argv[]) munmap(hptr[i], MAP_CHUNK_SIZE); free(hptr); - return 0; + + ksft_test_result_pass("Test\n"); + ksft_finished(); }