[LTP] [PATCH v2 2/5] swapon03: Cleanup

Petr Vorel
2025-11-06T16:35:42Z

- Remove unused return code in check_and_swapoff() and setup_swap(). The
purpose was to run cleanup() in the end of the setup() if creating
swap fails, but return code is always 0. Also cleanup() should be run
when test exits with tst_brk() anyway.
- Change return code from TFAIL to TBROK.
- Add missing brackets.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
The same as in v1.
I can split this if you like.

testcases/kernel/syscalls/swapon/swapon03.c | 23 +++++++--------------
1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
index 01a3b6d8ac..d9822c01ef 100644
--- a/testcases/kernel/syscalls/swapon/swapon03.c
+++ b/testcases/kernel/syscalls/swapon/swapon03.c
@@ -25,7 +25,7 @@

static int swapfiles;

-static int setup_swap(void)
+static void setup_swap(void)
{
pid_t pid;
int status;
@@ -54,33 +54,27 @@ static int setup_swap(void)
TST_EXP_PASS_SILENT(swapon(filename, 0));
}
exit(0);
- } else
+ } else {
waitpid(pid, &status, 0);
+ }

if (WEXITSTATUS(status))
- tst_brk(TFAIL, "Failed to setup swap files");
+ tst_brk(TBROK, "Failed to setup swap files");

tst_res(TINFO, "Successfully created %d swap files", swapfiles);
-
- 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 check_and_swapoff(const char *filename)
{
char cmd_buffer[256];
- int rc = -1;

snprintf(cmd_buffer, sizeof(cmd_buffer), "grep -q '%s.*file' /proc/swaps", filename);

- if (system(cmd_buffer) == 0 && swapoff(filename) != 0) {
+ if (system(cmd_buffer) == 0 && swapoff(filename) != 0)
tst_res(TWARN, "Failed to swapoff %s", filename);
- rc = -1;
- }
-
- return rc;
}

/*
@@ -110,10 +104,7 @@ 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");
- }
+ setup_swap();
}

static void cleanup(void)
--
2.51.0