All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Wang <liwang@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 8/8] libswap: Refactor is_swap_supported function to return status
Date: Sun, 28 Jan 2024 10:48:38 +0800	[thread overview]
Message-ID: <20240128024838.2699248-9-liwang@redhat.com> (raw)
In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com>

This updates the is_swap_supported function in the libltpswap
to return an integer status instead of void, allowing the function
to communicate success or failure to the caller. It introduces
checks and returns 0 on various failure conditions while logging
the failure without aborting the test case.

Signed-off-by: Li Wang <liwang@redhat.com>
---
 include/libswap.h         |  2 +-
 libs/libltpswap/libswap.c | 28 ++++++++++++++++++----------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/include/libswap.h b/include/libswap.h
index e67d65756..1e09db031 100644
--- a/include/libswap.h
+++ b/include/libswap.h
@@ -20,5 +20,5 @@ int make_swapfile(const char *swapfile, int blocks, int safe);
  * Check swapon/swapoff support status of filesystems or files
  * we are testing on.
  */
-void is_swap_supported(const char *filename);
+int is_swap_supported(const char *filename);
 #endif /* __LIBSWAP_H__ */
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 8aecad48d..14b7d9e3a 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -168,7 +168,7 @@ int make_swapfile(const char *swapfile, int blocks, int safe)
  * Check swapon/swapoff support status of filesystems or files
  * we are testing on.
  */
-void is_swap_supported(const char *filename)
+int is_swap_supported(const char *filename)
 {
 	int i, sw_support = 0;
 	int ret = make_swapfile(filename, 10, 1);
@@ -188,23 +188,31 @@ void is_swap_supported(const char *filename)
 	}
 
 	if (ret != 0) {
-		if (fi_contiguous == 0 && sw_support == 0)
+		if (fi_contiguous == 0 && sw_support == 0) {
 			tst_brk(TCONF, "mkswap on %s not supported", fstype);
-		else
-			tst_brk(TFAIL, "mkswap on %s failed", fstype);
+		} else {
+			tst_res(TFAIL, "mkswap on %s failed", fstype);
+			return 0;
+		}
 	}
 
 	TEST(tst_syscall(__NR_swapon, filename, 0));
 	if (TST_RET == -1) {
-		if (errno == EPERM)
+		if (errno == EPERM) {
 			tst_brk(TCONF, "Permission denied for swapon()");
-		else if (errno == EINVAL && fi_contiguous == 0 && sw_support == 0)
+		} else if (errno == EINVAL && fi_contiguous == 0 && sw_support == 0) {
 			tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
-		else
-			tst_brk(TFAIL | TTERRNO, "swapon() on %s failed", fstype);
+		} else {
+			tst_res(TFAIL | TTERRNO, "swapon() on %s failed", fstype);
+			return 0;
+		}
 	}
 
 	TEST(tst_syscall(__NR_swapoff, filename, 0));
-	if (TST_RET == -1)
-		tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "swapoff on %s failed", fstype);
+		return 0;
+	}
+
+	return (TST_RET == 0);
 }
-- 
2.40.1


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

  parent reply	other threads:[~2024-01-28  2:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-28  2:48 [LTP] [PATCH v5 0/8] improvement work on libswap library Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 1/8] libswap: add known swap supported fs check Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 2/8] swapon01: Test on all filesystems Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 3/8] swapon01: Improving test with memory limits and swap reporting Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 4/8] libswap: add function to prealloc contiguous file Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 5/8] libswap: Introduce file contiguity check Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 6/8] libswap: customize swapfile size Li Wang
2024-01-28  2:48 ` [LTP] [PATCH v5 7/8] swapon/off: enable all_filesystem in swap test Li Wang
2024-01-29  8:03   ` Petr Vorel
2024-01-29  8:26     ` Li Wang
2024-01-28  2:48 ` Li Wang [this message]
2024-01-29  8:03   ` [LTP] [PATCH v5 8/8] libswap: Refactor is_swap_supported function to return status Petr Vorel
2024-01-29 11:36     ` Li Wang
2024-01-29 12:22       ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240128024838.2699248-9-liwang@redhat.com \
    --to=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.