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(); }