From patchwork Wed Jan 31 14:05: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: 13539489 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 144AFC47258 for ; Wed, 31 Jan 2024 14:05:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 97DFE6B0088; Wed, 31 Jan 2024 09:05:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 92DA66B0089; Wed, 31 Jan 2024 09:05:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7CEFB6B008A; Wed, 31 Jan 2024 09:05:20 -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 6F3026B0088 for ; Wed, 31 Jan 2024 09:05:20 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 498BBA0D6C for ; Wed, 31 Jan 2024 14:05:20 +0000 (UTC) X-FDA: 81739778400.03.DD7BB7E Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf21.hostedemail.com (Postfix) with ESMTP id 8CF811C000F for ; Wed, 31 Jan 2024 14:05:17 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=hVRTdRod; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf21.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=1706709917; a=rsa-sha256; cv=none; b=v35yFxxXgfON7o9vgVWuB6AD/8v6gqNdZaCrPQidDMaBwCT/ZBxIvBquGGpwchqGx6HcBb 6P1v5IDIUETHEcLy4wb7o1iyKDEySOMYnwZnJ6YrxSYw/QAI7ANw5Wksq20NUfFjKG2akn 9d9dpgFQ8aNCmi81DFGORoIqI23PB4g= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=hVRTdRod; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf21.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=1706709917; 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:references:dkim-signature; bh=rs3JITGukBvqtMUpSjOqaaofsqqmPPqDr32jEpjdRB4=; b=t3QEgCiv5jBFYVRR/o0WOAq6INESMGEYuDRS/Td6q21nW+UCttIqbGzB0svWnaFKp0J3zh yHizOhZ8CiT2CfQxAz9GYD9S/+YGs8USHKRRJvnIB1shP2SkjbVAzgXsLIsDt0QTbwPRg/ 0l7Gkiqrc6Zd7hHGfR9jT90FZrcpbFs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709916; bh=C1jyyNN3WoASzPdbjbyMPpmrKLB566vijGdtqZFTW+0=; h=From:To:Cc:Subject:Date:From; b=hVRTdRodufiiXRyUTw9piPgw/oM92aLsJkDJGNDDTsunq7gJopZrnj+e3uqM09Ifw k0w0zc9ThSlxrYjasOBccPbbcGyeFCFKGuOcVC5KieK9Sp4aGF33D6MfyXTLlTrZyb dhTHrGWeb4FM7XQNVxruHPijt+Fkg/nEm98o5ebb8XFF8Qt/cXkO4XSlC3ndGxv0S2 oqaGai6ttvc6I60U/yqwE/TZ0j0LPMR46ap6XGlfAdWeChx84aXANCMFs6mYsw70DT FjeAPcOuZmZ8KNZfI5GISi+BwMX4fEXehcftq/U7JIgfeAVesXIjXx8CTEtZ+dnC9a BsGRGSxhSpIMg== 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 8243E3781FCF; Wed, 31 Jan 2024 14:05:14 +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 01/12] selftests/mm: map_fixed_noreplace: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:11 +0500 Message-ID: <20240131140528.320252-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8CF811C000F X-Stat-Signature: ytdxp7euotbrdrdfwir6eaita8xd9saw X-HE-Tag: 1706709917-257162 X-HE-Meta: U2FsdGVkX1+kmeCJcFK5ZphPj72Fj/brSKscrs4KOfnVi26uyLI1rgCkUFNt1JWhSHBbdUbtuzfb4J6Yf5OzH/ZMqR0wAaqha0qT5WHMDbFAZBArXQcso3bGdduefoOHUS0jE6AybRFRk2IEOwv9WFpOi59fuMaLmzonvjsXK8tW5v7rgwJ3WtHiHaIZpvbpdjHrhiZqrQS5WsA2kOk3ajjmlnkqJKfEkEcF2PEHw/qcJz+C0TnA21Y6xe8j5tJKyZnmr+FLqEJOMLXysB4V4BhOxSo24WFUsD80zMHcc4L6GfUwnryhaH7zS0E1HTZzyTz2tEZ0qrLGiuXKlYi4CLwIjP8J8qr1VbE841w1MQhjl2gQvTPLqpAo7mIRJj+njLlq7qNsP08KJEHBRd9oqonZZ8XaMGXP7dGf5B5zQypYNTpxSWubts8rKG5yGNjrtBL4ZEvhiEe+GhXfV7klYmYfZpa2j1l6jOQRF54gxK3GynwqZ/lroQ9ahnRTsU/pjo0LW3A3stj5A3QIVQEfju5XzX4PK79ucslat1tGEsbHgIy9400exq0p9reSshyUta9qxi4cc0Eokp/PJaZlJQN2s6BeyRLFHa3vqIdDqcwDMQETeioaH4/pbgksbnFLHmuTMBi/9L9kvNRxGf86LZdaB1POFaY1lyBg6g0HuQ0pgVrpWd3EewpB8w/ZYzCf3FdetqL5QHRYl3b4BeE5mkY2Yw3SowGJUpYAY6B9ddTHJOoffujAQa2P/2EKN8fe3wyynKSDl32WvjbeWRlW7A41N//sThYaZpIhb+HfcIhaX7ZZmIKMjAuMqF4fRh0ZlGMH2qVK89zDuFGqDieCh2aglMfkeaC0hiT5YK6CPspsOjlyggZXflRBJ05fhGWa8Adz26/cT1qLEcB281h0W5jMCRESTEeAZhHTktq7K5pyt68EC6GEqinaF1oIKmy1u7OpjZzqeRReQ7HlM6B bOjpXCtJ G67pzqMXzcsmyuo8/8aoEUy/VbO4M7Q8Kecdxt0oZibpQNUSyp2jDGxNTB9KM7eQ7fRrxYXxomxUpOTLjzWXDuwxMD/NmMaUARVRnEJ/ULOylKlxxc+xxeSjTOyQbEpT6LnENQax+6JY5oJh45TO3X4vsv/RinAkfb+CkGgwkP/LrTbXNCIwUdvqEo1heB9iyxUoC43D8I/c/Hen6zri1p0m4+V0ds+3wibFWbMCbpe2daQClMuir5kGX7eKhsy1fkkrzS4EZdsf6DbQYUljKy3BHMYeRVdqYmwj6pUhGhYfT5tk= 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 Wed Jan 31 14:05: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: 13539490 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 C48D0C47DB3 for ; Wed, 31 Jan 2024 14:05:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5AFCF6B0075; Wed, 31 Jan 2024 09:05:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5106A6B0089; Wed, 31 Jan 2024 09:05:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3B0776B008A; Wed, 31 Jan 2024 09:05:22 -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 29ED66B0075 for ; Wed, 31 Jan 2024 09:05:22 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B26A2140D3A for ; Wed, 31 Jan 2024 14:05:21 +0000 (UTC) X-FDA: 81739778442.12.AEE8A3D Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf05.hostedemail.com (Postfix) with ESMTP id BF46510002E for ; Wed, 31 Jan 2024 14:05:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=h5UcZbpz; spf=pass (imf05.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=1706709920; 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=xuKgxH7pc9HSel8SIXF2SKdiHKWQYFr28hLIX4Ao/Q+XOnMk44ZdUN4r2rBwGyXxfl7CDp NDMWCKDWz7Vg0+c3B8YYsyKKQnrIxT13Ro0XHuq9FJGgr6SgL7FfT5tBiDEk7M0mYzZ9Xw ctIukx9Uy9Q4fFAWRuIgt4d6Q6xaFio= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706709920; a=rsa-sha256; cv=none; b=edn3hSpvmE5qnB/hcDYx5c/C/E0CaV//eAk0xXSPOmB2gudl+MA5kw6VEUSZ9Rp0o1yBq9 QyOr4UDZBkM4B+wYawgiVGj6zIQ0RZls7sTMcXuyss/gGfypSE4QnhVe71+5wJunSggtv1 m4/hEuOOZPHDm8UY8J45RgSK+vgSqp4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=h5UcZbpz; spf=pass (imf05.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=1706709918; bh=svTlCA3lz9tOssty2sVCUQ4b7cMa6+0k/VLIT1J7+9U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h5UcZbpzz5WlVb6jsielorPLdi7v9/5hx+xUipMprgD+tt9/1YkFLdd7AoC6TPQD2 NcHFBo3gJQVxh7DMj5VVABkH8bWv78M2C/pj4/9cYseG2EGjirR5Ge6NtKUmIO+Lk1 HJDbWdNJx/ipBXngFurJcHtqlDx+MnfotdHuxskbV+P5KCqGTnzjfR2vaV2sqXjP2s XkvGMKGKGgioz+Yto7G22wbUCJKIJ629n4HIFURwALHAb7kBdlNkoMlOwxXwwixab4 mqjs6T3SNxuWD0Xuz5r8aX3sdSIZmlPHXu+180DZ14ycRcfzHfHHRyh18Rw+hDbzYD gmQBMl4TqlH1Q== 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 D3794378200E; Wed, 31 Jan 2024 14:05:16 +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 02/12] selftests/mm: map_hugetlb: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:12 +0500 Message-ID: <20240131140528.320252-2-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BF46510002E X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 5u6wrgxogiy1w6fdqwrmuagooi4419bp X-HE-Tag: 1706709919-531527 X-HE-Meta: U2FsdGVkX18OdIxi5sQDu5Wh53REuvRDIyQRsMKu5fT7SSqgeaIUKt1CR1Mvfo3Wl2pUGyI2F7+aLS7ZiaTxasmCTaSNipnF68zd1qmyS3P491pP3PgJzVytvB1FFp4YnYI6qZF2xWQYhQ6NiwOw5HnwY38mz/FHPSGy1h6gnxXYXBncOiMvF0SaMdPEc2MDU8PVfXtwOb9yVy6XwzT82tECqy3+BzFp9mAhA/ecHAMTsAm8E1e1L8tH2b/BfJh7ClrlK309KkJX49hbYBUolzN/5LYQmQW1jFOwQqcMxCFIgVOFwr4lJtcIXCaF6a3QhrEvprnLYVwpF4l8ZTE/z64CsB6a0PlIfbrbFee1nSIk4MFj22jB8oJDwSCdkfiynXCvTXpXMAMunDZj71POzcW10Hrtef4YKCrRXYoPAKz3u/5+X36heqZSrjOqgGzhHNmnetCvyTk9Hzlavk8fiBtsC0MbelhAq+nue4kgUhxGOTF+Av6I6GsDsKmADXrjpUwhPgJEyhdwgiSPZQhRY86w88P7yR8L3f7L8g+1MMT7zXxx7fTja6+ASNmpElIjh6JaYIbLc8sqNmYgv37UUz1hpHe4WRwAVrFavFrVayqh6OTtGyH8PQCxZGjdwvnOOJQR+l9Xy8TlkLsYdODN/P1F7DV6L+PqaAzvR1/Bh8fOrsJIWUNZqTIle60xNrFYDJkPhcMCbu5HGWSIqbjs8EepKBhQbtvAul/EigvvQ5mTkSbuaBoUgdtnzvmhXGH6wqm5EnYspRYjjjpkz8qp/tBQPmolCODYzJRaLDEsawWVUUhk5bfaSv2Ui3d8nhUtN4jNuUQWcO2gcDTPzMEWei0YcQQPIFmvdFAmhE0Ne+rxfebvYennVqmuDrm/h1c4PItgbyrbTgfI0Ygq79Y0Q0qQ143KnIAOgzFt2MuhJoud7EPxgK8BsjgbYxnc+zPcNwDZnVL8uUmOYfBBSkB H/xrVnf7 doh/wR8azsjPzmvkJkEIRuuPfF1c+BHxJ2mLQote37G90RiWFSL7emFmFmTnVlbg7iiZZzn3qSc4W08dQ0WQh65XWqsQSrdlpS6nj1B2X/S+5L1UpdW2roqyC+mciZ1TfYAUBdz2rGUYcNm2ISEQZCzcqMK0e3OXbgGHPOlElzPMRNLqI8x9VfEF4kHFks8X9apLKVF2U+v7vc+p57oTXCnUEpkSENGlicYKGqUT2lEEjZgIP1m1jawm1aMSDslhmo+trbZyoGqUof32khwUYzky2MJ8cqn3KZLMCDZyjX3axtDg= 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 Wed Jan 31 14:05: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: 13539491 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 EAFA2C47DDF for ; Wed, 31 Jan 2024 14:05:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7867A6B008C; Wed, 31 Jan 2024 09:05:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 671686B0092; Wed, 31 Jan 2024 09:05:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44CB06B0093; Wed, 31 Jan 2024 09:05:24 -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 2C0596B008C for ; Wed, 31 Jan 2024 09:05:24 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C9E2E160D66 for ; Wed, 31 Jan 2024 14:05:23 +0000 (UTC) X-FDA: 81739778526.04.299402D Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf19.hostedemail.com (Postfix) with ESMTP id E51741A001B for ; Wed, 31 Jan 2024 14:05:21 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=TydsDK21; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf19.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=1706709922; 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=K9NDyoXAo9J+1CYXUfXzYn7tlyWQx1aPknKVuDX31xPnd94tXtr4IWQgVkMOLuuxFf9sMD jV2Ist9ZxGH/+rKbgRiCdK2DGm+J+4fDn+HtzZAVBgq7BhTwZkZm3h6GRlGpprFm3P2+C7 L6bhTwlnQkMHHhdIu53V565F8tTjpX4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=TydsDK21; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf19.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=1706709922; a=rsa-sha256; cv=none; b=UDluisjbhaS0Bw15yzwtl6mG4Lb+hdmua5JMVTq35ZSxYeKl0YdhQ1onYJ4rhEFIJNnMGF t+OnBCKrnaQGZqW4/fAkWM6Mp6Md3SY1+JhrDKIplUaA6lt+q5g5T9VeFXZvZbQgqo7/C0 wFj2nxfCaQ/7wCms+kNS3zvgEcTExa8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709920; bh=y0GUUHT+6utzfuC41fyJPiGU8siNhU+amnQRcBTcLQo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TydsDK21IR1M/HEfLjaeAwPydIwVfgkYpQrRlisH5h7CKSnNqUrb8yLIaTLRtOGA3 vVDlayJJdepGiAI3j+/jmvU6bDTp56gAypnE6+MOb0uHymoOqGeqmeuorjZ/2PQ+O8 RLHJSPQsUIo7/+DEtNeY4tS5C85g/3dj1rFS+tFPgRRTwHrP+kXUQIFR3/0n8ZPIsu duAdQ2xfWrtvfokjkM6j3YKfBuNV2AeMsEWurRO8JP5roaHDHMmLVGT+/0mKgJ8GeT Rzo6OC9pHLIs7wyO+9vXJsSgR60MmkF7EongLPHeimgLfDBJnQ8bYZqku8/S64keYD RKMnARJQo/C1w== 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 431C53782079; Wed, 31 Jan 2024 14:05:19 +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 03/12] selftests/mm: map_populate: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:13 +0500 Message-ID: <20240131140528.320252-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: E51741A001B X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: uy7w8ywr4p4wumqx65j93tux3imq8rq8 X-HE-Tag: 1706709921-989931 X-HE-Meta: U2FsdGVkX1+KwtL7/lQpvr1Up/3vcDYlv6os7wD2HJVhHkRZmpCSP8qNJHG+rFbVQ1/mD6Ru7azeJhYjrJM6EbkoK9K7ysFsKRjxafcxYk9vj6kzp/1fll+5Sud2dEONHUiEgIq2DUc8BL16IAb8UTD41pQj9z9ePrhyJq+mqDpquTPKcFk7yVSWE4YxXrJ6OE4rrxBYXlExXAjsS+Z1FrWI4Ncsf8pUxE0obn3n7OUgFwB2aEnVLuUAn38ElnNCWwLTCuBr142xPxXLY7d0iJPKyp9o8XwqvveqZ3cfH4fm/H2r+Z9BoY+pA9VuDyT1UCFybjllUaBb30holU+krykrCNubGYcBgjvEjYuNNMQNOtb08A4a1hYfuA/1JTJJH+X7IQlvQY8Dmvg+yRIpgYXyzrNeKAPi8nneHkA209Oy0DnixXjOt7DjHtU9Sb523GjbV07mG1EPuBodiW3saouYNsztKRjSHHFAKs3XfP7/8ZnbtLG0kUS4x2U4IClb7SqaJ8WACFiave2MF8U9OK+cg1hXvNBCKdjk159WySMR73pS8Qfuz6QFP8L7eJGa9fTC9NEe7kwwejU9NRDrBVL1PGctEYhat8rpgql0Cx+kDzPO/bacd4siWZBn5+ckFcjWmW7k031VOoL/wf3jwTCXEtXhQIqo2gbNUGsw0g6E66bKFTeunyu3N5l6YTqchxedI2381/KPeiO0Eh9J5607UtTWeNSHLJBcAV7Tl5KUXC+s2lvhW8nY1wwwE8yh/V1BozS9ixDtcqlIVm4Z6T23FdH5uChqodDnb58FQguMDPF/FcjajjldG114tzTzFm4T3tL5pUfxzBDSivPfe2pEStosEdcYatHF5kqB2I7wLUVnCg/390XP9mUefKago6uZNInO4FsX+2AKL9/f6yMM0E+qE+Yr3yaHWv9ZIwFO/OhNZuUcx4ZTOyf00LjCl9hyVgUTvJLjlyUpl61 tGXlrtUZ xwmGKeMvuyiqBUBK8NNRo3rALQ6GJc15lLG0u2x62MUP+9IYCVhbx4dC8u0rtZgK4ymZHjm79AevsGlbryRDXW3V/f6jScvrKUA76U6yG6+QMsIrBcwOwzRdBaJcFgyphgE2p0s7Edo6QztDHKk0iaJWjxCkD5V/Ab3LV0k3fX0zJkAYdTQ7dTVqPFh2lqUEFoQaKadKRbhtyJHP25cGDIxUMJSa9PIKCtiHv+HtAg20GKQhufgf271XeWl892etr/lxSOtNZ/mb6Of9sT3ZwLpyNqvMQpDYqZMiU1aT0fAGCbb8= 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 Wed Jan 31 14:05: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: 13539492 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 C7DFDC47DB3 for ; Wed, 31 Jan 2024 14:05:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A93686B0093; Wed, 31 Jan 2024 09:05:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CDC06B0095; Wed, 31 Jan 2024 09:05:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 845196B0096; Wed, 31 Jan 2024 09:05:26 -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 714CF6B0093 for ; Wed, 31 Jan 2024 09:05:26 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 045A5160D66 for ; Wed, 31 Jan 2024 14:05:26 +0000 (UTC) X-FDA: 81739778652.01.9BCB5A3 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf29.hostedemail.com (Postfix) with ESMTP id 41BF6120026 for ; Wed, 31 Jan 2024 14:05:24 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=MACRpNQR; 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=1706709924; 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=6d9oz/x6OdJhyrimiDDxXgXwYu2XlYmkFjL+x8NbbBJ9aqXluVI42KIkeVG/FhQvUA1MXV aGlPuz5UcWeKFYPLwGTRbHVRXvRoAqUoMhMFSPjHWZFykJJ+NMk1xBa+nNLmQtzJv/sIH5 HwT4zFkRPIsQbIxJyN7tk4idYZtjxEM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=MACRpNQR; 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=1706709924; a=rsa-sha256; cv=none; b=oqR9jUYBNIXSN+ykY8cWUnY+0swjm1erVo3INRJL3zFB0FkUChbgV7OBPDvRppoIcUqPWN EeZlF6p4HysPqcYmVWiyITYbqdqea9pBQXK9koLclCTHX/VcRHJFhHQYMrwQLTmkquxWj4 iKz3DhDnaZX0+IBOeZcDBvpARZHbjRY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709923; bh=AYYPiG5/eQFpT9F2zXPDgcKcsgIGjoY5wyEFVeBzakA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MACRpNQRni2hxNtFtl0XFeCH9MObYnCAvaART/lNidK151skysiHjPaR4MZboLENO kSiZzJkI2kq3aACjopN5pOvZ07EYablIQQ8ZbPv1J5rVeVKClSoDDoqqabEv8hKQNe tJwrEM+7F7Aow/nmgzl5c2D3G5Vk03PKnxPylQsEqm2R0DUzvZfxEfpuTFzzHWJ9iX 4p3Zl8ns1zYYh5d93xBE6QgQRca+dM+UixWexBKSRzQp+LckUG8PPvV0d7o3hSwCWe GZ9zqxWUgp9pbf8g46q3WGpnY/14HJYTjCZUvXRjDDlQ8fyb8uf6B4d9/ixrxI9tXo JHuSSK3zpAelQ== 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 9F8E23782084; Wed, 31 Jan 2024 14:05:21 +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 04/12] selftests/mm: mlock-random-test: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:14 +0500 Message-ID: <20240131140528.320252-4-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 41BF6120026 X-Stat-Signature: gjqke48ce6go1k1uxct571pzawu8kgfw X-HE-Tag: 1706709924-248787 X-HE-Meta: U2FsdGVkX1+u+BLGmKje2r013MoKzqXYzINqqn5dsDWGKltj8o7BALuHRushbIjSZ5V/vbLWHp5YgtTY7V+MAAlJEiI00TOA6qFwHpHwd03lO/sXAVKuCWx5GtBVAAPAYRAVPskcYzDe/YevJNHQL+cNJn25v/nz2Bxb2An0+Mxc1AEUh+nrB6MF4wwKyDQTYv7ZnUwvc2D8sNwuqAOgxdRuZ3SNRhR1Sbqc1zbwZwMVqm4/TEhM4JQyqooDO8X0dIdk1NLj6DrSKtc2PbZW+2kVrToqVXMNj8/f8gJjeKjubCQ9gzSJu+OHycjUx8wSYNN19wHRdQs6OpOTlne4VyFWa3CTRpWsBdA58opgCEJL4TYZIrliQhP0vKllE3DvH0IXPaKADvSvmGFQGSJj8JOcqFyfQ1y/cx5AURO69UIPeg/W2iOZAhVt4L4P96SBVZXmHolyKUXsgGQoDUaMBZ5pD0D8rL4qeVDR8vbiOW/ZPhIwTYpNvRi+cSPNsa6xs8Ekj2ADikDtmIDCGuftqqQVCV1c6lvSKkQEKIEIsWQgwT68l2L+3uErE1euLSXQPgjBH7rNF50VoqketAoUP461gxSou9vicZMz1nOJxXG0WHG+QOqxmGo0BCGWWdQG4rwHAVtOJdugGe7QlvS3M9CZTZHlAyoBmgYD5w/H5KYm913vmDaB68LJrFmdW5aQq232tifYR0omc5XkeIZuRtkG89Hv4NnCebVZmFIHP2wY4wYaVvRYaZfswQxTFd75qb1iKIlczAsgi/z6rjxQ4zpzRpE/PikZ42XzSTcEZKRN24VCoLcvIx+jaU8Bfkgd+V5/7LuZ4UZRC1N44UXp4TEaX7fxWpauBb1nBkfq7SzWBfZHtz5flwiJxvy8ony0VFKWaLD5ibaOFUOmMpfvbrF1nhmP+HK3QR2LVA1tb4vlX+RrinI5YSPhh/bwNELnLHSVURvujWqUKfsHACi DL4MlmE1 SMRt54/4tMncdJrdEzlcgL2UUMnS1ckAZfAaUesxCl/BY5gasHOTE+8yL9AQyIrUDgzPso0XQ9u4k0UGQAlt/eNmS5g9/QaG11IzFEEeqpEfFPTk7m6e0BXjr2rOSbFf/TYKNLUWvLIRBsH225hLRTbWYThf2t3bR3tA1J1T8Cf5zJiL6T22xSCIvEM1prZETJx+mYd4SBBNOGqjAMg4r5/BycU8atU83dfxM6nTpTc1Drt+6jlu0e1NtOA== 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 Wed Jan 31 14:05: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: 13539493 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 617D2C47DB3 for ; Wed, 31 Jan 2024 14:05:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 86D126B0095; Wed, 31 Jan 2024 09:05:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 81D4E6B0096; Wed, 31 Jan 2024 09:05:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 622216B0098; Wed, 31 Jan 2024 09:05:29 -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 4ABB36B0095 for ; Wed, 31 Jan 2024 09:05:29 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id EB542A0D87 for ; Wed, 31 Jan 2024 14:05:28 +0000 (UTC) X-FDA: 81739778736.20.6C37BB0 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf07.hostedemail.com (Postfix) with ESMTP id 1E30F40022 for ; Wed, 31 Jan 2024 14:05:26 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=aYcFNeYX; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf07.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=1706709927; 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=D/0ymxZRrzvxWc89IMrJDuPVXUQCedliMMxOi9V3UOsaz605KVduvmv7VcPUqKSR8OqI74 2xNO9sY2rOx0nMKsS+O8zQ7gq8jU6ufRHy9B6hTbAVgg9T/ulupbTYFrGzLDWCuQrY8RX7 2BAMD79+aeXJDuEOvRTupB+7p8NuYDA= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=aYcFNeYX; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf07.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=1706709927; a=rsa-sha256; cv=none; b=vbCqJwxUxeoIs/9S5uFLGTjTNzcuSEH3RV0mCwx6XHtUOleucmjMwyHDmAETFbM5OIClik 2fw9AVKCk3nKPlfAgsBURQMjTuhoGKC9Q+ZVFpeDZ8MlqlwPPGGWEbhAI08m9/bMhuHGiE K/455RdOMIKS/tyBVvdP3CBhY5jsnxk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709925; bh=/wNqMM3jESWbi0B8UMhy6VskAZTZSdGLdkXtnfOduUA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aYcFNeYXOKcmqOMkMt34ywvrMULqiFH2mZy2hP2sn0FOP+vFVZ4SpUAfHLBung+vt jRqo9lSOBI22CGJRHuVBJOHJs2ivMSJONnV99kWDAHcuqLxQZ0qEqaz0nNtZCMd+kH qIv195PvuCf9LGJew1D2aIoCPEM6xN5w6UL4Te7Urfwyn3ARpiNsI7kFjqqt/uIJxj BNWMAUiZbvUdIOKjBQDEt6TocZ9l8TOnzCw0q9iaiTRbZSFdyt1Subt9bPJhErbFEL /aYv5KYx1bA9G0FqStUL7uO2eH0nU3Oi5RRVNvCp2JAt2krf74CKo9C39VHvbTXo1t 0zbyPd5rEHRSg== 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 3AC243781FCF; Wed, 31 Jan 2024 14:05:24 +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 05/12] selftests/mm: mlock2-tests: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:15 +0500 Message-ID: <20240131140528.320252-5-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1E30F40022 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: qsi9fxywsx1wk358stokk8hs9gzpyuqw X-HE-Tag: 1706709926-378693 X-HE-Meta: U2FsdGVkX18xEg0s95nF9OYgq2dBIh4hphRX4o2PgeGBZjfVw/fO2OKI4EWJzKvRHBpuu24YyQAOnZ9iP1dWsza2S89F0Atcs0aInKWVYfzuzMXxX/7H4wJ1rbqHi4s6s/sZt5/n4f9R5i7tve5hod2AlOFOY7IPWf2gd8vqHGYpghWmOZRPq0BiqxQSfHy8FNlrSKEPO1VCGSwOZW0PS8zJYOECpnNExUZ//f4FR8zyt5Efm/1oHLj01k1tXksxm8GclA98bFIs54dJnf9yFDjwJMdLVHSPE5XG9WYiLCu5KSOw/pvvLhnM6cJk4cPsrE6MavzIYY4nLDs7CcFSXzKp+M8Y4AoLMr9W7gDprxQTG+fhHFaNhf6uLBeeLhhDQjbz9nDig4L+n/s1U9XqE3p+gQ3Xb8mhZar5EzenYRgj3P+Oo/CufGeK/IwkdJcx8Z6H4sF1jxgrpZ4ZSTYBCwvYlJkB9iKgdFOKQdEBZK8EfjDAgBRZRAAy4G4reCD7sG6I1lQKkKLBZtOCJ7KJFMK780rXIsUF1z2dge8SUBD/6uk172igi+tTrUYzPBukzFtkuzTYVyWae7V5fJgSB4EKeEjWdEypShB9QOrAfk9g4lHTH+dIVG2BsoGreAVTMnsLcwjBlmJ6Atj7e65c1ekyEjhjPE04LPf5bljK1VMArzam6G2W9sdPinL+HDsWM4RDQA4XhC3IApBDGKo5xgTbKFAl9EUYB6w/nj6qi1uoMkDeJEXcD/Dj4e9kc7Y+/Pwsuqu2qL7irK9Vilm+BEG4h+ZWDPGXElR8yJFOU7b4mNGR+Okl0LEafTopHhJvqq9xXSCcpPHrCRXF0x3aC9aAOGSjeppVIiaJ/RLN6BaZlxjeKnKRs3Q8MMMmweUviZfz1Yebv0w2RYbumfMvkQqhQHPf7QQkB+aXI27Ja0I4RzFM3mES5WssugjL/K+tw8B3YgqZYkdwjAZGilN VnoTb5gp nlWwpe7KyDOV3h7bMmP+83gZ+ZTzB6eA9C5KaQf/b/A1GFP72497rKn/TR3Jw5r2Od6wyNrcvw7bjUKGKUAGyDd3tsSlrz6Ju3yyoNS7nsGxvuG4Oq1xPbt+3ocopii7Fp4y9S69DgHmKbY8wavfLAfoUg09GX4MhF8HjX5WKZtQMAKj8IBKr9eTH1XYRY3b46AflFpvoqvNY+q/YD/tNT2zrQy3FOG8tUQvAD0hQ4usZd6VM77S4UHllCA== 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 Wed Jan 31 14:05: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: 13539494 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 4FFC2C47258 for ; Wed, 31 Jan 2024 14:05:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B05656B0098; Wed, 31 Jan 2024 09:05:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AB5AB6B0099; Wed, 31 Jan 2024 09:05:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92F0C6B009A; Wed, 31 Jan 2024 09:05:31 -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 801716B0098 for ; Wed, 31 Jan 2024 09:05:31 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 63F08160D41 for ; Wed, 31 Jan 2024 14:05:31 +0000 (UTC) X-FDA: 81739778862.05.1C592EE Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf16.hostedemail.com (Postfix) with ESMTP id 86B9018002D for ; Wed, 31 Jan 2024 14:05:29 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ZrDnzEY3; 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=1706709929; 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=4la3S8AVpAfBG2ZJgEM34Q1zbd1VN7lXvyR4Ho/f6MGgIt4kUWpfTdWjRBeNNS0qou3/i+ 3uvD4CUa1jR1Dl3TtdDbykU4P5SkyvJYAWXli46toNFFNidZT1uCeTuz4FSXKThAmLp7zK 9fQWBZ5hDF8cWI0aWyoBh4K2CF99X/M= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706709929; a=rsa-sha256; cv=none; b=uxthI5ZbPDCdVXxwqHNkPINeY9C2uHA4sYZVHzCk/RbocX/kdWgsmnfhGRrJzoFoufPkTQ ZRXadDnOYXWRWksKgxgq50S1WHdmnwJGnbXyZ/sm8Hd3Fdy5AADD2SIWkKYKDrAEYBf/w9 aZzRtX6oVbEKEcSoRIXYLHnmNSfCDMI= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ZrDnzEY3; 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709928; bh=CPJegAn2jct8qTIbcEKKHIZ5byMY8HScpq2uBuAZ1YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZrDnzEY3rzWcjZkSa3uAcAd9BGqFqhU2OHdHPsNsJbhysLzQzaE7YLsDLyB+7FYWS Xoz0pswOQGcJE1Tau57YwdpSq1a439eI86rf3V8kch+DhoDmPAo0LJBkuDSea0mUWW I8fh0ntBg97aZHyjSrQwYDpBhAWHVhczZ95HPMiN+wnTDusYfdWvfQxuyD24FpKu7/ pua8hdFYFKUxHkTDIOaYvVQEacnCKixrqEjVsachpClsphQqL2h33y0g8tFupsmc6N 8Ih09s0cBS4PokvOsM6QONYqIWL0bU6pzbZrGsIO5FiXA5t8Y11VY33C/dUw8P5ccK Js/k2cnu2zqdw== 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 A0B44378200E; Wed, 31 Jan 2024 14:05:26 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan , Christian Brauner Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/12] selftests/mm: mrelease_test: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:16 +0500 Message-ID: <20240131140528.320252-6-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 86B9018002D X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: tr4sei8jiysq9kkmut38un85r8ji3etb X-HE-Tag: 1706709929-305101 X-HE-Meta: U2FsdGVkX1/X9vR1TxEOpFxuUDsQjHnshIDKiYh+w/KjGsPol0KAcUa6LlCOQUfzXy/6v61n/szRB5ju3kRWRH07GM9dBKFd9bZVvJGJ/REH2RyuNJwh7bExvMTLmbpojh3mG1YLtla0MF5eH2wVCxDy8xT03stwagB80RBubbqg4/FwZJhlIwmjXoVt463XVJEakUtA3/bueNg+8FEIZhe276WkNZMdb1GyP++QVFtCKIuKTG34TwQTTlk+GgMlF0FU19Pu+bcbVdSaiAxNiQZHA0lICOctxY1G/wavhm2p7DT08hGPUeWnnnuwOIeW5oedYWLi03YedNRnfhak/vkfjBDK6D09cLqXvP6JPxJRNPWRy1/DWvZ/3al9BTcicG7CfrJnpSUNyqhtFpxHBmH/DA6dUdlpXk3GdDNW/TNFyofVKV503RHa0uqqkOBvOsDpidkkNpdbng02uaiXnekfcNiE6SZAAMzvVp5RbLaLOAZZBWU4I7G6VuM2NBFyZceM0OYHqViUot7qDe6oOHFg8mQE2y215T7eGa0wF0Rae/B7fQX1kHhh5JKF7HXmpWFATsY3kRjBNueUzfzMNVT0vPl00xvJ6VjuJeq5eq8v8dd5UfIRpT/uwD3I/MK364KQe95vG95r5vkRJj9EwE63BlrPdCGJE/RpAIMHvr5F4LFSBch0ND5KCW1eGH0QtBQ3ucy61hQFJrFO0mwDktjy2WBMhUwuSwYYvi75rHWd9aF1jRKS5mY/kyepNJBbf3K9KcIcEAqVW/6iUnHq+C8K1YJpZYTiikxNzkuRfWGee07dXrmO7twqTkABB26h+wWUVl5BoPibcmchbqJGD67H14pm0b5vC5056Ok43afbUlsye7ViP+PGNXRJUBC9bph57kpvnWz383frTGMbHqpFoPTsQKoEPM+BwXn8SCjrnE01gdHK3tsTAcRnNaN4iAmNxHbiFeFl2wo8S9V xF3jeG2Z EUHjNSLhfySvGIhUD2ddrp3qB1YKqmHbbKR6GunjaxLC07ZUgej/8Iwb6xEeuZHEzDhLCZUDUnXpDik8/JTkAmQntJYdk66RxXbzOdLOqNVYhGQvV+KhQw+Psk22bAR+TX3Lu7fdrmcdQAhU5ew3+YI4+UuF96fMg5HvYaegwyBquaDSJKvev1i1r+saLSeLsdszGhT2rbgFG5AYChiUiiu/F8/19DzksDaBSxqztn5NxtTtXfWWYJdKYeDH84Oe2q1GO7saWCpLj+yWNQ6xmrmi8JgOQ9qaM32Id7PYHgmdT/ak= 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 Wed Jan 31 14:05: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: 13539495 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 8DC00C47258 for ; Wed, 31 Jan 2024 14:05:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B0A76B009A; Wed, 31 Jan 2024 09:05:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5570D6B009B; Wed, 31 Jan 2024 09:05:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33E2A6B009C; Wed, 31 Jan 2024 09:05:34 -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 11EC66B009A for ; Wed, 31 Jan 2024 09:05:34 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E49A6401F5 for ; Wed, 31 Jan 2024 14:05:33 +0000 (UTC) X-FDA: 81739778946.26.6DD3820 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf03.hostedemail.com (Postfix) with ESMTP id 017722001B for ; Wed, 31 Jan 2024 14:05:31 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=wPNX67SU; 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=1706709932; a=rsa-sha256; cv=none; b=3PusSXygpC/QR6vxCKCOzYZ8wf/h2/mUzJZkwW/Say8NND7v5pF9SYhJ2iItwESlIPY7IL +tNHFkgY7touXx04lExNwbO/0NvFGBZnIbJHD2x2WEGmzN6YVBq7/k//zx3RKlOfCqL2CA qN6c63r4K0on+ZfkyYggJ8ehLqE+RHk= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=wPNX67SU; 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=1706709932; 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=xxQip4ldsu96qDT32tlvW5HVFm9Hbkxy3GnFc9rVmLuPB5YfVhxVRXREeSPxOzs+M5CF79 wTYNlhX6uacjdleIILiII/DQJDu85zUNNvxLyF4wt6kPoCdRyND0FNZBTRSTTMMUURdYuT Ha+ECC3S0aLOjWcyOciuNRybaJ5A2+w= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709930; bh=SKE8pMm9wj80+Eluj9OfOxnVYjWtsY8duRngXOEJh3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wPNX67SUgEQLlZYrDr/wsFSlH2sQMpKUAAIRr9G3b8rq+a+FnMRWIbkXpYE0dec8w OCJ6rjTSn3Qv0BcCVx2GiSHbGl9B356zAqlDkgn8hCeAagZEatvImz3P9JFv1f61JV Z4t4VdwkAQanripUhgj7f42vjYCXsjA3u1vMrz9ZAdHn1pvHwvb2h66pIkyqvbfyWM YfM3iLrHOV4U/RXAKUFFsrvlqh8eWd3lpbac8DVkKOKoMaQwY6YnjTpgC3pUBiJ+f0 JDkQeAuzTmshNFYaErn0KJl3L9/o3yDG5Zj9RSmVk9W26bPwnQ/IS6zVVF6KEnfoIw 50B3VnnGMUaUw== 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 2BAE73782084; Wed, 31 Jan 2024 14:05: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 07/12] selftests/mm: mremap_dontunmap: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:17 +0500 Message-ID: <20240131140528.320252-7-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 017722001B X-Stat-Signature: sco53eop8jru6rgmwnseorsyckq6fwc4 X-HE-Tag: 1706709931-19305 X-HE-Meta: U2FsdGVkX1/2YwgTBamukfF625WfnuRd/lUWUSCCXtiZz43SueXxzQQLZ+ahnL6XWmE83fn+3fJlGt+0XvPceXK5B8u3xBssYDKDNSd7FyvIhWN+041NeLBLNKUwtYsCCfY/lrlMn4jHMJSWxxAGjRxGpj0uHF6VnoAHO7J/lETUdGMu9hbLgqAuY6nQtPRbM80SHazwQRMTxFPQwNmZmq+EVJ6Q8sTBacIZcWUbUzyaxgfm/+5UUetmF1OX/5AmJvHAQc0dGv5xIBB8QlU8d9L++LMBNOkO3GscfQgydQ+hYAC6GClJxkTcjxBbX/J8a5QBl/mWsEQbUGtEcuYZORuUQ33WMLQNokQ3OJwn/mIL6L2B/TiMzgiIomz7YmPtBjONSRxnLZYSxvsdKbFXMmVEk8zXbf48AeUYRMri0bmQF5fcSpDyVu+ZIx4sG3s2ldygrUpDF6ImcATjyiv8Aunc2Kzj02OFnTDkLoGtCnCrORiCf+FJ19qMyiLKkF85YjPg450SpKC+uerAp/zwIE3KsTT7UZuKOSbDN/zbhBa3qrYSx5Bo1MyypzQbIx0K+CEoOzfZ2JcYLPDFoGmkcjNYZseSQshAnUYo0vIGiz2w/s6m89P4YClV5oMlJ5NuJ1PRRp+1g0C5PL/odE6u6mauBB7ryDZl6p8d8SM1C1foJ2dGTvAbutHzZkQtKzpOf3Ys4UZq32Vgwgs7rxhGL+OPFnd9H87jxgwOg3GmsxPco2b31bKRJZ3Im3yBMJsSFrJf0LDTOApIwAp/cj7rdoWz1YVepRsvomq84TVrEsUdxFldWDqgAIGD94cUIvd1flUUzT7CB73080qa2lLFcwpdTBME2h5h0/+rXIPh4t6mbECNIK0DtHaaiVkA4g2iGbvJGtETIbgM+R0ulO1UqDkOWkndYibaibm+IJ0JEU8+CVc87Pw6TXU3U/kzxXaJey31KCJY3FDuwzHcIto ZT7fNmuR DXmrIEAohTxA5ZbUj/ofk5a4AeVYlKdIQsQJ84+/gBRQwAcnZYedZQccMqUIxbPec23bcs09ugAUCXdbfhHmly2CDWbBu7vzuoZ9c1Ghr/4b5ZTJse433zxJ4/KngHGSRDrB7uuH//wyxkBe3YbJ7JdU2rofnrGj72pGmMdan24E4wKXFY8t6fGHrAvaJG90Og1p+mU0riDy5jrfHzjY69+x4DifIxeAOZz8CnpbdYYWMAt2/LC3Z05esIRbKlyMVkn0BKCJGwhndkXJxpjWIaac7t98M/TaJ/63XBGBcUK6qvKg= 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 Wed Jan 31 14:05: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: 13539496 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 BF96BC47DB3 for ; Wed, 31 Jan 2024 14:05:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 204D66B009B; Wed, 31 Jan 2024 09:05:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 13FF36B009C; Wed, 31 Jan 2024 09:05:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFBBC6B009D; Wed, 31 Jan 2024 09:05:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id D83196B009B for ; Wed, 31 Jan 2024 09:05:36 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id AA9BD1C1645 for ; Wed, 31 Jan 2024 14:05:36 +0000 (UTC) X-FDA: 81739779072.21.084CE3D Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf19.hostedemail.com (Postfix) with ESMTP id 6FAA01A0012 for ; Wed, 31 Jan 2024 14:05:34 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=H2cvcLnq; spf=pass (imf19.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=1706709934; a=rsa-sha256; cv=none; b=uMvU8nqP0pe0DXU6LWNlwYtYa/VP5MNOumSQi1lmnBOLE1D/FoyAbwOVCpnERGIDKNi7qQ wUsdNK8pHM30Q0Ke/MOzQYiCFl3/yuUZQDdzGEZ717PESQzy6b7s+CGRE+dJNCSS6YJZHE T21WDfTe5n1p+gs40caDDuGrvLe/wcg= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=H2cvcLnq; spf=pass (imf19.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=1706709934; 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=o8hddnIjLedowfvj94UT24NgskHkFmWOQI+q/EStPySFpJV6zupJ12l63Z2iX2mDIE9ToQ HqYyR1hEFHhTdJNF02VogUVI1M3fmGSDsvNBHUJEXbf7qQBWdki0ivroHWiow35ju7r0G1 MG5vzbL1a6Bu3WFTel4JyxGKk8pCdRs= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709933; bh=phqEauq7xpk8vLg2PWuGHTlhwPPAnujnoDVOr8o/G5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H2cvcLnqDAlu9okcUlMwtXTeEVacC+q7HUFU9Bvx8FikknotxD45KIPTuAPbx7fMv gw/iqsqc+PxuDJmuXG3atS2YEWuPF763Bre9JLU6YwnYLTa0MUUc/Tv2KKfl2GhSCc 8HujmyxtJlpRD0nq0PVXkuxsNgwgDyDGWkgx9PFG0YM7LrIkShGvCVlps8Lu/8/N9s MptCP9l/dGao8Hxivm82iHbnFKKOcmicEqvIvBs2h5/1qgnAPSPEoJN6F52+OgdqBw dQRCGKRmzVw2rg4+n5UXE4lwIIH4BOfhcMII0AgvAwX30yQRWs8aDz9vI1uqaNGZZz +GbiL3LK2hodg== 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 A9302378206B; Wed, 31 Jan 2024 14:05: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 08/12] selftests/mm: split_huge_page_test: conform test to TAP format output Date: Wed, 31 Jan 2024 19:05:18 +0500 Message-ID: <20240131140528.320252-8-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6FAA01A0012 X-Stat-Signature: k9aix3hh15jnbrnr48saq5aqip9hbcfb X-Rspam-User: X-HE-Tag: 1706709934-125726 X-HE-Meta: U2FsdGVkX1+XICuW1f4kyglc50nczrPUD69lasVUjdNCYFnWf6eLmQlF8krxKRWHB8caQI+mkxG4k2GYk5Ce5k4LY0KjjWDF88tLDJMuOBPkDKHUpAe+iARYDW776HjG1NgdusMCirgw9oXHUEXgFBqcvbpLw9+Wfad3AY8gaXTAFEjk2l40rCaIC/1aVno72S1bCJ7474XIASrRMi8iDef2wWFXXQWLuIVxOWc0qvlzUDZ5ka/yhx0h4qpADx5lRFwY6UVpUsp0xHlba8Ml+yIFc22NAjEwCsR4jYQr8UxOKfCuDLHejOLciy8OpblY7scoMHVxIOry2IyeoWObBLFhZPR9lbXFloolrVh/lb+hx1VI80vmhiBrbuJsTWHzWRZRRiXCPOOzZjPQUH1Cu33LG2OMoz+MTjCvB657StBNUJzw0oF5/X0R8VN7db5nkJ9qbdBxiQIP0kP4iFRkkhpLClVcydoN0IoR9KtoO5XknoAtIhSoYmRViRonvk794heHddrJmwditNJBcaGtXYnJtlDeQ5Gi7DxJiuv3M73Drj7I7hMuso+agjB3uFWH8R8BxChxGuaZH58dF5cPnGoQfYvfLsmp68T+xhYEHne86z2IJV2pzc99LH2fdwYrIIBpPBRQTMJSQ9AwQ+e5LGm8dR/zqM/wFhROn1SLtu0znD40yIpB8KgtYZcZ60ghQd+IXddmV6y8XjDGfr2DZZkBLvVH74NMNur58md4+dL5YTut85odNsZ9B0FL2zAeQQmn071T96nHg7klo6SJEAO5Lw1ZBToD5exkg4wTh8lqTa5PWqJggExLSpTRi0u9d0QdLzLoyGsKwv4cV9iOqFFFrZBwnbFAZMlnkKALRrPDKXFGA6yg6QCXJx0fkD584JYCdbEjOPCI/6VHgqXwuGonXWiA0Nz5eVY3qO2RXO1QjIbXbGQ36OXR/bbF1KsrD9TuVOmfQnbifWYfgMC SKVBGYhe X4N2LR9kkAMWoMf4XeiXUV2AVzbgfpt6SHRr1eliox194xStViyTdqHBJRtMGzTZhNO8kOmF995RJQcbYfJtH51j+Jfh3VFyT9Ego4LgJ8aGEcSZdHHUCZxKAikIEe8uGiihtgg4k3HFBTjIlMQJucBUMPLUb8oAtXxbW4lHTNUT2QchnkKr7NWR0R74NPIuo7UdAv5q3aVC2WBWxDZMg9wmzLJ2r/n57QLYJF9hKCiP84Qe2fFO96XhhIkHAhabX9LX8baKnevvlr4Luaa0Mvw/9XAyz1q9JsA7X6wGxhN51s/Q= 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 Wed Jan 31 14:05: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: 13539497 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 27462C47DB3 for ; Wed, 31 Jan 2024 14:05:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A42946B009D; Wed, 31 Jan 2024 09:05:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9CF166B009E; Wed, 31 Jan 2024 09:05:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F7C36B009F; Wed, 31 Jan 2024 09:05:39 -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 6CF716B009D for ; Wed, 31 Jan 2024 09:05:39 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 326A71A0D26 for ; Wed, 31 Jan 2024 14:05:39 +0000 (UTC) X-FDA: 81739779198.05.7B4A124 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf08.hostedemail.com (Postfix) with ESMTP id 1918C160024 for ; Wed, 31 Jan 2024 14:05:36 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Y5pQ9du2; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf08.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=1706709937; 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=uvNiT1o/7EQWRIXAABtgHCEeHsEWTueRQvIss0LI+uBG0qgMLAsfbKbHjSHzF66ONquEtd cptfqRkGThp84GtpDhziXATibZIE/8EV0C2AUwJ8Tx6CzKQpeUcgwrPWg9JeYdGtv+E8ka 4+/aVaZJILkohGRDcmp5EpTTIU9B66g= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Y5pQ9du2; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf08.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=1706709937; a=rsa-sha256; cv=none; b=m4RJQOa1/A0kgXQMVRBQmF0x6h9omVpyxw64TySodjZZg58tsB6hnb1ql4UqPzt3JtsRew OdNpL5m6TvnhfyrZmsqAzaWJJWMGG6tsmrGIAFi/zG4hdwIM5XxrldPHRnbpBmb+2g+Msd kOwQ6GnC31R8/iZm8zmyxbx54ZewZpU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709936; bh=Qz1hYpXZ0ZArWwJNMRoiOZt8O4/weesIABzDbZYxCC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y5pQ9du2FKfMQPOxu64NoVlqah6eSuWUHY5+FBrkKanpFPShFX5b3UutJy6s/vvdA WwVo6144/79OXPuwuz9aHuk7y5vvrchSQBPaBeNGhDbxG8FNUMN8QewODzOZTt6gIQ bhFh5SO8/Vst+A1DbHoirNZnYkfpahdulHbOKy+6k/5EVuQaXJA7+x1Y2UBnVmJbMr QtuKFBQ2x3POfXWyubTuk1EbpCHeKnYvAcK8Dl40kuoScttAKMJNZVmqbSHnE3ESC8 nG3JCuJnDoyAAN0dltBDedl3XQgFUQMTC0VTt0JCvSXWuvDrSDJS+V0szzUS8LVT1A RLKaFkFqQrsyg== 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 5F4073781FCF; Wed, 31 Jan 2024 14:05:34 +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 09/12] selftests/mm: thp_settings: conform to TAP format output Date: Wed, 31 Jan 2024 19:05:19 +0500 Message-ID: <20240131140528.320252-9-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1918C160024 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: 3icihqgo1srgwn6szhmcjrgm77fyoee1 X-HE-Tag: 1706709936-898113 X-HE-Meta: U2FsdGVkX19ITCSVz9JGjnXmSsSDf8UXPceElEMuc7wl4vkxFDUvE3rA/9APEKIf7g/2qYoD0+t5XBRe2qHsZo3o0PwNY7lbbhoRm7T5rWqToFZZ2tj5HljlKHg8lJ2GTTv00/N70UAuUQ6Z4VwOT01tqKMZ+d/mFaMO+dLfhPY1vtpRfExJArq+5mJz5fXErB6FlCjV9sNVUH5ePnxT04xAZrdZ5s2jSl+bjQ8uQT3VC11JU11eCTOhFiUlU4xis0jHR2GjgeYmiNgrD7Xm9t+DphZivU0spMen8Eu4ZoM5/fo655Wwu5bc0CRH537DEZDqBvRilFU0IspPRvjK0cIh5z+3UYKciFlUf7JiXyRuBSKMY6kDwuO5LSsBqQakF+yGr7yRg5HxRfu/tS6vk7RStbSIAhE3l2RJclYPUIj6/R0UGCYGpHecblTnjzSprZXWgpMuvTtXJOMZpUK0rwdcrocgtj+/uMb0lTR4esMaNkDdeuasAHWyogAz1Kzu/g2Xya/p7F5+qId2LMfnIF8FSnjdLxT115cnqklo1JTAeu7R5Gd08hcVUC4843s9SsBEZZlZQsz8tVpeXw2JswsVIAs6jpCx+0qDtVU+nKUGyTbayKKF/xBwiSZHBnUNebkXHIwmYvecLQ+BsqG+fS33ye+Nl5TkcB1NuzHsIhuYDYXayk7pIXR7Cw7gGxY6Kg9WQXxFGCkyK5Oq6KOVVmf/l2AKh5q5kvxhKWzs/F31soXNYkAPpdbnctCCDJHIKRjWCGXZr7I8w21V2wqaavM1Ll7AMNvLhpQ+JCGUVToJclQvUd5D31JGJ8CtjLnvWz5liVGs7nZDJWvlyulbeOpL5U77g8Cea4yEsuoEnSe/LMLQNBv3+rcd03qEKFf4vZPobDnUlSdmBuzbAIgO3E8/c7yX1zb8ZsVp2DBK55ZgPJthQPbq7BAHQXx387Ht0CsuGv2PUMBZErxos9u 5AB877/n ZlLo0Mw7EreWXePe47Xzy8vh8bwhXJohIbEAeOQBRDTlnALyFPK+WhzEbFt3Ss4M+qyRN2Skb+n/mERaTeOr8ai5RRldEiI4gXh1sxTVRGaU3ZxdXSkIjl+mjhavZIxozHarISa3cJHLyuJ8qqKUChFXmiyTUA7NXpz9tSbx8ARafouvy+QLRwgy93jeBx0KWQiLXM5lfT2QrRPhrqHo6/FK7qyiGgppcdB7s+idce8/he4azMcx919rC2kr62VNZQevOUwCg0Yj9SUFDEVyDWHg6yXh25ZXYfxyCfD5kXRs5wkg= 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 Wed Jan 31 14:05:20 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: 13539498 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 66F77C47DB3 for ; Wed, 31 Jan 2024 14:05:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C18826B009F; Wed, 31 Jan 2024 09:05:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BA0FF6B00A0; Wed, 31 Jan 2024 09:05:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A42586B00A1; Wed, 31 Jan 2024 09:05:41 -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 88D2D6B009F for ; Wed, 31 Jan 2024 09:05:41 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 48D5940CD4 for ; Wed, 31 Jan 2024 14:05:41 +0000 (UTC) X-FDA: 81739779282.04.F8781DA Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf11.hostedemail.com (Postfix) with ESMTP id 743AB40018 for ; Wed, 31 Jan 2024 14:05:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b="0cZEqd/x"; 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; 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=1706709939; 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=Vojw6ce1pykMVoGh9caKSQtD9SCiM41EBhwAb4FtAt+rhQxVZ/xEqzE1ANa62JnPIxostl b0sN9iqv7i1MtAUVQQkg/8SbqIrysUCptbeXcf3lxF5BnOD8b/oZVfAPv5bkQ1mjSGJlw0 CzaIyisUk1vON1ChGmBqeJCL5B8MOhQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706709939; a=rsa-sha256; cv=none; b=E+Uwxd8HBi6rnNkQCbpfc2q7tT2AmKYn60ZHqyN8qrgOYLOZ8X1HaVOGg+wLoXFBn5DIP/ hHhm7Nfx2014OGmiSTLCCc7+hp1cL/Ecc4vGWAFCF4se1oMxfnhIR8GyeInx5YqfXOWA4m 4z8BlBjoIQdJoSNeR9Jh8gUqZGpv0Bo= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b="0cZEqd/x"; 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; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709938; bh=phT1qh4JSwaGJfIJ4Mc7ECbFwdGcURcGclR3lGXRi70=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0cZEqd/xtcCbUc8Te+lSugu4cqQorSPM5s57Kx4aC2yXDEPK7y1mnDLe6ZeB6yQcS QzgKd5h4qIlh+00kHu2u20ttHXZFx6O72qpjUQkEhA+z33Xt7vET4loEazi2e7t716 sNZsrqU1snBFAEI4AfmTfYhdCGXWC6t8T2oQTNOEr8zT2O4neQ/xL26BtxIiDRSHlH upnu6Ac3NYgZi3di2sKb36uNmkqAEhL5j28gsKXKk1f8r0qpZSRI1mcaJCGGtq6TyW j+rLhGsDmAZHGGk6Arr1KPZfexaw0O1LTEhnFne/zDwLwLycNUa7fiPJokN7NnyebT cgnw2jh75RRfQ== 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 D1F0D378206B; Wed, 31 Jan 2024 14:05:36 +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 10/12] selftests/mm: thuge-gen: conform to TAP format output Date: Wed, 31 Jan 2024 19:05:20 +0500 Message-ID: <20240131140528.320252-10-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 743AB40018 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: zj9e34nj94qjjokschqpnfyiwdroutro X-HE-Tag: 1706709939-938124 X-HE-Meta: U2FsdGVkX18kQ9GthzmH07pcEEr4D6bypWs0Amwr4rsGVkmQq+BP/ElxZ3fe6ZOOVICXI0/TIKSJ9BDZrOjahyng6d7WVqBsXhGkpJylbw4bfuQDi86ZOXoV9vTVvso4qMbcriO+QdZZRdElzs47TbdDj7RC5Qsmm+MUUFuq7ekErjjwcavM4Z5ZjkeYnbTgfyOtPpimmFQotaa02UlGkfi5AnCcCJQ7hGZ4pWeqR+MRQ0yoLNp6Su1CLyNNP1wQZCDkZXmRT0GgqbhA/TJFEp7CmTpHhY8DtERK7x7cQootDf09//mlPMrSJdSbw1wnYft04LM9czZTEYTQ6dxRlpfx/k8i8jhUgSuFV0o6+qgY1TW8FUeoCIq43d6xAfdot1g5dCmAJtyJRcZoYCaF/2ov3qigmnLNQOFlB/vkOlQ92WATG/msFpZ3fIqPmvY440Uql8eqYu7BoYRvXHp0gLTIoRau25Sf0dAwsFWIrf5RI9Jv/IDOIeTehyr3Sf0pTjo0qRl0EtS87tWu+ZLsZW8gmoOzcLmaOeJWiyXWTP4O7lepVlIoj4zPtkZ0L3agdvh2AcQEXX7AzQFxUwnXJfBJxiQCJNfWehBrT81iZXZH+KkauNMuqCgeyAJgQ8rqFgEcWpV5Kjc20dgrQVJFruGXbAVBouYSyV/bMG2lkAGrqjJzGT+l+suXd/DQJ5nvG3PeketzR7LNWV8MR7tDgLZd/MayBlpEns7/K5NcIQ/B1K5NuocLsIQ3dyxo+MMZ4fA2fEA9AGc0c3l4XNpM0cf/ukbaxsQRMl7lB7ahrgE3O6s8hOjSrTwkrMV8Rtx4PxiIpFW39DDWYHKf+zTj6SWQRXp3utYhCJJ9Y+wh6LmGty2FyDKA9kv0He/eZswvXsawq+hhJI22LWDsJR3CugQIARugI5oM0S1tkgABuO1z0naxZ8BxH+vzp/UiPmie 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 Wed Jan 31 14:05:21 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: 13539499 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 65D3DC47258 for ; Wed, 31 Jan 2024 14:05:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5625A6B00A1; Wed, 31 Jan 2024 09:05:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4EBA76B00A2; Wed, 31 Jan 2024 09:05:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33D9A6B00A3; Wed, 31 Jan 2024 09:05:44 -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 1BED66B00A1 for ; Wed, 31 Jan 2024 09:05:44 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id D3A861C1094 for ; Wed, 31 Jan 2024 14:05:43 +0000 (UTC) X-FDA: 81739779366.28.AF56CE8 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf14.hostedemail.com (Postfix) with ESMTP id 0B49410002C for ; Wed, 31 Jan 2024 14:05:41 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=3f+BaCVH; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf14.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=1706709942; 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=wn1p7kaYt7VM6qN/4yfp/4af5IMu9xV72SNygiki6Dxt127+WztMXj5zsEv0/hqh5oF7vq /Wq8bZu+dam4vo8ICwpTqVzsWWEJvP6c9M1htP0kCp0MWZ36tmEUYBv/3B1MYtvkLhRVCX E4AN6AkFTG+xR/5xe3ls3adBGHfILwo= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=3f+BaCVH; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf14.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=1706709942; a=rsa-sha256; cv=none; b=NsdnxzhBPRvgVgg9eetr4IUKC6ljkX9pZxX19Hkmy+TsEr7pu1XLv+bAuTHzfs2wPUzL+d WV1X7mDX6pGHtVhfIjSreEZilgAnwcNsfc53WkTtw+Hkxo5bgdzCOdo2Wcc077sFHgzQo7 2R6kw6py3L0YwRxPF4krvgmFMCg8u7k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709940; bh=oFf1K2mfeMM9jrFoVwJzVfcP3pmuBYS1DF+vRN85jqk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=3f+BaCVH11VOm4tY8FHrLyoUrRQ7PU62w2wjDp5L7h/Jdn4OXG4mCaiCuKGRLr7tb RPpfVphdNKWzhuFSWjW1iJtzU4WlOyl7f9eNoZI9GtjICj7Eh3l6aTIgqfMllXCJe0 eI9UrT1cjnQIG3FCqyqOflwg7Nx09sTv1sQbMfV8DeRyEGr6ZHHHDhWTAdlUUUAvyP yOCM0hF1ZMN6uXQgiCZkJLmsQ3/sYAHz0P91TtCaGz8YT0KL+OyugYk+WJAbHpgl8J 57df//bvcexHayvkMJQFhPIgQMS5VBA4VKOWZRpExyZy2XfgLXS8AwfMjcIB5M45Fc 5iU2blGJ+E+nw== 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 438843782081; Wed, 31 Jan 2024 14:05: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 11/12] selftests/mm: transhuge-stress: conform to TAP format output Date: Wed, 31 Jan 2024 19:05:21 +0500 Message-ID: <20240131140528.320252-11-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0B49410002C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: q6bhpf6xmb6iii3f19azmtfz3s9ogrnk X-HE-Tag: 1706709941-628828 X-HE-Meta: U2FsdGVkX18srxE9VSJ/SghzDTg0rE7gTUInfiFn2YNmXsLZKxrJtuG1saciricXFEh2Ub56b8wbe6CJGaBpy2I58SKwlPca0NoMwBZPqGwuS3cI9I2O7HT+UEIYm5LyNHaAndhvDQpcczSq+gnTBwF2mExb+/HcDuLMeanKQFfAgcY8xBrX0nNrn6/ycQqFo6ngbWNN5irdqBIWadeah2vkpLvWwVv7oi8PMvtCsu16Td7R2G1ohxNbZ52XT6gkRyqyWImdOX4OHqZNXhNYSzhpw+9TW3fnc6V6/PiFNYYVv9GBQnv3qQsYcWdVvUNfQG+AYReLEQ/FvWM0DApnMO2JEuORNtFxPXOfLR1g62DMq79IrotzDoAgQNDB/huFHiPJBCkJcTTUK6oRIt1hZhpNDEtqobosyOTcKxsTKGYjPUYfd2xA4eY2UDBP2sDpYZdDHukt/nwOGfzBzSiwQBrl/osIJHq725DuQENbKPfaowIWd0N6nw8sS0cZOdCeuVt/DLNq5ClxWXSHPdeVPbq1r8vIWsPKnaKveb4PvfQg8tE1nKCtTKhaDBzMJtLCAL5BIHWV8k5Sla2nO5ezgGsr/5j6nSzm/7wmsYMZ/rOlnhsu7dsacsAt9qBy058DbAZb35Z5aWAuPUVFHwT9LddoTwmsNl2IL8kvx3xbIWIGNRWOYeUfM3KrYMWcTiqpju78MoSREBICiH4DoQZsxiSrVmsfZmIGjF08NVBLzXBdGn1rs6st+kILeojLdrOr3IdqctbO4FSfjSMY3mP3wCThsiznNHjrvFeWgUy5K5bm6+7jcDj7ezjY++9nX8nC+ViT1exh/wxGCCi+Wo1RRAvfMpafBobo6YAd/2Pzd0Q0haRkvceO37SysVszvRXZuj5oVgslxqUKRBwo9ROK3sPxvEmYoyJ9sepNl8DzUO6/8oafUab3erV5pXSg0g60oB9brXjIEcqkjvSxJHI auiv6bsd ia68t/WXwdubPoNZhD8Ye6p5acDfH2ZI5cS1d4txWSxyzrv+df9o+vnlb6rOrxOhoHJbO8nvM/onZRp34Idj7HzdI+R21CNe60iBQ7d6+zlzTBkdy+khDiNg8X++tZoA10/QaOlCatJ556D9kOLkwOmbYHPzg2rnyWKy7L+Zu/lJNdFqN5/oA4URGv8VjxOn19LLcFLRnzvgQaspk427XooHDgpygIsotHFyYpQraYTjanL0RswMgA9Nmtg== 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 Wed Jan 31 14:05:22 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: 13539500 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 31D5EC47DB3 for ; Wed, 31 Jan 2024 14:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A92B46B00A2; Wed, 31 Jan 2024 09:05:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F4906B00A3; Wed, 31 Jan 2024 09:05:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 893346B00A4; Wed, 31 Jan 2024 09:05:46 -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 6BBE96B00A2 for ; Wed, 31 Jan 2024 09:05:46 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4509980D20 for ; Wed, 31 Jan 2024 14:05:46 +0000 (UTC) X-FDA: 81739779492.19.609582C Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf22.hostedemail.com (Postfix) with ESMTP id 587B2C002C for ; Wed, 31 Jan 2024 14:05:44 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=NDduIphe; 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; 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=1706709944; 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=qKbTeL0b6IHix+4RjhtyHT0Lpah8x7HYbLuJ5nhs5ig3ddS117DlVazEOWqbc959schkLx DkMbhAANQVqo++J6r0J55aFTKRIrgvT/3JGppzqTPwiFYydM6riOpjX6uL5o8bBNP9g0z0 VXj8l3x/iK935P9fBLiKf5tQZRcHVVI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706709944; a=rsa-sha256; cv=none; b=KohIXqD3badqF+P6g1kh3vyK6JWHLz9oxr8b/OCSzmmxQBigTQ0I2F7SAql2yNJlyYCy3h vXMdje6SSY0+K7tLMkWh69eLi/W2HuVzscGFw+Iv0OZBROJK6kYVdONG5qEPd1NPyQ3kca eAuvHXs7pJ2oq4pu6sEl0Qt607/SgpM= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=NDduIphe; 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; dmarc=pass (policy=quarantine) header.from=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706709943; bh=2kIkJOhTpv8Q3QiyGfqRKh0McTWdwjht00wQfRsByJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDduIphetMOQtuiPrCjAjVqGhbHMOGChazuerTGytlmJkwljYhUqUgJ4eh2KwUdvL G6QGhqSC6PGhjZRmbzH2RZSat5WaEUBEzUg9bnuze8UHIkUiEdK+7mgLpbWx9Ko+fS qJSmj+0YAqeQwSiesltDdilDr4ZkJ144vQ6jtdn6y1j7pQmKZ1esdyq7U/C9J9dmYT Cp3KbS7/TIlhEVUEv0MhVQ9ojxFJgnnxIjguuYQKKA9SiuhWYOtmfU26SoNc9Zn5cp suHOo24MGltQVnhmARjiYnIg6b6tjm4Uk2B6M2mjNQUJ+JDWVLeZOxnK7XNP4VKk1j Qcs9zRB8H7bzQ== 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 A7DA4378200E; Wed, 31 Jan 2024 14:05: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 12/12] selftests/mm: virtual_address_range: conform to TAP format output Date: Wed, 31 Jan 2024 19:05:22 +0500 Message-ID: <20240131140528.320252-12-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240131140528.320252-1-usama.anjum@collabora.com> References: <20240131140528.320252-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 587B2C002C X-Rspam-User: X-Stat-Signature: 6qrnz1knz8rt9wguxati5kpgk74rm4mh X-Rspamd-Server: rspam03 X-HE-Tag: 1706709944-248599 X-HE-Meta: U2FsdGVkX19Gtv+qLthn3EObN8y1hrNzWduWmzSvSioGxOpvgMJl0QSv0cB8tDsN0VbwpJqdRDwQZRhC9i+L8rgLQ5K5pmNI9DJbLoULXX4k/2iuPXFE4x8w+OEXKLC1XBczlYQflIEh379hNrMI+OhGzBnBmhV4esI8QRZ66SYmQ+6WWX+R0qi1DZVFdRCMYjritQtQnM5TckL6FheYyMhzSgQVJAVOTDJ8+g22Ez0ekerT8FZJNwU25gkqR1vSYAYXUThRsEwRf2Co4KsKjjRE+cMsv1oMPeZbX5dTrrz43lF9rWmIwiAJXnYQhVLLRk9fuotVL8i4rboeuCVj92pOD2OMsE9oo5T2dzwf7hPAhB9w7qK/Xzw8eZhbLq1gOgoF5ysR11TtoLWN1Kt+D0wAWU3/ct542nnU+jBKpSgn7heFDlGO94oPWvTmBpuxk+QcB2CfRCW1L0nIHndmXevbyMpjiOgrnV1icDoLS0FiKpj6Hb5hMPyL1D1c4r8b43EbGZ5yDgoCsWSMkTcoATvzV8FCo5qfgD2QbJvhkCLpnJNt6Gx2+cvTLjoH5DRoJT1ynHPp1R7hBF1py1/Kzld2C8vv/ZLQliX9yQ5YLash5tYns0wjJBRssnVjYZ32r/Z1Ro4qzyslA3v3M2R5zg91ZQLQ1VpThAmBHZ8p+M7z/z12++WHxuNqyFEHKMusJzp2ummNzMEFLY4f0RtdmZjqPPp8Ek0zjeSodIK4axtnjhI5cwtF9k4QN1vFkodtH+hWVBjzp1Ggnq4uY7V8TfwtXDPCgU9EhTR8cTbN1j91HUevvuqA1mVqUdeyQVr4Z/VVc7I8eoSw4+h67NccC4DvH2n7eGLsWHpS4aVnoId57a2lHs8YuQyHWeZM6d0FhHbBeu6bIIHXi9fB68RFcL8KQdN+YsCFLHOIW32HgC13aiAPrfRVBfhJaWrHGF1/CaPq+nKbfFgEoRgC2el S0rREvKO ZkiNpyy6W6Z0ADwIzFAdanE1NsllPH3Hc1stLCeFGQMHDOXMc/iiGJP5tWiW/kaiSmzi0raRBPYbeDPsjGkCi9BZtD4EpNgizOrbwQzx8mey9ZUO7ij/jk75Yt66hjG4Z12Iio6UpXHpn3KIB9/9gpjuxqa722l6nsqW6InJ66Brxuto2tIWVHVtI7K0FxmdmPbvMz98nIvvCzo9k9Y+hh523wKCggfacslsS9Fv0QwKHj4I8hi6wU9Ab8XUxTTOz5BE+/0XtnbR09tUO8Vu5PTMu1uCfUgx/n+IVAnyUPelaOMw= 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(); }