From patchwork Fri Jan 26 11:21: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: 13532448 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 660CEC47DDF for ; Fri, 26 Jan 2024 11:21:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DECC16B0095; Fri, 26 Jan 2024 06:21:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D6C466B0099; Fri, 26 Jan 2024 06:21:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0AFE6B009A; Fri, 26 Jan 2024 06:21:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A6A476B0095 for ; Fri, 26 Jan 2024 06:21:42 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4782080F19 for ; Fri, 26 Jan 2024 11:21:42 +0000 (UTC) X-FDA: 81721222044.02.8D2D469 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf05.hostedemail.com (Postfix) with ESMTP id 89298100020 for ; Fri, 26 Jan 2024 11:21:40 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ctzgBNKK; dmarc=pass (policy=quarantine) header.from=collabora.com; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706268100; 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=jjZzUqCCU16DR/v7uWIQCMY5QzsHvlyTduuk+WCMCZc=; b=E3XcWH0c0WrgJTuHfK3NwfI2qlex+i1xQavskA7wBGmeDenF3NuHHA/ABJByg8JwLr5NQi RQhR3GSYzjeYstBeCQcBCmsjErNW7CUI54zg6OO7lt2Qsd7YVBRps4Lqo9BU1RNcl1j1ct 70kZOk3EIom0K5LUG2Hkzvek6Kp6CLs= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=ctzgBNKK; dmarc=pass (policy=quarantine) header.from=collabora.com; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706268100; a=rsa-sha256; cv=none; b=F0F5fkNGTwrZrF/AYoSPH+/I+273OzqHjyLoVRRTAhOX+UNHIPCgZZvWiSZnBxABbW67G6 UK8i4RkL3GvgPFc8zbuJaCFtCXJbFa1b8UogZv+l6F3impHzmQa42aqu1NpicED1GbURv5 th1P8q0plBIX7Bxss16T4lZObcjsIOY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706268099; bh=oDxKY6D9IYcq3xKVIIbcarJ6RozlBwyEKP7D9+dutbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ctzgBNKKw3Zm63flRPmQV7k3ZxCtCt6ZXwYL/2QwVbNWoS4TV85VHw+K2hNOftLyT AhBiBwk+/ghMUsJE2JKJksYOzE0Q7Kv1vM0w4Q5Z11m7YqK/AT7j5O6H9FOEoY80Yv 9EiEJwYLgEAzGdyQT6sxP6pnbVoNDFv2t/elNVEzW+l3xNBNDPlyAuwBx1z9RY3QT1 x3nGidv+PC/NldxAzP1tPfWJAfvUa6zns1zTWiaHy3vdiPhxCpAUPjB7UHLnEx6VVN 2+E4Ahfq2U0OJ4qrka0N9px8HHJIwgriaA+TTTXyYbeG4+PIWofvp/jy8dpcvHVNNE 8galWk+HiZEqA== 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 D34CF3782072; Fri, 26 Jan 2024 11:21: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 v4 3/7] selftests/mm: hugetlb-madvise: conform test to TAP format output Date: Fri, 26 Jan 2024 16:21:22 +0500 Message-ID: <20240126112129.1480265-3-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240126112129.1480265-1-usama.anjum@collabora.com> References: <20240126112129.1480265-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: mu85u5xouxeummffbe6m9rtxf4htgucj X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 89298100020 X-HE-Tag: 1706268100-86361 X-HE-Meta: U2FsdGVkX18Z+4CaF//Jnm6Yvj2qSAF6ILYjs5lOM2NnCXBLvjyMr208DtQUANA0sshL85JINUjgmFgWWqyo1OMuN4wtf1yKhzf1Vs3FdwcYOYvUJGheoa0mKH3qTZHlaQSIEvis/T9Var7uD+eb8IQ8ftaluGAM/9nSkVZsYrkryE9nyCKxHX0ft0kUgHnqyyX7aZUUCwkPvoyP3I0+WycgK4h6B8BX9C7cmD7xqgorv4tIxl4HXPX7iK0kJRZIt/ma1Ow98RVS5v1zOulXvydquLzD7TvoXyFDxdMKXGD5zMMqKiiwuI0D0tW5QJqoZMTq4uVHmKOEvSJajqjBGjauk5tI2vy/a6EDykoyKfb1irPponHB5d6zodpM5sUoiIGx4L+C0B2TfFUh91ksmjUzRWJSf9OSYifrhDBkYihCopm4MDAOXvz/W1/ltgtMegoR9/aiu0LzWeJ6bpo9chcIQ7SLa0nrLuZ6JptXk01P5WdMUVCjp6mVwsG8SGUGHWQ0GkQNEVB76pRgijsBVwZWOLQK8DUaifNS9DzR70Rc/eUX8fJPjcLXLi9J4pAKnWmdjeRfnHMSfTIJi3yY+kyWjEYN1NkAMvERZeepWzptZZu6mdEfKejDWHsC4tw0gtcxMbciMZHy6xD7gzYeHaNKWAsFOccU9jGeYIcRDksSxIOyKu/a1vwT4OLxsawLatG3efkL8p6gOnPmAa7mf6LcRdm5UST8Me5z/hmCwAJ2Cjfa9oEduM82hZH8sjWx8M3TVf+aQK9QrupeiVVTXfUhZZIrOOSeoSz4Bo2TvPVYdURrg6E5sSJKv3sjoLkvameBDVccop4zF8cI/eg1fcVXGkNOxkEHyS8wkbexIFxZdTrkAkY+0T6K4Vf2NzLGjF4hZuW26pn8gaFSUBlvkIChDcx0mK38nro7NIvakpIoe6FgymztxXgoGv9LUT6bODWj6G9LYATVeYvBjOP P6c5KdhN SDEqOHJp2Z9i562/kX3O7kkBh3ZAEDm6BZ7ck+lCaHAkQx7MdoeAqZ1fPmlgEYslJ/hOK3s3nLz6bi1BRfCuKo9SNaEfpTznLIobsZOfk4Xfd6K3BuQmXeVKcEmX9Hp4G7D0UiYM5cvqgFTy8i+ClELNUeTvhbIAY61+pVy4FV3pCiqLY1G7e4iHSkoh4lF1tdsJ65GfuuzpH7UDQ/AsOQKb2i0ZVAiqo6qXXRBTkXQYOOILbe935TK3xgQ== 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 --- Changes since v3: - Rebased on top of next-20240125 --- tools/testing/selftests/mm/hugetlb-madvise.c | 207 +++++++------------ 1 file changed, 80 insertions(+), 127 deletions(-) diff --git a/tools/testing/selftests/mm/hugetlb-madvise.c b/tools/testing/selftests/mm/hugetlb-madvise.c index f32d99565c5ea..2d9b27bc0d01d 100644 --- a/tools/testing/selftests/mm/hugetlb-madvise.c +++ b/tools/testing/selftests/mm/hugetlb-madvise.c @@ -19,19 +19,14 @@ #include #include #include "vm_util.h" +#include "../kselftest.h" #define MIN_FREE_PAGES 20 #define NR_HUGE_PAGES 10 /* common number of pages to map/allocate */ #define validate_free_pages(exp_free) \ - do { \ - int fhp = get_free_hugepages(); \ - if (fhp != (exp_free)) { \ - printf("Unexpected number of free huge " \ - "pages line %d\n", __LINE__); \ - exit(1); \ - } \ - } while (0) + ksft_test_result(get_free_hugepages() == (exp_free), \ + "Validation of free pages (%d)\n", __LINE__) unsigned long huge_page_size; unsigned long base_page_size; @@ -64,28 +59,27 @@ int main(int argc, char **argv) int fd; int ret; + ksft_print_header(); + huge_page_size = default_huge_page_size(); - if (!huge_page_size) { - printf("Unable to determine huge page size, exiting!\n"); - exit(1); - } + if (!huge_page_size) + ksft_exit_fail_msg("Unable to determine huge page size, exiting!\n"); + base_page_size = sysconf(_SC_PAGE_SIZE); - if (!huge_page_size) { - printf("Unable to determine base page size, exiting!\n"); - exit(1); - } + if (!huge_page_size) + ksft_exit_fail_msg("Unable to determine base page size, exiting!\n"); free_hugepages = get_free_hugepages(); if (free_hugepages < MIN_FREE_PAGES) { - printf("Not enough free huge pages to test, exiting!\n"); - exit(1); + ksft_print_msg("Not enough free huge pages to test, exiting!\n"); + ksft_finished(); } fd = memfd_create(argv[0], MFD_HUGETLB); - if (fd < 0) { - perror("memfd_create() failed"); - exit(1); - } + if (fd < 0) + ksft_exit_fail_msg("memfd_create() failed\n"); + + ksft_set_plan(37); /* * Test validity of MADV_DONTNEED addr and length arguments. mmap @@ -97,16 +91,13 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); + if (munmap(addr, huge_page_size) || - munmap(addr + (NR_HUGE_PAGES + 1) * huge_page_size, - huge_page_size)) { - perror("munmap"); - exit(1); - } + munmap(addr + (NR_HUGE_PAGES + 1) * huge_page_size, huge_page_size)) + ksft_exit_fail_msg("munmap: %s\n", strerror(errno)); + addr = addr + huge_page_size; write_fault_pages(addr, NR_HUGE_PAGES); @@ -114,21 +105,13 @@ int main(int argc, char **argv) /* addr before mapping should fail */ ret = madvise(addr - base_page_size, NR_HUGE_PAGES * huge_page_size, - MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with invalid addr line %d\n", - __LINE__); - exit(1); - } + MADV_DONTNEED); + ksft_test_result(ret, "The madvise call with invalid address\n"); /* addr + length after mapping should fail */ ret = madvise(addr, (NR_HUGE_PAGES * huge_page_size) + base_page_size, - MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with invalid length line %d\n", - __LINE__); - exit(1); - } + MADV_DONTNEED); + ksft_test_result(ret, "The madvise call with invalid address\n"); (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); @@ -139,10 +122,9 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); + write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); @@ -150,19 +132,12 @@ int main(int argc, char **argv) ret = madvise(addr + base_page_size, NR_HUGE_PAGES * huge_page_size - base_page_size, MADV_DONTNEED); - if (!ret) { - printf("Unexpected success of madvise call with unaligned start address %d\n", - __LINE__); - exit(1); - } + ksft_test_result(ret, "The madvise call with unaligned start address\n"); /* addr + length should be aligned down to huge page size */ - if (madvise(addr, - ((NR_HUGE_PAGES - 1) * huge_page_size) + base_page_size, - MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, ((NR_HUGE_PAGES - 1) * huge_page_size) + base_page_size, + MADV_DONTNEED); + ksft_test_result(!ret, "The madvise call with aligned start address\n"); /* should free all but last page in mapping */ validate_free_pages(free_hugepages - 1); @@ -177,17 +152,14 @@ int main(int argc, char **argv) PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); + write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_DONTNEED on anonymous private mapping\n"); /* should free all pages in mapping */ validate_free_pages(free_hugepages); @@ -197,29 +169,25 @@ int main(int argc, char **argv) /* * Test MADV_DONTNEED on private mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_msg("fallocate: %s\n", strerror(errno)); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); addr = mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); /* read should not consume any pages */ read_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* madvise should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_DONTNEED on private mapping of file\n"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* writes should allocate private pages */ @@ -227,10 +195,9 @@ int main(int argc, char **argv) validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); /* madvise should free private pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_DONTNEED on private mapping of file\n"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* writes should allocate private pages */ @@ -245,10 +212,9 @@ int main(int argc, char **argv) * implementation. */ if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_msg("fallocate: %s\n", strerror(errno)); + validate_free_pages(free_hugepages); (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); @@ -256,29 +222,25 @@ int main(int argc, char **argv) /* * Test MADV_DONTNEED on shared mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_msg("fallocate: %s\n", strerror(errno)); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); addr = mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); /* write should not consume any pages */ write_fault_pages(addr, NR_HUGE_PAGES); validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* madvise should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_DONTNEED on shared mapping of file\n"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* @@ -286,29 +248,25 @@ int main(int argc, char **argv) * * madvise is same as hole punch and should free all pages. */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE); + ksft_test_result(!ret, "The madvise MADV_REMOVE on shared mapping of file\n"); + validate_free_pages(free_hugepages); (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); /* * Test MADV_REMOVE on shared and private mapping of hugetlb file */ - if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) { - perror("fallocate"); - exit(1); - } + if (fallocate(fd, 0, 0, NR_HUGE_PAGES * huge_page_size)) + ksft_exit_fail_msg("fallocate: %s\n", strerror(errno)); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); addr = mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - if (addr == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); /* shared write should not consume any additional pages */ write_fault_pages(addr, NR_HUGE_PAGES); @@ -317,10 +275,8 @@ int main(int argc, char **argv) addr2 = mmap(NULL, NR_HUGE_PAGES * huge_page_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); - if (addr2 == MAP_FAILED) { - perror("mmap"); - exit(1); - } + if (addr2 == MAP_FAILED) + ksft_exit_fail_msg("mmap: %s\n", strerror(errno)); /* private read should not consume any pages */ read_fault_pages(addr2, NR_HUGE_PAGES); @@ -331,17 +287,15 @@ int main(int argc, char **argv) validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); /* madvise of shared mapping should not free any pages */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_REMOVE on shared mapping of file\n"); + validate_free_pages(free_hugepages - (2 * NR_HUGE_PAGES)); /* madvise of private mapping should free private pages */ - if (madvise(addr2, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr2, NR_HUGE_PAGES * huge_page_size, MADV_DONTNEED); + ksft_test_result(!ret, "The madvise MADV_REMOVE on shared mapping of file\n"); + validate_free_pages(free_hugepages - NR_HUGE_PAGES); /* private write should consume additional pages again */ @@ -353,15 +307,14 @@ int main(int argc, char **argv) * not correct. private pages should not be freed, but this is * expected. See comment associated with FALLOC_FL_PUNCH_HOLE call. */ - if (madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE)) { - perror("madvise"); - exit(1); - } + ret = madvise(addr, NR_HUGE_PAGES * huge_page_size, MADV_REMOVE); + ksft_test_result(!ret, "The madvise MADV_REMOVE on shared mapping of file\n"); + validate_free_pages(free_hugepages); (void)munmap(addr, NR_HUGE_PAGES * huge_page_size); (void)munmap(addr2, NR_HUGE_PAGES * huge_page_size); close(fd); - return 0; + ksft_finished(); }