[LTP] [PATCH 2/3] syscalls/swapon03: Use get_maxswapfiles() api instead of hard code

Yang Xu (Fujitsu) xuyang2018.jy@fujitsu.com
Fri Dec 22 02:39:26 CET 2023


Hi Li, Petr

I am writting v2 patch that introduce another libltpswap api named
as get_used_swapfiles like we did in ipc library.

But I found libltpswap and swapon/swapoff cases all use swapon/swapff 
syscall directly instead of glibc wrapper. IMO, on old glibc/other libc 
doesn't support this wrapper so it use syscall directly. Can I replace 
them by glibc wrapper directly?

Best Regards
Yang Xu

> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>   testcases/kernel/syscalls/swapon/swapon03.c | 47 +++------------------
>   1 file changed, 6 insertions(+), 41 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c
> index dc633ebc6..744fca3d1 100644
> --- a/testcases/kernel/syscalls/swapon/swapon03.c
> +++ b/testcases/kernel/syscalls/swapon/swapon03.c
> @@ -19,14 +19,12 @@
>   
>   #include "tst_test.h"
>   #include "lapi/syscalls.h"
> -#include "swaponoff.h"
>   #include "libswap.h"
>   
>   static int setup_swap(void);
>   static int clean_swap(void);
>   static int check_and_swapoff(const char *filename);
> -
> -static int swapfiles;
> +static int swapfiles, max_swapfiles;
>   
>   int testfiles = 3;
>   static struct swap_testfile_t {
> @@ -57,47 +55,13 @@ static void verify_swapon(void)
>   			"(%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));
> -			}
> -		}
> +		tst_res(TFAIL, "swapon(2) succeeded unexpectedly");
>   	}
>   
>   	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;
> @@ -139,9 +103,10 @@ static int setup_swap(void)
>   		tst_brk(TFAIL, "Failed to find existing number of swapfiles");
>   
>   	/* Determine how many more files are to be created */
> -	swapfiles = MAX_SWAPFILES - swapfiles;
> -	if (swapfiles > MAX_SWAPFILES)
> -		swapfiles = MAX_SWAPFILES;
> +	max_swapfiles = (int)get_maxswapfiles();
> +	swapfiles = max_swapfiles - swapfiles;
> +	if (swapfiles > max_swapfiles)
> +		swapfiles = max_swapfiles;
>   	pid = SAFE_FORK();
>   	if (pid == 0) {
>   		/*create and turn on remaining swapfiles */


More information about the ltp mailing list