[LTP] [Patch v6 7/8] swapon/off: enable all_filesystem in swap test

Li Wang liwang@redhat.com
Wed Jan 31 11:25:13 CET 2024


Signed-off-by: Li Wang <liwang@redhat.com>
---
 testcases/kernel/syscalls/swapoff/swapoff01.c | 16 ++++++++---
 testcases/kernel/syscalls/swapoff/swapoff02.c | 20 ++++++++------
 testcases/kernel/syscalls/swapon/swapon02.c   | 27 ++++++++++++-------
 testcases/kernel/syscalls/swapon/swapon03.c   |  8 +++++-
 4 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c
index e3b445d05..af2a759cb 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff01.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff01.c
@@ -17,15 +17,19 @@
 #include "lapi/syscalls.h"
 #include "libswap.h"
 
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT"/testswap"
+#define SWAP_FILE	MNTPOINT"/swapfile"
+
 static void verify_swapoff(void)
 {
-	if (tst_syscall(__NR_swapon, "./swapfile01", 0) != 0) {
+	if (tst_syscall(__NR_swapon, SWAP_FILE, 0) != 0) {
 		tst_res(TFAIL | TERRNO, "Failed to turn on the swap file"
 			 ", skipping test iteration");
 		return;
 	}
 
-	TEST(tst_syscall(__NR_swapoff, "./swapfile01"));
+	TEST(tst_syscall(__NR_swapoff, SWAP_FILE));
 
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "Failed to turn off swapfile,"
@@ -38,17 +42,21 @@ static void verify_swapoff(void)
 
 static void setup(void)
 {
-	is_swap_supported("./tstswap");
+	is_swap_supported(TEST_FILE);
 
 	if (!tst_fs_has_free(".", 64, TST_MB))
 		tst_brk(TBROK,
 			"Insufficient disk space to create swap file");
 
-	if (make_swapfile("swapfile01", 65536, 1))
+	if (make_swapfile(SWAP_FILE, 65536, 1))
 		tst_brk(TBROK, "Failed to create file for swap");
 }
 
 static struct tst_test test = {
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.dev_min_size = 512,
+	.all_filesystems = 1,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.test_all = verify_swapoff,
diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c
index cd940b1e7..89ffd6ece 100644
--- a/testcases/kernel/syscalls/swapoff/swapoff02.c
+++ b/testcases/kernel/syscalls/swapoff/swapoff02.c
@@ -18,6 +18,10 @@
 #include "lapi/syscalls.h"
 #include "libswap.h"
 
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT"/testswap"
+#define SWAP_FILE	MNTPOINT"/swapfile"
+
 static int setup01(void);
 static void cleanup01(void);
 
@@ -32,8 +36,8 @@ static struct tcase {
 	void (*cleanup)(void);
 } tcases[] = {
 	{"path does not exist", ENOENT, "ENOENT", "./doesnotexist", NULL, NULL},
-	{"Invalid file", EINVAL, "EINVAL", "./swapfile01", NULL, NULL},
-	{"Permission denied", EPERM, "EPERM", "./swapfile01", setup01, cleanup01}
+	{"Invalid file", EINVAL, "EINVAL", SWAP_FILE, NULL, NULL},
+	{"Permission denied", EPERM, "EPERM", SWAP_FILE, setup01, cleanup01}
 };
 
 static void verify_swapoff(unsigned int i)
@@ -82,16 +86,16 @@ static void setup(void)
 	nobody = SAFE_GETPWNAM("nobody");
 	nobody_uid = nobody->pw_uid;
 
-	is_swap_supported("./tstswap");
-
-	if (!tst_fs_has_free(".", 1, TST_KB))
-		tst_brk(TBROK, "Insufficient disk space to create swap file");
+	is_swap_supported(TEST_FILE);
 
-	if (tst_fill_file("./swapfile01", 0x00, 1024, 1))
-		tst_brk(TBROK, "Failed to create swapfile");
+	if (make_swapfile(SWAP_FILE, 10, 1))
+		tst_brk(TBROK, "Failed to create file for swap");
 }
 
 static struct tst_test test = {
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.test = verify_swapoff,
diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c
index f5b0d6d56..d8ff16b08 100644
--- a/testcases/kernel/syscalls/swapon/swapon02.c
+++ b/testcases/kernel/syscalls/swapon/swapon02.c
@@ -20,6 +20,12 @@
 #include "lapi/syscalls.h"
 #include "libswap.h"
 
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT"/testswap"
+#define NOTSWAP_FILE	MNTPOINT"/notswap"
+#define SWAP_FILE	MNTPOINT"/swapfile"
+#define USED_FILE	MNTPOINT"/alreadyused"
+
 static uid_t nobody_uid;
 static int do_swapoff;
 
@@ -29,9 +35,9 @@ static struct tcase {
 	char *path;
 } tcases[] = {
 	{"Path does not exist", ENOENT, "./doesnotexist"},
-	{"Invalid path", EINVAL, "./notswap"},
-	{"Permission denied", EPERM, "./swapfile01"},
-	{"File already used", EBUSY, "./alreadyused"},
+	{"Invalid path", EINVAL, NOTSWAP_FILE},
+	{"Permission denied", EPERM, SWAP_FILE},
+	{"File already used", EBUSY, USED_FILE},
 };
 
 static void setup(void)
@@ -41,13 +47,13 @@ static void setup(void)
 	nobody = SAFE_GETPWNAM("nobody");
 	nobody_uid = nobody->pw_uid;
 
-	is_swap_supported("./tstswap");
+	is_swap_supported(TEST_FILE);
 
-	SAFE_TOUCH("notswap", 0777, NULL);
-	make_swapfile("swapfile01", 10, 0);
-	make_swapfile("alreadyused", 10, 0);
+	SAFE_TOUCH(NOTSWAP_FILE, 0777, NULL);
+	make_swapfile(SWAP_FILE, 10, 0);
+	make_swapfile(USED_FILE, 10, 0);
 
-	if (tst_syscall(__NR_swapon, "alreadyused", 0))
+	if (tst_syscall(__NR_swapon, USED_FILE, 0))
 		tst_res(TWARN | TERRNO, "swapon(alreadyused) failed");
 	else
 		do_swapoff = 1;
@@ -55,7 +61,7 @@ static void setup(void)
 
 static void cleanup(void)
 {
-	if (do_swapoff && tst_syscall(__NR_swapoff, "alreadyused"))
+	if (do_swapoff && tst_syscall(__NR_swapoff, USED_FILE))
 		tst_res(TWARN | TERRNO, "swapoff(alreadyused) failed");
 }
 
@@ -78,6 +84,9 @@ static void verify_swapon(unsigned int i)
 }
 
 static struct tst_test test = {
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.test = verify_swapon,
diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index e13009111..72f39e7c7 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -22,6 +22,9 @@
 #include "swaponoff.h"
 #include "libswap.h"
 
+#define MNTPOINT	"mntpoint"
+#define TEST_FILE	MNTPOINT"/testswap"
+
 static int setup_swap(void);
 static int clean_swap(void);
 static int check_and_swapoff(const char *filename);
@@ -256,7 +259,7 @@ static void setup(void)
 	if (access("/proc/swaps", F_OK))
 		tst_brk(TCONF, "swap not supported by kernel");
 
-	is_swap_supported("./tstswap");
+	is_swap_supported(TEST_FILE);
 }
 
 static void cleanup(void)
@@ -265,6 +268,9 @@ static void cleanup(void)
 }
 
 static struct tst_test test = {
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.forks_child = 1,
-- 
2.40.1



More information about the ltp mailing list