public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API
@ 2024-02-26 13:53 Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 2/7] libltpswap: alter tst_count_swaps API Yang Xu via ltp
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

Currently, the kernel constant MAX_SWAPFILES value is calculated as below
------------------------------------
 #ifdef CONFIG_DEVICE_PRIVATE
 #define SWP_DEVICE_NUM 4
 #else
 #define SWP_DEVICE_NUM 0
 #endif

 #ifdef CONFIG_MIGRATION
 #define SWP_MIGRATION_NUM 3
 #else
 #define SWP_MIGRATION_NUM 0

 #ifdef CONFIG_MEMORY_FAILURE
 #define SWP_HWPOISON_NUM 1
 #else
 #define SWP_HWPOISON_NUM 0
 #endif

 #define SWP_PTE_MARKER_NUM 1
 #define MAX_SWAPFILES_SHIFT   5

 #define MAX_SWAPFILES \
	((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \
	SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \
	SWP_PTE_MARKER_NUM)
------------------------------------
Also, man-pages missed something after 5.14 kernel. I have sent two patches[1][2] to
add it. The kernel patches modify this kernel constant in[3][4][5][6]. Also, after kernel 6.2.0
[7],kernel always compile in pte markers.

[1]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=26f3ec74e
[2]https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=6bf3937fc
[3]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=5042db43cc
[4]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=b756a3b5e
[5]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=679d10331
[6]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=6c287605f
[7]https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/linux/swap.h?id=ca92ea3dc5

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/libswap.h         |  7 +++++++
 libs/libltpswap/libswap.c | 44 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/include/libswap.h b/include/libswap.h
index bdc5aacc6..cc68d5e6b 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -21,4 +21,11 @@ int make_swapfile(const char *swapfile, int blocks, int safe);
  * we are testing on.
  */
 bool is_swap_supported(const char *filename);
+
+/*
+ * Get kernel constant MAX_SWAPFILES value.
+ *
+ */
+int tst_max_swapfiles(void);
+
 #endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index c79de19d7..3528a3fb9 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -12,10 +12,13 @@
 #include <stdbool.h>
 
 #define TST_NO_DEFAULT_MAIN
+#define DEFAULT_MAX_SWAPFILE 32
 
 #include "tst_test.h"
 #include "libswap.h"
 #include "lapi/syscalls.h"
+#include "tst_kconfig.h"
+#include "tst_safe_stdio.h"
 
 static const char *const swap_supported_fs[] = {
 	"btrfs",
@@ -217,3 +220,44 @@ bool is_swap_supported(const char *filename)
 
 	return true;
 }
+
+/*
+ * Get kernel constant MAX_SWAPFILES value.
+ */
+int tst_max_swapfiles(void)
+{
+	unsigned int swp_migration_num = 0, swp_hwpoison_num = 0, swp_device_num = 0, swp_pte_marker_num = 0;
+	struct tst_kconfig_var migration = TST_KCONFIG_INIT("CONFIG_MIGRATION");
+	struct tst_kconfig_var memory = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
+	struct tst_kconfig_var device = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
+	struct tst_kconfig_var marker = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
+
+	tst_kconfig_read(&migration, 1);
+	tst_kconfig_read(&memory, 1);
+	tst_kconfig_read(&device, 1);
+	tst_kconfig_read(&marker, 1);
+
+	if (migration.choice == 'y') {
+		if (tst_kvercmp(5, 19, 0) < 0)
+			swp_migration_num = 2;
+		else
+			swp_migration_num = 3;
+	}
+
+	if (memory.choice == 'y')
+		swp_hwpoison_num = 1;
+
+	if (device.choice == 'y') {
+		if (tst_kvercmp(4, 14, 0) >= 0)
+			swp_device_num = 2;
+		if (tst_kvercmp(5, 14, 0) >= 0)
+			swp_device_num = 4;
+	}
+
+	if ((marker.choice == 'y' && tst_kvercmp(5, 19, 0) >= 0) ||
+		tst_kvercmp(6, 2, 0) >= 0) {
+		swp_pte_marker_num = 1;
+	}
+
+	return DEFAULT_MAX_SWAPFILE - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
+}
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 2/7] libltpswap: alter tst_count_swaps API
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() API Yang Xu via ltp
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

