From patchwork Fri Feb 2 11:31:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muhammad Usama Anjum X-Patchwork-Id: 13542773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB617C4828E for ; Fri, 2 Feb 2024 11:31:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2D116B008C; Fri, 2 Feb 2024 06:31:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BB35D6B0093; Fri, 2 Feb 2024 06:31:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A071D6B0095; Fri, 2 Feb 2024 06:31:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 73C586B008C for ; Fri, 2 Feb 2024 06:31:44 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1C51C120E8F for ; Fri, 2 Feb 2024 11:31:44 +0000 (UTC) X-FDA: 81746648928.28.BDB8B48 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) by imf03.hostedemail.com (Postfix) with ESMTP id 57A0B20002 for ; Fri, 2 Feb 2024 11:31:42 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=0lfqji+e; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf03.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706873502; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NBGcD6igMjkCr462TPdDWbNTfEPOvbMajBGZreLeDwU=; b=JGLBs459vp9WiOtD5/W4tG4tMqfOzsS8gfDlRClM0wBgtL6s5x7CfFM0EtoHXPpUbE7wOm J8lyMR5Hv28Dpr6kUNodiXCoEHno5nI0qSc6xPW2nYLQgR1kYScaWLwZHctrBmvt8e1MXK 39f6f5K4t2L2ULtfJ+BiccGWO+kuA7s= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=collabora.com header.s=mail header.b=0lfqji+e; dmarc=pass (policy=quarantine) header.from=collabora.com; spf=pass (imf03.hostedemail.com: domain of usama.anjum@collabora.com designates 46.235.227.194 as permitted sender) smtp.mailfrom=usama.anjum@collabora.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706873502; a=rsa-sha256; cv=none; b=G0vzEy0Kg5rQdUPDY6WyvfyjLgUwaxCGXTxyW2a7964cAKnm0hRkxtgi20cb0rOcJ4W94h PTZkpotZFnz7PKUmpWMz/o4ppXufdQcGjnMIaqEVDI5q+JavDuAX5kaQp0jQMyqkgwqfC0 nx6Rq7EeCZyqOvhzbfbkrdNaSzxhPVk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706873501; bh=CPJegAn2jct8qTIbcEKKHIZ5byMY8HScpq2uBuAZ1YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0lfqji+eLlBS5e+wEw7FViQVc/F4HiU2UzSDgYsDCtUrLKYO4xfGq1b0zlJ7y6DQo 936S7ZEbazYvahmRV/khY9mhLfY7436WPsk3goRckXKRe4/1OcvSLkxbUdAIvBpPKg ACArrnKoof3qb5Gum32J6lS8YBRDJVELyv93YNlBJxZkf7BP8phc0BkR/8A35/iiPt 7pzulvjDSQruyOIJOIqJVqAW8hzDhWhZd5UTksWOdAxCm4sH2L5zkR695jneIhmytb Mu6MKAsSh7+deOUe2T/xy/a1z7bxHpSrih4Cr0BubJTB0ckHcLNZMfDre+0RY5bWqN WoWLsxJigKP4Q== Received: from localhost.localdomain (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: usama.anjum) by madrid.collaboradmins.com (Postfix) with ESMTPSA id AB6F137811CF; Fri, 2 Feb 2024 11:31:39 +0000 (UTC) From: Muhammad Usama Anjum To: Andrew Morton , Shuah Khan Cc: Muhammad Usama Anjum , kernel@collabora.com, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 06/12] selftests/mm: mrelease_test: conform test to TAP format output Date: Fri, 2 Feb 2024 16:31:13 +0500 Message-ID: <20240202113119.2047740-7-usama.anjum@collabora.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240202113119.2047740-1-usama.anjum@collabora.com> References: <20240202113119.2047740-1-usama.anjum@collabora.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: hd3u35mit1k316etowk4wh5tn31y1bpn X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 57A0B20002 X-HE-Tag: 1706873502-453222 X-HE-Meta: U2FsdGVkX1/3MINlm4d795Ljdh7v3bhamPPTl9YqICM4cYvS2zm29S3I/KWaZ/kTNi88b7xelv6rb0CukCx6kjrIJIllQdNbsEcWTAJ6Xqi2pmIwKT6t7jRjLffYjpOwVrII3Su8q+z6X5YM3YsEy4OuZ1k9i7wK89jSyrtoLTC/V/O4nPVem9qZJk/9V5qUmHDS7IWbB4v/n9pe//Ab3J5FXWdoVjh/vfFxgImOtADhrTQdB9CmVAcC2xhf0N6lZmzdyeuwOYuXDxVu5UglzlA/2MSf/Wr52e2+8anPXUE13womgFMSLUpaGl6SkOqsOL9wL/9+zGhI3rcG6++zC37g4Ada71qqCtoEhhVf5tH+95EkSeiwG6pzosvTWBwtpbVD+uMHQaca3zljSBt1yJeSab0gSfzFoaNDBFzEFjabxCd+TZ/Ps0JefM+YnQhoYe3n+cUGJShbZKJE7+bc+4BLJQ4Sf8kieyoy1lRQKDFaypIzWTRWsup+pHDEQH4NWdqQydAE6gVwYhW0zxWTP0ByY9a1bp87sVyUxRaH7kWXmUSB1OXWklux9Qd0zB1TvZZXLBeQNCntrmtqemylxrEQq0PwzTzob0X/zoP9hXG2gCB2+v41I860Xho03elT8tedG2OLCj+uR6bBZBKa13mR6VznmhK+NuZvcBaII2Ag751sEiBMFmtUq92OgP1kDeOAItolI+8Vkl3XvwnXr3coNlEWsvim1Jj1X/Ts82dVe1+mfiDHV+ahgHnNvdt0E3ry2oz+VGXZVxuOPcquqCrRtXwph/zgubE4Q3h8iZv6uZCcFqCze+uqomweqZUQSpdw0C+2s3Jkr3aCFMzysVy7VxPS7YZB+jd9Pl2RBiW+MyzLLY0yElv7/IiFiuYlkjjAvGahgAUUt+cBKNP+jeGTjyio9Owd3/QSaBAQExHHGUslOyUpQbAlT5De2RDv+euRe6eCzRDHsBXhhYn nXxewoR3 9TqCjbZ2kF8EN8Eu7kQkoDYMOWcvlhvwkRXYEbeok9RT2GQnunVZZHZhUmZvy6xpYP485hf8wLFpczBcIQOwYa87t9qFD2dv/ENytEkapIPJxGyVRNdScUT6q4eH1vLAfH340SAWEjr9cAXqvFXYy7IuC2KGEPObCygW63VpDAa/N+3uyr8Ymr5JA+SkRoPClQEqlJSrzAQVuhZJYrAUUU8t+I4tSxZ2JJBFO8LNtojWhHCq/UzIkxKmazTOEIYNBboRONgRdhpRxbwB1vWJNwaaMrNlO+fcOb/g1uolnumotKXs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Conform the layout, informational and status messages to TAP. No functional change is intended other than the layout of output messages. Signed-off-by: Muhammad Usama Anjum --- tools/testing/selftests/mm/mrelease_test.c | 80 +++++++++------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/tools/testing/selftests/mm/mrelease_test.c b/tools/testing/selftests/mm/mrelease_test.c index d822004a374e9..100370a7111df 100644 --- a/tools/testing/selftests/mm/mrelease_test.c +++ b/tools/testing/selftests/mm/mrelease_test.c @@ -26,19 +26,15 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) buf = (char *)mmap(NULL, nr_pages * psize(), PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, 0, 0); - if (buf == MAP_FAILED) { - perror("mmap failed, halting the test"); - return KSFT_FAIL; - } + if (buf == MAP_FAILED) + ksft_exit_fail_msg("mmap failed, halting the test: %s\n", strerror(errno)); for (i = 0; i < nr_pages; i++) *((unsigned long *)(buf + (i * psize()))) = i; /* Signal the parent that the child is ready */ - if (write(pipefd, "", 1) < 0) { - perror("write"); - return KSFT_FAIL; - } + if (write(pipefd, "", 1) < 0) + ksft_exit_fail_msg("write: %s\n", strerror(errno)); /* Wait to be killed (when reparenting happens) */ while (getppid() == ppid && timeout > 0) { @@ -54,23 +50,17 @@ static int alloc_noexit(unsigned long nr_pages, int pipefd) /* The process_mrelease calls in this test are expected to fail */ static void run_negative_tests(int pidfd) { - int res; /* Test invalid flags. Expect to fail with EINVAL error code. */ if (!syscall(__NR_process_mrelease, pidfd, (unsigned int)-1) || errno != EINVAL) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease with wrong flags"); - exit(res); + ksft_exit_fail_msg("process_mrelease with wrong flags: %s\n", strerror(errno)); } /* * Test reaping while process is alive with no pending SIGKILL. * Expect to fail with EINVAL error code. */ - if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease on a live process"); - exit(res); - } + if (!syscall(__NR_process_mrelease, pidfd, 0) || errno != EINVAL) + ksft_exit_fail_msg("process_mrelease on a live process: %s\n", strerror(errno)); } static int child_main(int pipefd[], size_t size) @@ -93,11 +83,18 @@ int main(void) char byte; int res; + ksft_print_header(); + ksft_set_plan(1); + /* Test a wrong pidfd */ if (!syscall(__NR_process_mrelease, -1, 0) || errno != EBADF) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease with wrong pidfd"); - exit(res); + if (errno == ENOSYS) { + ksft_test_result_skip("process_mrelease not implemented\n"); + ksft_finished(); + } else { + ksft_exit_fail_msg("process_mrelease with wrong pidfd: %s", + strerror(errno)); + } } /* Start the test with 1MB child memory allocation */ @@ -107,16 +104,14 @@ int main(void) * Pipe for the child to signal when it's done allocating * memory */ - if (pipe(pipefd)) { - perror("pipe"); - exit(KSFT_FAIL); - } + if (pipe(pipefd)) + ksft_exit_fail_msg("pipe: %s\n", strerror(errno)); + pid = fork(); if (pid < 0) { - perror("fork"); close(pipefd[0]); close(pipefd[1]); - exit(KSFT_FAIL); + ksft_exit_fail_msg("fork: %s\n", strerror(errno)); } if (pid == 0) { @@ -134,28 +129,23 @@ int main(void) res = read(pipefd[0], &byte, 1); close(pipefd[0]); if (res < 0) { - perror("read"); if (!kill(pid, SIGKILL)) waitpid(pid, NULL, 0); - exit(KSFT_FAIL); + ksft_exit_fail_msg("read: %s\n", strerror(errno)); } pidfd = syscall(__NR_pidfd_open, pid, 0); if (pidfd < 0) { - perror("pidfd_open"); if (!kill(pid, SIGKILL)) waitpid(pid, NULL, 0); - exit(KSFT_FAIL); + ksft_exit_fail_msg("pidfd_open: %s\n", strerror(errno)); } /* Run negative tests which require a live child */ run_negative_tests(pidfd); - if (kill(pid, SIGKILL)) { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("kill"); - exit(res); - } + if (kill(pid, SIGKILL)) + ksft_exit_fail_msg("kill: %s\n", strerror(errno)); success = (syscall(__NR_process_mrelease, pidfd, 0) == 0); if (!success) { @@ -169,18 +159,15 @@ int main(void) if (errno == ESRCH) { retry = (size <= MAX_SIZE_MB); } else { - res = (errno == ENOSYS ? KSFT_SKIP : KSFT_FAIL); - perror("process_mrelease"); waitpid(pid, NULL, 0); - exit(res); + ksft_exit_fail_msg("process_mrelease: %s\n", strerror(errno)); } } /* Cleanup to prevent zombies */ - if (waitpid(pid, NULL, 0) < 0) { - perror("waitpid"); - exit(KSFT_FAIL); - } + if (waitpid(pid, NULL, 0) < 0) + ksft_exit_fail_msg("waitpid: %s\n", strerror(errno)); + close(pidfd); if (!success) { @@ -188,11 +175,10 @@ int main(void) size *= 2; goto retry; } - printf("All process_mrelease attempts failed!\n"); - exit(KSFT_FAIL); + ksft_exit_fail_msg("All process_mrelease attempts failed!\n"); } - printf("Success reaping a child with %zuMB of memory allocations\n", - size); - return KSFT_PASS; + ksft_test_result_pass("Success reaping a child with %zuMB of memory allocations\n", + size); + ksft_finished(); }