From patchwork Mon Jan 1 08:36: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: 13508611 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 53A75C47074 for ; Mon, 1 Jan 2024 08:36:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D6936B0266; Mon, 1 Jan 2024 03:36:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 485FD6B0269; Mon, 1 Jan 2024 03:36:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34D686B026A; Mon, 1 Jan 2024 03:36:23 -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 2395D6B0266 for ; Mon, 1 Jan 2024 03:36:23 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D4FF8140372 for ; Mon, 1 Jan 2024 08:36:22 +0000 (UTC) X-FDA: 81630085404.24.B1681E4 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf05.hostedemail.com (Postfix) with ESMTP id 2C9E910000C for ; Mon, 1 Jan 2024 08:36:20 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Ih5HKF13; 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=1704098181; 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=67hZCxmCWr64yEhuzarT0pHn0dKsId92sEpePOPIJUE=; b=p6So24oI+ftL56msGxDDOpxhIRS6HXKqO94AjnrW36rHRH0DAK/z4Iap6/OU6JsMLNCvXi /FwVptr7iFJsZNhzIImz0oxDJilFw2fK8mIKLxr5kyIH9I68jieQxz3diJPQi5Byho3t1z TFVRyRwFCBeuueZGczIEc0nogGEqMgc= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=Ih5HKF13; 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=1704098181; a=rsa-sha256; cv=none; b=1T1mscOOsrVczlhVeWh6752McABdoD46iwjQdciD5LPwJ4KI6RwBpMffwLtn4YQ+hX9cuS 9m/DCi+CGq3rmB2d26Lgwt67cBEjceWXPXOSHQAAE6GHWhCdcJhk0zDdlYdgDpQuBZp7x3 zeNdVVQyPKx98r4r2r4F4TkngoaExro= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1704098179; bh=+gfEvPhINeOZS8khMkMB/mit5yJKB+pQv1n24ICuSNo=; h=From:To:Cc:Subject:Date:From; b=Ih5HKF13oEvT0bH79pnSPQX3Cu92PdkFswDDQ4n1MV89I9Ddfo7Ek1Y8dYNc9VQyG 7bIk1vYKqGtQVJYhJ6C5cHKTQm6hbVRafuwV+xd5ax10Y0PjhXkgCTvVpKac4FDeEi WTiLgsRIuKyxEJFttoiqTIbfLBwZC0XGUrc88cdv8zO1U4WQUHfbLwmR0Wck+FI6CF rLrc+y1pBwP7s1wKcPpijmFR6yj9bCa2OZHJF94YKA/YK8BHP1jCuQIKRbX3ZHmjQI F54bvDJFwsyRc0GhuDfn+vgosQkZyPHELOtEwekO0JWNzh2Mt4okN3XzP4PbTZ7WgB G/TkxMaaDW4Dg== 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 A03FE378000B; Mon, 1 Jan 2024 08:36:17 +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 1/2] selftests/mm: conform test to TAP format output Date: Mon, 1 Jan 2024 13:36:12 +0500 Message-ID: <20240101083614.1076768-1-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C9E910000C X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: weqpd8p14b5xuzsk816uttoqcxutstzn X-HE-Tag: 1704098180-952980 X-HE-Meta: U2FsdGVkX1/aw71fLheQv+fQijeNffKNAMYgoo3R0TOeI8iXrrDJildEFyr9+CyCvsFeqWV8Fp/ToRK4YnpSxIO97ABFago6ddEX1sBDtDFTl1h6xv+9cWQ0dmCMheLEpYGmaH+wR8CDVI4hDZd2xXE8vByq/iFdgCvvIlompa6w5DtP+RncNjzjVasI5wfFnnwOV95UjzIA6mcN3Om57bAVE7+PBXa5/CRcH2abIFa4JpyA1bPl2pnd9GiZNBJMicHV/mttEwicbwlzR3GXujP8OFLMeEPohk3tVTVzRLybh1PPpfFPnZ9NmrLRGEOp8BFgnEjeJ+fU3qm4T+1HU4jWav+TkFIJoAvWSQRhb81TZrNDXR+s8HnIOlJkhBDKPOMvYPAVMMH1L1LQSFaxlJFIaY1O8xe4vMyFO5vtV22jr5KPY+mcJ94iSdX9ioLMFMajJdkgUiTcZnW7UtcGl8MbcHuIIL1u3ram6hOAE8d6FZdLPEPXjL3y0BqtcdT8rTFQgk5F35MQB4ZUPZpHQMnMK6sM+9BF/AyuiBRwb6WJNEXeDhZnVvO4I6LvAiVYAGEp/Ya6JI9Zcfc30iTBl9l5jQ3oRv42kA3OEXa5iNNfB8GWyuiw23i4IrFm4B6+RvqLN5lVbnMrVTjxKOABqzKA7hHhotQV8JVpE3gJE9Iyaaf6ZQdVU1ficmvEKXxeDllEaP5a/yAc/XL3xoZnl7WD+17rbOk5zyc4lb9w4fgpE6qwe+kSZw78NZzNMZTBCsBmj5FI6C11v48BYSZsifeCCNR3Ckx6dpokjPv6SfZnEVAQS5sEF1VOaxTXOwxPluYPH46h0jA1w5szzfPEn4WZCNiFG2ym9ST+r4v+qRxNjGV2rZtrbhQvd/8PmDZoasdSV9WOBAeMHxq+48Q+/0ZZndbrXYj56q7J2N8k9uZImuQKn0PVDctuOoJ262LB5PS4osGIAhS2QJEHfSS feBRmMYY j5Ae3jx8J1FAhJ/lPCvtwIFxJ4f9dzz2QJTQZ53bc4xuB4DGVxrWfWJO6SyDzzRI/72pprtjiJlkossut2Yz5kRpb3kl+b2cnEa0r1FsLS4E6GFlgwjKdo/jEWQsoRwGznQ2COtoHOEW3qwkISUg3Ima6rq5TQdtm7cxlNlD3RfjXJ2Rrr2c6M9ZQrtmA0JGbsuyeor3KZ1z8Zg19DQP3SeDsr+PE4W0bet/2gHw2VtjbkS7p5DsCNEEH7w== 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/compaction_test.c | 91 ++++++++++---------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/mm/compaction_test.c b/tools/testing/selftests/mm/compaction_test.c index 9b420140ba2b..707b0809b717 100644 --- a/tools/testing/selftests/mm/compaction_test.c +++ b/tools/testing/selftests/mm/compaction_test.c @@ -33,7 +33,7 @@ int read_memory_info(unsigned long *memfree, unsigned long *hugepagesize) FILE *cmdfile = popen(cmd, "r"); if (!(fgets(buffer, sizeof(buffer), cmdfile))) { - perror("Failed to read meminfo\n"); + ksft_print_msg("Failed to read meminfo: %s\n", strerror(errno)); return -1; } @@ -44,7 +44,7 @@ int read_memory_info(unsigned long *memfree, unsigned long *hugepagesize) cmdfile = popen(cmd, "r"); if (!(fgets(buffer, sizeof(buffer), cmdfile))) { - perror("Failed to read meminfo\n"); + ksft_print_msg("Failed to read meminfo: %s\n", strerror(errno)); return -1; } @@ -62,14 +62,14 @@ int prereq(void) fd = open("/proc/sys/vm/compact_unevictable_allowed", O_RDONLY | O_NONBLOCK); if (fd < 0) { - perror("Failed to open\n" - "/proc/sys/vm/compact_unevictable_allowed\n"); + ksft_print_msg("Failed to open /proc/sys/vm/compact_unevictable_allowed: %s\n", + strerror(errno)); return -1; } if (read(fd, &allowed, sizeof(char)) != sizeof(char)) { - perror("Failed to read from\n" - "/proc/sys/vm/compact_unevictable_allowed\n"); + ksft_print_msg("Failed to read from /proc/sys/vm/compact_unevictable_allowed: %s\n", + strerror(errno)); close(fd); return -1; } @@ -78,12 +78,13 @@ int prereq(void) if (allowed == '1') return 0; + ksft_print_msg("Compaction isn't allowed\n"); return -1; } int check_compaction(unsigned long mem_free, unsigned int hugepage_size) { - int fd; + int fd, ret = -1; int compaction_index = 0; char initial_nr_hugepages[10] = {0}; char nr_hugepages[10] = {0}; @@ -94,18 +95,21 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) fd = open("/proc/sys/vm/nr_hugepages", O_RDWR | O_NONBLOCK); if (fd < 0) { - perror("Failed to open /proc/sys/vm/nr_hugepages"); + ksft_test_result_fail("Failed to open /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); return -1; } if (read(fd, initial_nr_hugepages, sizeof(initial_nr_hugepages)) <= 0) { - perror("Failed to read from /proc/sys/vm/nr_hugepages"); + ksft_test_result_fail("Failed to read from /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); goto close_fd; } /* Start with the initial condition of 0 huge pages*/ if (write(fd, "0", sizeof(char)) != sizeof(char)) { - perror("Failed to write 0 to /proc/sys/vm/nr_hugepages\n"); + ksft_test_result_fail("Failed to write 0 to /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); goto close_fd; } @@ -114,14 +118,16 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) /* Request a large number of huge pages. The Kernel will allocate as much as it can */ if (write(fd, "100000", (6*sizeof(char))) != (6*sizeof(char))) { - perror("Failed to write 100000 to /proc/sys/vm/nr_hugepages\n"); + ksft_test_result_fail("Failed to write 100000 to /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); goto close_fd; } lseek(fd, 0, SEEK_SET); if (read(fd, nr_hugepages, sizeof(nr_hugepages)) <= 0) { - perror("Failed to re-read from /proc/sys/vm/nr_hugepages\n"); + ksft_test_result_fail("Failed to re-read from /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); goto close_fd; } @@ -129,67 +135,58 @@ int check_compaction(unsigned long mem_free, unsigned int hugepage_size) huge pages */ compaction_index = mem_free/(atoi(nr_hugepages) * hugepage_size); - if (compaction_index > 3) { - printf("No of huge pages allocated = %d\n", - (atoi(nr_hugepages))); - fprintf(stderr, "ERROR: Less that 1/%d of memory is available\n" - "as huge pages\n", compaction_index); - goto close_fd; - } - - printf("No of huge pages allocated = %d\n", - (atoi(nr_hugepages))); - lseek(fd, 0, SEEK_SET); if (write(fd, initial_nr_hugepages, strlen(initial_nr_hugepages)) != strlen(initial_nr_hugepages)) { - perror("Failed to write value to /proc/sys/vm/nr_hugepages\n"); + ksft_test_result_fail("Failed to write value to /proc/sys/vm/nr_hugepages: %s\n", + strerror(errno)); goto close_fd; } - close(fd); - return 0; + if (compaction_index > 3) { + ksft_print_msg("ERROR: Less that 1/%d of memory is available\n" + "as huge pages\n", compaction_index); + ksft_test_result_fail("No of huge pages allocated = %d\n", (atoi(nr_hugepages))); + goto close_fd; + } + + ksft_test_result_pass("Memory compaction succeeded. No of huge pages allocated = %d\n", + (atoi(nr_hugepages))); + ret = 0; close_fd: close(fd); - printf("Not OK. Compaction test failed."); - return -1; + return ret; } int main(int argc, char **argv) { struct rlimit lim; - struct map_list *list, *entry; + struct map_list *list = NULL, *entry; size_t page_size, i; void *map = NULL; unsigned long mem_free = 0; unsigned long hugepage_size = 0; long mem_fragmentable_MB = 0; - if (prereq() != 0) { - printf("Either the sysctl compact_unevictable_allowed is not\n" - "set to 1 or couldn't read the proc file.\n" - "Skipping the test\n"); - return KSFT_SKIP; - } + ksft_print_header(); + + if (prereq() != 0) + return ksft_exit_pass(); + + ksft_set_plan(1); lim.rlim_cur = RLIM_INFINITY; lim.rlim_max = RLIM_INFINITY; - if (setrlimit(RLIMIT_MEMLOCK, &lim)) { - perror("Failed to set rlimit:\n"); - return -1; - } + if (setrlimit(RLIMIT_MEMLOCK, &lim)) + ksft_exit_fail_msg("Failed to set rlimit: %s\n", strerror(errno)); page_size = getpagesize(); - list = NULL; - - if (read_memory_info(&mem_free, &hugepage_size) != 0) { - printf("ERROR: Cannot read meminfo\n"); - return -1; - } + if (read_memory_info(&mem_free, &hugepage_size) != 0) + ksft_exit_fail_msg("Failed to get meminfo\n"); mem_fragmentable_MB = mem_free * 0.8 / 1024; @@ -225,7 +222,7 @@ int main(int argc, char **argv) } if (check_compaction(mem_free, hugepage_size) == 0) - return 0; + return ksft_exit_pass(); - return -1; + return ksft_exit_fail(); }