Like we count the IPC resource total, we can also add a
similar API for swapfiles, so we can use it for swapon03 case.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 include/libswap.h         |  5 +++++
 libs/libltpswap/libswap.c | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/libswap.h b/include/libswap.h
index cc68d5e6b..8c75e20ae 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -28,4 +28,9 @@ bool is_swap_supported(const char *filename);
  */
 int tst_max_swapfiles(void);
 
+/*
+ * Get the used swapfiles number.
+ */
+int tst_count_swaps(void);
+
 #endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 3528a3fb9..5e0c79b8f 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -261,3 +261,28 @@ int tst_max_swapfiles(void)
 
 	return DEFAULT_MAX_SWAPFILE - swp_migration_num - swp_hwpoison_num - swp_device_num - swp_pte_marker_num;
 }
+
+/*
+ * Get the used swapfiles number.
+ */
+int tst_count_swaps(void)
+{
+	FILE *fp;
+	int used = -1;
+	char c;
+
+	fp = SAFE_FOPEN("/proc/swaps", "r");
+	if (fp == NULL)
+		return -1;
+
+	while ((c = fgetc(fp)) != EOF) {
+		if (c == '\n')
+			used++;
+	}
+
+	SAFE_FCLOSE(fp);
+	if (used < 0)
+		tst_brk(TBROK, "can't read /proc/swaps to get used swapfiles resource total");
+
+	return used;
+}
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() API
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 2/7] libltpswap: alter tst_count_swaps API Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 4/7] swaponoff.h: Remove useless header Yang Xu via ltp
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/swapon/swapon03.c | 44 ++++-----------------
 1 file changed, 8 insertions(+), 36 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 2a0fc99e6..26385a5ae 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -19,7 +19,6 @@
 
 #include "tst_test.h"
 #include "lapi/syscalls.h"
-#include "swaponoff.h"
 #include "libswap.h"
 
 #define MNTPOINT	"mntpoint"
