diff mbox series

[v2] swapon02: Simplify code, add copyright, modify docparse

Message ID 20231129061212.72817-1-xuyang2018.jy@fujitsu.com
State Accepted
Headers show
Series [v2] swapon02: Simplify code, add copyright, modify docparse | expand

Commit Message

Yang Xu \(Fujitsu\) Nov. 29, 2023, 6:12 a.m. UTC
Simplify permission-related test code, making structures look simpler

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/swapon/swapon02.c | 66 +++++++--------------
 1 file changed, 22 insertions(+), 44 deletions(-)

Comments

Li Wang Nov. 29, 2023, 9:20 a.m. UTC | #1
Reviewed-by: Li Wang <liwang@redhat.com>
Yang Xu \(Fujitsu\) Nov. 30, 2023, 1:11 a.m. UTC | #2
Hi Li

Sorry, I missed the COMMITTED subject when git-format this patch, so I have merged this patch before got your RVB.

Best Regards
Yang Xu

From: Li Wang <liwang@redhat.com>
Sent: Wednesday, November 29, 2023 5:21 PM
To: Xu, Yang/徐 杨 <xuyang2018.jy@fujitsu.com>
Cc: ltp@lists.linux.it; Yang, Xiao/杨 晓 <yangx.jy@fujitsu.com>
Subject: Re: [LTP] [PATCH v2] swapon02: Simplify code, add copyright, modify docparse

Reviewed-by: Li Wang <liwang@redhat.com<mailto:liwang@redhat.com>>

--
Regards,
Li Wang
Li Wang Nov. 30, 2023, 2:37 a.m. UTC | #3
No problem, thanks!

On Thu, Nov 30, 2023 at 9:12 AM Yang Xu (Fujitsu) <xuyang2018.jy@fujitsu.com>
wrote:

> Hi Li
>
>
>
> Sorry, I missed the COMMITTED subject when git-format this patch, so I
> have merged this patch before got your RVB.
>
>
>
> Best Regards
>
> Yang Xu
>
>
>
> *From:* Li Wang <liwang@redhat.com>
> *Sent:* Wednesday, November 29, 2023 5:21 PM
> *To:* Xu, Yang/徐 杨 <xuyang2018.jy@fujitsu.com>
> *Cc:* ltp@lists.linux.it; Yang, Xiao/杨 晓 <yangx.jy@fujitsu.com>
> *Subject:* Re: [LTP] [PATCH v2] swapon02: Simplify code, add copyright,
> modify docparse
>
>
>
> Reviewed-by: Li Wang <liwang@redhat.com>
>
>
>
> --
>
> Regards,
>
> Li Wang
>
diff mbox series

Patch

diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index d34c17a80..e5129723e 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -1,56 +1,39 @@ 
 // SPDX-License-Identifier: GPL-2.0-or-later
-
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
+ * Copyright (c) Linux Test Project, 2002-2023
  */
 
 /*\
  * [Description]
  *
  * This test case checks whether swapon(2) system call returns
- *  1. ENOENT when the path does not exist
- *  2. EINVAL when the path exists but is invalid
- *  3. EPERM when user is not a superuser
- *  4. EBUSY when the specified path is already being used as a swap area
+ * - ENOENT when the path does not exist
+ * - EINVAL when the path exists but is invalid
+ * - EPERM when user is not a superuser
+ * - EBUSY when the specified path is already being used as a swap area
  */
 
-#include <errno.h>
 #include <pwd.h>
 
 #include "tst_test.h"
 #include "lapi/syscalls.h"
 #include "libswap.h"
 
-static void setup01(void);
-static void cleanup01(void);
-
 static uid_t nobody_uid;
 static int do_swapoff;
 
 static struct tcase {
 	char *err_desc;
 	int exp_errno;
-	char *exp_errval;
 	char *path;
-	void (*setup)(void);
-	void (*cleanup)(void);
 } tcases[] = {
-	{"Path does not exist", ENOENT, "ENOENT", "./doesnotexist", NULL, NULL},
-	{"Invalid path", EINVAL, "EINVAL", "./notswap", NULL, NULL},
-	{"Permission denied", EPERM, "EPERM", "./swapfile01", setup01, cleanup01},
-	{"File already used", EBUSY, "EBUSY", "./alreadyused", NULL, NULL},
+	{"Path does not exist", ENOENT, "./doesnotexist"},
+	{"Invalid path", EINVAL, "./notswap"},
+	{"Permission denied", EPERM, "./swapfile01"},
+	{"File already used", EBUSY, "./alreadyused"},
 };
 
-static void setup01(void)
-{
-	SAFE_SETEUID(nobody_uid);
-}
-
-static void cleanup01(void)
-{
-	SAFE_SETEUID(0);
-}
-
 static void setup(void)
 {
 	struct passwd *nobody;
@@ -70,7 +53,7 @@  static void setup(void)
 		do_swapoff = 1;
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	if (do_swapoff && tst_syscall(__NR_swapoff, "alreadyused"))
 		tst_res(TWARN | TERRNO, "swapoff(alreadyused) failed");
@@ -79,24 +62,19 @@  void cleanup(void)
 static void verify_swapon(unsigned int i)
 {
 	struct tcase *tc = tcases + i;
-	if (tc->setup)
-		tc->setup();
-
-	TEST(tst_syscall(__NR_swapon, tc->path, 0));
-
-	if (tc->cleanup)
-		tc->cleanup();
-
-	if (TST_RET == -1 && TST_ERR == tc->exp_errno) {
-		tst_res(TPASS, "swapon(2) expected failure;"
-			 " Got errno - %s : %s",
-			 tc->exp_errval, tc->err_desc);
-		return;
+	if (tc->exp_errno == EPERM)
+		SAFE_SETEUID(nobody_uid);
+
+	TST_EXP_FAIL(tst_syscall(__NR_swapon, tc->path, 0), tc->exp_errno,
+		     "swapon(2) fail with %s", tc->err_desc);
+
+	if (tc->exp_errno == EPERM)
+		SAFE_SETEUID(0);
+
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "swapon(2) failed unexpectedly, expected: %s",
+			tst_strerrno(tc->exp_errno));
 	}
-
-	tst_res(TFAIL, "swapon(2) failed to produce expected error:"
-	         " %d, errno: %s and got %d.", tc->exp_errno,
-	         tc->exp_errval, TST_ERR);
 }
 
 static struct tst_test test = {