All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] readahead01.c: use TST_EXP_FAIL() macro and fix warnings
Date: Tue, 19 Jul 2022 12:57:09 +0530	[thread overview]
Message-ID: <20220719072709.20397-1-akumar@suse.de> (raw)

cleanup using TST_EXP_FAIL() macro with expected errno code and fixing
checkpatch warnings

Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
 .../kernel/syscalls/readahead/readahead01.c   | 52 ++++---------------
 1 file changed, 9 insertions(+), 43 deletions(-)

diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c
index a0be96065..4355457e9 100644
--- a/testcases/kernel/syscalls/readahead/readahead01.c
+++ b/testcases/kernel/syscalls/readahead/readahead01.c
@@ -21,52 +21,22 @@
 #include "lapi/syscalls.h"
 
 #if defined(__NR_readahead)
-static void check_ret(long expected_ret)
-{
-	if (expected_ret == TST_RET) {
-		tst_res(TPASS, "expected ret success - "
-			"returned value = %ld", TST_RET);
-		return;
-	}
-	tst_res(TFAIL, "unexpected failure - "
-		"returned value = %ld, expected: %ld",
-		TST_RET, expected_ret);
-}
-
-static void check_errno(long expected_errno)
-{
-	if (TST_ERR == expected_errno) {
-		tst_res(TPASS | TTERRNO, "expected failure");
-		return;
-	}
-
-	if (TST_ERR == 0)
-		tst_res(TFAIL, "call succeeded unexpectedly");
-	else
-		tst_res(TFAIL | TTERRNO, "unexpected failure - "
-			"expected = %ld : %s, actual",
-			expected_errno, strerror(expected_errno));
-}
 
 static void test_bad_fd(void)
 {
 	char tempname[PATH_MAX] = "readahead01_XXXXXX";
 	int fd;
 
-	tst_res(TINFO, "test_bad_fd -1");
-	TEST(readahead(-1, 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EBADF);
+	tst_res(TINFO, "%s -1", __func__);
+	TST_EXP_FAIL(readahead(-1, 0, getpagesize()), EBADF);
 
-	tst_res(TINFO, "test_bad_fd O_WRONLY");
+	tst_res(TINFO, "%s O_WRONLY", __func__);
 	fd = mkstemp(tempname);
 	if (fd == -1)
 		tst_res(TFAIL | TERRNO, "mkstemp failed");
 	SAFE_CLOSE(fd);
 	fd = SAFE_OPEN(tempname, O_WRONLY);
-	TEST(readahead(fd, 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EBADF);
+	TST_EXP_FAIL(readahead(fd, 0, getpagesize()), EBADF);
 	SAFE_CLOSE(fd);
 	unlink(tempname);
 }
@@ -75,23 +45,19 @@ static void test_invalid_fd(void)
 {
 	int fd[2];
 
-	tst_res(TINFO, "test_invalid_fd pipe");
+	tst_res(TINFO, "%s pipe", __func__);
 	SAFE_PIPE(fd);
-	TEST(readahead(fd[0], 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EINVAL);
+	TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL);
 	SAFE_CLOSE(fd[0]);
 	SAFE_CLOSE(fd[1]);
 
-	tst_res(TINFO, "test_invalid_fd socket");
+	tst_res(TINFO, "%s socket", __func__);
 	fd[0] = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
-	TEST(readahead(fd[0], 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EINVAL);
+	TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL);
 	SAFE_CLOSE(fd[0]);
 }
 
-void test_readahead(void)
+static void test_readahead(void)
 {
 	test_bad_fd();
 	test_invalid_fd();
-- 
2.36.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2022-07-19  7:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  7:27 Avinesh Kumar [this message]
2022-07-19 11:33 ` [LTP] [PATCH] readahead01.c: use TST_EXP_FAIL() macro and fix warnings Cyril Hrubis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220719072709.20397-1-akumar@suse.de \
    --to=akumar@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.