@@ -104,47 +103,20 @@ static void verify_swapon(void)
 static int setup_swap(void)
 {
 	pid_t pid;
-	int j, fd;
 	int status;
+	int j, max_swapfiles, used_swapfiles;
 	int res = 0;
 	char filename[FILENAME_MAX];
-	char buf[BUFSIZ + 1];
 
-	/* Find out how many swapfiles (1 line per entry) already exist */
-	swapfiles = 0;
-
-	if (seteuid(0) < 0)
-		tst_brk(TFAIL | TERRNO, "Failed to call seteuid");
-
-	/* This includes the first (header) line */
-	if ((fd = open("/proc/swaps", O_RDONLY)) == -1) {
-		tst_brk(TFAIL | TERRNO,
-			"Failed to find out existing number of swap files");
-	}
-	do {
-		char *p = buf;
-		res = read(fd, buf, BUFSIZ);
-		if (res < 0) {
-			tst_brk(TFAIL | TERRNO,
-				 "Failed to find out existing number of swap files");
-		}
-		buf[res] = '\0';
-		while ((p = strchr(p, '\n'))) {
-			p++;
-			swapfiles++;
-		}
-	} while (BUFSIZ <= res);
-	close(fd);
-	if (swapfiles)
-		swapfiles--;	/* don't count the /proc/swaps header */
-
-	if (swapfiles < 0)
-		tst_brk(TFAIL, "Failed to find existing number of swapfiles");
+	SAFE_SETEUID(0);
 
 	/* Determine how many more files are to be created */
-	swapfiles = MAX_SWAPFILES - swapfiles;
-	if (swapfiles > MAX_SWAPFILES)
-		swapfiles = MAX_SWAPFILES;
+	max_swapfiles = tst_max_swapfiles();
+	used_swapfiles = tst_count_swaps();
+	swapfiles = max_swapfiles - used_swapfiles;
+	if (swapfiles > max_swapfiles)
+		swapfiles = max_swapfiles;
+
 	pid = SAFE_FORK();
 	if (pid == 0) {
 		/*create and turn on remaining swapfiles */
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 4/7] swaponoff.h: Remove useless header
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 2/7] libltpswap: alter tst_count_swaps API Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() API Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-26 13:53 ` [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

Since we have use tst_max_swapfiles() api in swapon03.c, so this header
is useless and can be removed safely.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/swapon/swaponoff.h | 8 --------
 1 file changed, 8 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/swapon/swaponoff.h

diff --git a/testcases/kernel/syscalls/swapon/swaponoff.h b/testcases/kernel/syscalls/swapon/swaponoff.h
deleted file mode 100644
index 900761bda..000000000
--- a/testcases/kernel/syscalls/swapon/swaponoff.h
+++ /dev/null
@@ -1,8 +0,0 @@
-
-#ifndef __SWAP_ON_OFF_H_
-#define __SWAP_ON_OFF_H_
-
-#include <linux/version.h>
-#define MAX_SWAPFILES 30
-
-#endif
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
                   ` (2 preceding siblings ...)
  2024-02-26 13:53 ` [LTP] [PATCH v5 4/7] swaponoff.h: Remove useless header Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-28  7:32   ` Petr Vorel
  2024-02-26 13:53 ` [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

It seems this section doesn't affect anything, btw it is useless,
so remove it.

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/swapon/Makefile | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/Makefile b/testcases/kernel/syscalls/swapon/Makefile
index 53c795090..6954112a8 100644
--- a/testcases/kernel/syscalls/swapon/Makefile
+++ b/testcases/kernel/syscalls/swapon/Makefile
@@ -1,11 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) International Business Machines Corp., 2001
 
-NEEDSPECIAL	:= $(shell echo MAX_SWAPFILES | $(CC) -E -xc -include linux/swap.h 2>/dev/null - | tail -n 1 | grep 32; echo $?)
-ifneq ($(strip $(NEEDSPECIAL)),)
-export CFLAGS	+= -DOLDER_DISTRO_RELEASE
-endif
-
 top_srcdir		?= ../../../..
 
 LTPLIBS = ltpswap
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
                   ` (3 preceding siblings ...)
  2024-02-26 13:53 ` [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-28  7:24   ` Petr Vorel
  2024-02-26 13:53 ` [LTP] [PATCH v5 7/7] Add fallback for RHEL9 Yang Xu via ltp
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

By moving swapfile create stage from verify_swaopon and
test EPERM error more accurate. Also use glibc wrapper by
using swapon/swapoff instead of call syscall number directly
because glibc/musl/binoic also support them since long time ago.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 testcases/kernel/syscalls/swapon/swapon03.c | 167 +++++---------------
 1 file changed, 41 insertions(+), 126 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 26385a5ae..30410e1cd 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -16,7 +16,7 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <sys/wait.h>
-
+#include <sys/swap.h>
 #include "tst_test.h"
 #include "lapi/syscalls.h"
 #include "libswap.h"
@@ -24,88 +24,13 @@
 #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);
-
 static int swapfiles;
 
-int testfiles = 3;
-static struct swap_testfile_t {
-	char *filename;
-} swap_testfiles[] = {
-	{"firstswapfile"},
-	{"secondswapfile"},
-	{"thirdswapfile"}
-};
-
-int expected_errno = EPERM;
-
-static void verify_swapon(void)
-{
-	if (setup_swap() < 0) {
-		clean_swap();
-		tst_brk(TBROK, "Setup failed, quitting the test");
-	}
-
-	TEST(tst_syscall(__NR_swapon, swap_testfiles[0].filename, 0));
-
-	if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
-		tst_res(TPASS | TTERRNO, "swapon(2) got expected failure");
-	} else if (TST_RET < 0) {
-		tst_res(TFAIL | TTERRNO,
-			"swapon(2) failed to produce expected error "
-			"(%d). System reboot recommended.",
-			expected_errno);
-	} else {
-		/*
-		 * Probably the system supports MAX_SWAPFILES > 30, let's try with
-		 * MAX_SWAPFILES == 32. Call swapon sys call once again for 32
-		 * now we can't receive an error.
-		 */
-		TEST(tst_syscall(__NR_swapon, swap_testfiles[1].filename, 0));
-
-		/* Check return code (now we're expecting success) */
-		if (TST_RET < 0) {
-			tst_res(TFAIL | TTERRNO,
-				"swapon(2) got an unexpected failure");
-		} else {
-			/*
-			 * Call swapon sys call once again for 33 now we have to receive an error.
-			 */
-			TEST(tst_syscall(__NR_swapon, swap_testfiles[2].filename, 0));
-
-			/* Check return code (should be an error) */
-			if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
-				tst_res(TPASS,
-					"swapon(2) got expected failure;"
-					" Got errno = %d, probably your"
-					" MAX_SWAPFILES is 32",
-					expected_errno);
-			} else {
-				tst_res(TFAIL,
-					"swapon(2) failed to produce"
-					" expected error: %d, got %s."
-					" System reboot after execution of LTP"
-					" test suite is recommended.",
-					expected_errno, strerror(TST_ERR));
-			}
-		}
-	}
-
-	if (clean_swap() < 0)
-		tst_brk(TBROK, "Cleanup failed, quitting the test");
-}
-
-/*
- * Create 33 and activate 30 swapfiles.
- */
 static int setup_swap(void)
 {
 	pid_t pid;
 	int status;
 	int j, max_swapfiles, used_swapfiles;
-	int res = 0;
 	char filename[FILENAME_MAX];
 
 	SAFE_SETEUID(0);
@@ -127,16 +52,7 @@ static int setup_swap(void)
 			make_swapfile(filename, 10, 0);
 
 			/* turn on the swap file */
-			res = tst_syscall(__NR_swapon, filename, 0);
-			if (res != 0) {
-				if (errno == EPERM) {
-					printf("Successfully created %d swapfiles\n", j);
-					break;
-				} else {
-					printf("Failed to create swapfile: %s\n", filename);
-					exit(1);
-				}
-			}
+			TST_EXP_PASS_SILENT(swapon(filename, 0));
 		}
 		exit(0);
 	} else
@@ -145,13 +61,40 @@ static int setup_swap(void)
 	if (WEXITSTATUS(status))
 		tst_brk(TFAIL, "Failed to setup swaps");
 
-	/* Create all needed extra swapfiles for testing */
-	for (j = 0; j < testfiles; j++)
-		make_swapfile(swap_testfiles[j].filename, 10, 0);
+	tst_res(TINFO, "Successfully created %d swapfiles", swapfiles);
+	make_swapfile(TEST_FILE, 10, 0);
 
 	return 0;
 }
 
+/*
+ * Check if the file is at /proc/swaps and remove it giving swapoff
+ */
+static int check_and_swapoff(const char *filename)
+{
+	char cmd_buffer[256];
+	int rc = -1;
+
+	if (snprintf(cmd_buffer, sizeof(cmd_buffer),
+		"grep -q '%s.*file' /proc/swaps", filename) < 0) {
+		tst_res(TWARN, "sprintf() failed to create the command string");
+	} else {
+		rc = 0;
+		if (system(cmd_buffer) == 0) {
+			/* now we need to swapoff the file */
+			if (swapoff(filename) != 0) {
+				tst_res(TWARN, "Failed to turn off swap "
+					"file. system reboot after "
+					"execution of LTP test suite "
+					"is recommended");
+				rc = -1;
+			}
+		}
+	}
+
+	return rc;
+}
+
 /*
  * Turn off all swapfiles previously turned on
  */
@@ -169,49 +112,17 @@ static int clean_swap(void)
 		}
 	}
 
-	for (j = 0; j < testfiles; j++) {
-		if (check_and_swapoff(swap_testfiles[j].filename) != 0) {
-			tst_res(TWARN, "Failed to turn off swap file %s.",
-				 swap_testfiles[j].filename);
-			return -1;
-		}
+	if (check_and_swapoff("testfile") != 0) {
+		tst_res(TWARN, "Failed to turn off swap file testfile");
+		return -1;
 	}
 
 	return 0;
 }
 
-/*
- * Check if the file is at /proc/swaps and remove it giving swapoff
- */
-static int check_and_swapoff(const char *filename)
+static void verify_swapon(void)
 {
-	char cmd_buffer[256];
-	int rc = -1;
-
-	if (snprintf(cmd_buffer, sizeof(cmd_buffer),
-		     "grep -q '%s.*file' /proc/swaps", filename) < 0) {
-		tst_res(TWARN, "sprintf() failed to create the command string");
-	} else {
-
-		rc = 0;
-
-		if (system(cmd_buffer) == 0) {
-
-			/* now we need to swapoff the file */
-			if (tst_syscall(__NR_swapoff, filename) != 0) {
-
-				tst_res(TWARN, "Failed to turn off swap "
-					 "file. system reboot after "
-					 "execution of LTP test suite "
-					 "is recommended");
-				rc = -1;
-
-			}
-
-		}
-	}
-
-	return rc;
+	TST_EXP_FAIL(swapon(TEST_FILE, 0), EPERM, "swapon(%s, 0)", TEST_FILE);
 }
 
 static void setup(void)
@@ -220,6 +131,10 @@ static void setup(void)
 		tst_brk(TCONF, "swap not supported by kernel");
 
 	is_swap_supported(TEST_FILE);
+	if (setup_swap() < 0) {
+		clean_swap();
+		tst_brk(TBROK, "Setup failed, quitting the test");
+	}
 }
 
 static void cleanup(void)
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [LTP] [PATCH v5 7/7] Add fallback for RHEL9
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
                   ` (4 preceding siblings ...)
  2024-02-26 13:53 ` [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
@ 2024-02-26 13:53 ` Yang Xu via ltp
  2024-02-27  9:13 ` [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Li Wang
  2024-02-28  7:19 ` Petr Vorel
  7 siblings, 0 replies; 14+ messages in thread
