diff mbox series

readahead01.c: use TST_EXP_FAIL() macro and fix warnings

Message ID 20220719072709.20397-1-akumar@suse.de
State Accepted
Headers show
Series readahead01.c: use TST_EXP_FAIL() macro and fix warnings | expand

Commit Message

Avinesh Kumar July 19, 2022, 7:27 a.m. UTC
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(-)

Comments

Cyril Hrubis July 19, 2022, 11:33 a.m. UTC | #1
Hi!
Nice cleanup, applied, thanks.
diff mbox series

Patch

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