[LTP] [PATCH 1/1] swapon03: swapon() file on mounted filesystem

Petr Vorel pvorel@suse.cz
Mon Feb 12 20:26:12 CET 2024


Change in 009a407a0 left the testing actually on TMPDIR (i.e. not on
mounted filesystems), but it also failed on 6.7.0 openSUSE Tumbleweed
kernel (it worked on 6.8.0-rc1):

    # ./swapon03
    tst_supported_fs_types.c:49: TINFO: mkfs is not needed for tmpfs
    tst_test.c:1701: TINFO: === Testing on ext2 ===
    tst_test.c:1117: TINFO: Formatting /dev/loop0 with ext2 opts='' extra opts=''
    mke2fs 1.47.0 (5-Feb-2023)
    tst_test.c:1131: TINFO: Mounting /dev/loop0 to /tmp/LTP_swaqXc3II/mntpoint fstyp=ext2 flags=0
    tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
    Failed to create swapfile: swapfile02
    swapon03.c:181: TFAIL: Failed to setup swaps

While at it, use snprintf() consistently and remove error handling (we
newer use check for snprintf()), use TTERRNO.

Fixes: 009a407a0 ("swapon/off: enable all_filesystem in swap test")
Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
Hi,

this is a proper fix, replacing
https://patchwork.ozlabs.org/project/ltp/patch/20240205022857.191692-2-pvorel@suse.cz/

Kind regards,
Petr

 testcases/kernel/syscalls/swapon/swapon03.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 05fe2045f..2a0fc99e6 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -52,8 +52,7 @@ static void verify_swapon(void)
 	TEST(tst_syscall(__NR_swapon, swap_testfiles[0].filename, 0));
 
 	if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
-		tst_res(TPASS, "swapon(2) got expected failure (%d),",
-			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 "
@@ -151,14 +150,8 @@ static int setup_swap(void)
 		/*create and turn on remaining swapfiles */
 		for (j = 0; j < swapfiles; j++) {
 
-			/* prepare filename for the iteration */
-			if (sprintf(filename, "swapfile%02d", j + 2) < 0) {
-				printf("sprintf() failed to create "
-				       "filename");
-				exit(1);
-			}
-
 			/* Create the swapfile */
+			snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
 			make_swapfile(filename, 10, 0);
 
 			/* turn on the swap file */
@@ -196,14 +189,8 @@ static int clean_swap(void)
 	char filename[FILENAME_MAX];
 
 	for (j = 0; j < swapfiles; j++) {
-		if (snprintf(filename, sizeof(filename),
-			     "swapfile%02d", j + 2) < 0) {
-			tst_res(TWARN, "sprintf() failed to create filename");
-			tst_res(TWARN, "Failed to turn off swap files. System"
-				 " reboot after execution of LTP test"
-				 " suite is recommended");
-			return -1;
-		}
+		snprintf(filename, sizeof(filename), "%s%02d", TEST_FILE, j + 2);
+
 		if (check_and_swapoff(filename) != 0) {
 			tst_res(TWARN, "Failed to turn off swap file %s.", filename);
 			return -1;
-- 
2.43.0



More information about the ltp mailing list