From: Yang Xu via ltp @ 2024-02-26 13:53 UTC (permalink / raw)
  To: ltp

Since device number patch and pte number patch have been backported into
RHEL9,  we should add fallback for this distro.

Acked-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 libs/libltpswap/libswap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 5e0c79b8f..c8cbb8ea1 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -18,6 +18,7 @@
 #include "libswap.h"
 #include "lapi/syscalls.h"
 #include "tst_kconfig.h"
+#include "tst_kvercmp.h"
 #include "tst_safe_stdio.h"
 
 static const char *const swap_supported_fs[] = {
@@ -231,6 +232,11 @@ int tst_max_swapfiles(void)
 	struct tst_kconfig_var memory = TST_KCONFIG_INIT("CONFIG_MEMORY_FAILURE");
 	struct tst_kconfig_var device = TST_KCONFIG_INIT("CONFIG_DEVICE_PRIVATE");
 	struct tst_kconfig_var marker = TST_KCONFIG_INIT("CONFIG_PTE_MARKER");
+	struct tst_kern_exv kvers[] = {
+		/* RHEL9 kernel has patch 6c287605f and 679d10331 since 5.14.0-179 */
+		{ "RHEL9", "5.14.0-179" },
+		{ NULL, NULL},
+	};
 
 	tst_kconfig_read(&migration, 1);
 	tst_kconfig_read(&memory, 1);
@@ -238,7 +244,7 @@ int tst_max_swapfiles(void)
 	tst_kconfig_read(&marker, 1);
 
 	if (migration.choice == 'y') {
-		if (tst_kvercmp(5, 19, 0) < 0)
+		if (tst_kvercmp2(5, 19, 0, kvers) < 0)
 			swp_migration_num = 2;
 		else
 			swp_migration_num = 3;
@@ -254,7 +260,7 @@ int tst_max_swapfiles(void)
 			swp_device_num = 4;
 	}
 
-	if ((marker.choice == 'y' && tst_kvercmp(5, 19, 0) >= 0) ||
+	if ((marker.choice == 'y' && tst_kvercmp2(5, 19, 0, kvers) >= 0) ||
 		tst_kvercmp(6, 2, 0) >= 0) {
 		swp_pte_marker_num = 1;
 	}
-- 
2.39.3


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

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
                   ` (5 preceding siblings ...)
  2024-02-26 13:53 ` [LTP] [PATCH v5 7/7] Add fallback for RHEL9 Yang Xu via ltp
@ 2024-02-27  9:13 ` Li Wang
  2024-02-28 10:32   ` Yang Xu (Fujitsu) via ltp
  2024-02-28  7:19 ` Petr Vorel
  7 siblings, 1 reply; 14+ messages in thread
From: Li Wang @ 2024-02-27  9:13 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Xu, Petr,

The patch set generally looks good to me.

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


-- 
Regards,
Li Wang

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API
  2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
                   ` (6 preceding siblings ...)
  2024-02-27  9:13 ` [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Li Wang
@ 2024-02-28  7:19 ` Petr Vorel
  7 siblings, 0 replies; 14+ messages in thread
From: Petr Vorel @ 2024-02-28  7:19 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Yang Xu,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case
  2024-02-26 13:53 ` [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
@ 2024-02-28  7:24   ` Petr Vorel
  2024-02-28  8:15     ` Yang Xu (Fujitsu) via ltp
  0 siblings, 1 reply; 14+ messages in thread
From: Petr Vorel @ 2024-02-28  7:24 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Yang Xu,

> By moving swapfile create stage from verify_swaopon and
> test EPERM error more accurate. Also use glibc wrapper by
> using swapon/swapoff instead of call syscall number directly
> because glibc/musl/binoic also support them since long time ago.
s/binoic/bionic/

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES
  2024-02-26 13:53 ` [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
@ 2024-02-28  7:32   ` Petr Vorel
  0 siblings, 0 replies; 14+ messages in thread
From: Petr Vorel @ 2024-02-28  7:32 UTC (permalink / raw)
  To: Yang Xu; +Cc: ltp

Hi Yang Xu,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case
  2024-02-28  7:24   ` Petr Vorel
@ 2024-02-28  8:15     ` Yang Xu (Fujitsu) via ltp
  2024-02-28 13:27       ` Petr Vorel
  0 siblings, 1 reply; 14+ messages in thread
From: Yang Xu (Fujitsu) via ltp @ 2024-02-28  8:15 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp@lists.linux.it

Hi Petr

> Hi Yang Xu,
> 
>> By moving swapfile create stage from verify_swaopon and
>> test EPERM error more accurate. Also use glibc wrapper by
>> using swapon/swapoff instead of call syscall number directly
>> because glibc/musl/binoic also support them since long time ago.
> s/binoic/bionic/
> 
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks for your nice review. Sorry, when your review v4 patch, I don't 
solve all comment in v5. So I did it in my own ltp fork branch named as 
v5_max_swapfiles[1](such as swapfiles => swap file, snprint return 
value, else branch....).

ps: Only the 6th patch was modified, other patches aren't modified. If 
you see no problem, I plan to merge this patchset today.

[1]https://github.com/xuyang0410/ltp/commits/v5_max_swapfiles/

Best Regards
Yang Xu
> 
> Kind regards,
> Petr

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API
  2024-02-27  9:13 ` [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Li Wang
@ 2024-02-28 10:32   ` Yang Xu (Fujitsu) via ltp
  0 siblings, 0 replies; 14+ messages in thread
From: Yang Xu (Fujitsu) via ltp @ 2024-02-28 10:32 UTC (permalink / raw)
  To: Li Wang; +Cc: ltp@lists.linux.it

Hi Li, Petr

> Hi Xu, Petr,
> 
> The patch set generally looks good to me.
> 
> Reviewed-by: Li Wang <liwang@redhat.com <mailto:liwang@redhat.com>>

Thanks for your review, merged!

Best Regars
Yang Xu
> 
> 
> -- 
> Regards,
> Li Wang

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case
  2024-02-28  8:15     ` Yang Xu (Fujitsu) via ltp
@ 2024-02-28 13:27       ` Petr Vorel
  0 siblings, 0 replies; 14+ messages in thread
From: Petr Vorel @ 2024-02-28 13:27 UTC (permalink / raw)
  To: Yang Xu (Fujitsu); +Cc: ltp@lists.linux.it

Hi Yang Xu,

> Hi Petr

> > Hi Yang Xu,

> >> By moving swapfile create stage from verify_swaopon and
> >> test EPERM error more accurate. Also use glibc wrapper by
> >> using swapon/swapoff instead of call syscall number directly
> >> because glibc/musl/binoic also support them since long time ago.
> > s/binoic/bionic/

> > Reviewed-by: Petr Vorel <pvorel@suse.cz>

> Thanks for your nice review. Sorry, when your review v4 patch, I don't 
> solve all comment in v5. So I did it in my own ltp fork branch named as 
> v5_max_swapfiles[1](such as swapfiles => swap file, snprint return 
> value, else branch....).

> ps: Only the 6th patch was modified, other patches aren't modified. If 
> you see no problem, I plan to merge this patchset today.

[2] looks good to me, please merge. Very nit (feel free to ignore):
snprintf(cmd_buffer, ...) is too long, renaming cmd_buffer just to buf would
shorten whole line.

Kind regards,
Petr

> [1]https://github.com/xuyang0410/ltp/commits/v5_max_swapfiles/

[2] https://github.com/xuyang0410/ltp/commit/9e83b1fb1d8f8631122c70a336aacd28f94d8343

> Best Regards
> Yang Xu

> > Kind regards,
> > Petr

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

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-02-28 13:28 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-26 13:53 [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Yang Xu via ltp
2024-02-26 13:53 ` [LTP] [PATCH v5 2/7] libltpswap: alter tst_count_swaps API Yang Xu via ltp
2024-02-26 13:53 ` [LTP] [PATCH v5 3/7] syscalls/swapon03: use tst_max_swapfiles() and GET_USED_SWAPFILES() API Yang Xu via ltp
2024-02-26 13:53 ` [LTP] [PATCH v5 4/7] swaponoff.h: Remove useless header Yang Xu via ltp
2024-02-26 13:53 ` [LTP] [PATCH v5 5/7] swapon/Makefile: Remove useless section for MAX_SWAPFILES Yang Xu via ltp
2024-02-28  7:32   ` Petr Vorel
2024-02-26 13:53 ` [LTP] [PATCH v5 6/7] syscalls/swapon03: Simply this case Yang Xu via ltp
2024-02-28  7:24   ` Petr Vorel
2024-02-28  8:15     ` Yang Xu (Fujitsu) via ltp
2024-02-28 13:27       ` Petr Vorel
2024-02-26 13:53 ` [LTP] [PATCH v5 7/7] Add fallback for RHEL9 Yang Xu via ltp
2024-02-27  9:13 ` [LTP] [PATCH v5 1/7] libltpswap: Add tst_max_swapfiles API Li Wang
2024-02-28 10:32   ` Yang Xu (Fujitsu) via ltp
2024-02-28  7:19 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox