[LTP] [PATCH v1] Remove ltp_quick_clone from mountns testing suite

Richard Palethorpe rpalethorpe@suse.de
Tue Mar 7 13:26:38 CET 2023


Hello,

Andrea Cervesato via ltp <ltp@lists.linux.it> writes:

> ltp_quick_clone has been replaced by SAFE_CLONE in the mountns testing
> suite that now is independed from libclone and legacy API.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
>  testcases/kernel/containers/mountns/mountns.h  | 18 ------------------
>  .../kernel/containers/mountns/mountns01.c      | 16 ++++++++--------
>  .../kernel/containers/mountns/mountns02.c      | 16 ++++++++--------
>  .../kernel/containers/mountns/mountns03.c      | 16 ++++++++--------
>  .../kernel/containers/mountns/mountns04.c      |  2 +-
>  5 files changed, 25 insertions(+), 43 deletions(-)
>
> diff --git a/testcases/kernel/containers/mountns/mountns.h b/testcases/kernel/containers/mountns/mountns.h
> index 615f1a058..9bb854659 100644
> --- a/testcases/kernel/containers/mountns/mountns.h
> +++ b/testcases/kernel/containers/mountns/mountns.h
> @@ -8,28 +8,10 @@
>  #define COMMON_H
>  
>  #include "tst_test.h"
> -#include "lapi/sched.h"
>  
>  #define DIRA "LTP_DIR_A"
>  #define DIRB "LTP_DIR_B"
>  
> -static int dummy_child(void *v)
> -{
> -	(void)v;
> -	return 0;
> -}
> -
> -static void check_newns(void)
> -{
> -	int pid, status;
> -
> -	pid = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, dummy_child, NULL);
> -	if (pid < 0)
> -		tst_brk(TCONF, "CLONE_NEWNS not supported");
> -
> -	SAFE_WAIT(&status);
> -}
> -

If we remove this then we need to check the kernel config for namespace
support. Which you were doing in other tests IIRC.

Otherwise looks good, but setting to changes requested.

>  static void umount_folders(void)
>  {
>  	if (tst_is_mounted(DIRA))
> diff --git a/testcases/kernel/containers/mountns/mountns01.c b/testcases/kernel/containers/mountns/mountns01.c
> index e8f176920..c5b6077f1 100644
> --- a/testcases/kernel/containers/mountns/mountns01.c
> +++ b/testcases/kernel/containers/mountns/mountns01.c
> @@ -33,8 +33,9 @@
>  #include <sys/mount.h>
>  #include "mountns.h"
>  #include "tst_test.h"
> +#include "lapi/sched.h"
>  
> -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
> +static void child_func(void)
>  {
>  	TST_CHECKPOINT_WAIT(0);
>  
> @@ -51,13 +52,11 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
>  	TST_CHECKPOINT_WAKE_AND_WAIT(0);
>  
>  	SAFE_UMOUNT(DIRA);
> -
> -	return 0;
>  }
>  
>  static void run(void)
>  {
> -	int ret;
> +	const struct tst_clone_args args = { CLONE_NEWNS, SIGCHLD };
>  
>  	SAFE_UNSHARE(CLONE_NEWNS);
>  
> @@ -67,9 +66,10 @@ static void run(void)
>  	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
>  	SAFE_MOUNT("none", DIRA, "none", MS_SHARED, NULL);
>  
> -	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
> -	if (ret < 0)
> -		tst_brk(TBROK, "clone failed");
> +	if (!SAFE_CLONE(&args)) {
> +		child_func();
> +		return;
> +	}
>  
>  	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
>  
> @@ -93,7 +93,6 @@ static void run(void)
>  
>  static void setup(void)
>  {
> -	check_newns();
>  	create_folders();
>  }
>  
> @@ -107,5 +106,6 @@ static struct tst_test test = {
>  	.cleanup = cleanup,
>  	.test_all = run,
>  	.needs_root = 1,
> +	.forks_child = 1,
>  	.needs_checkpoints = 1,
>  };
> diff --git a/testcases/kernel/containers/mountns/mountns02.c b/testcases/kernel/containers/mountns/mountns02.c
> index 4b85fa79b..c2260961e 100644
> --- a/testcases/kernel/containers/mountns/mountns02.c
> +++ b/testcases/kernel/containers/mountns/mountns02.c
> @@ -34,8 +34,9 @@
>  #include <sys/mount.h>
>  #include "mountns.h"
>  #include "tst_test.h"
> +#include "lapi/sched.h"
>  
> -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
> +static void child_func(void)
>  {
>  	TST_CHECKPOINT_WAIT(0);
>  
> @@ -51,13 +52,11 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
>  	TST_CHECKPOINT_WAKE_AND_WAIT(0);
>  
>  	SAFE_UMOUNT(DIRA);
> -
> -	return 0;
>  }
>  
>  static void run(void)
>  {
> -	int ret;
> +	const struct tst_clone_args args = { CLONE_NEWNS, SIGCHLD };
>  
>  	SAFE_UNSHARE(CLONE_NEWNS);
>  
> @@ -68,9 +67,10 @@ static void run(void)
>  
>  	SAFE_MOUNT("none", DIRA, "none", MS_PRIVATE, NULL);
>  
> -	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
> -	if (ret < 0)
> -		tst_brk(TBROK, "clone failed");
> +	if (!SAFE_CLONE(&args)) {
> +		child_func();
> +		return;
> +	}
>  
>  	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
>  
> @@ -94,7 +94,6 @@ static void run(void)
>  
>  static void setup(void)
>  {
> -	check_newns();
>  	create_folders();
>  }
>  
> @@ -108,5 +107,6 @@ static struct tst_test test = {
>  	.cleanup = cleanup,
>  	.test_all = run,
>  	.needs_root = 1,
> +	.forks_child = 1,
>  	.needs_checkpoints = 1,
>  };
> diff --git a/testcases/kernel/containers/mountns/mountns03.c b/testcases/kernel/containers/mountns/mountns03.c
> index 1d26a25d8..357a4f30b 100644
> --- a/testcases/kernel/containers/mountns/mountns03.c
> +++ b/testcases/kernel/containers/mountns/mountns03.c
> @@ -36,8 +36,9 @@
>  #include <sys/mount.h>
>  #include "mountns.h"
>  #include "tst_test.h"
> +#include "lapi/sched.h"
>  
> -static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
> +static void child_func(void)
>  {
>  	/*
>  	 * makes mount DIRA a slave of DIRA (all slave mounts have
> @@ -59,13 +60,11 @@ static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
>  	TST_CHECKPOINT_WAKE_AND_WAIT(0);
>  
>  	SAFE_UMOUNT(DIRA);
> -
> -	return 0;
>  }
>  
>  static void run(void)
>  {
> -	int ret;
> +	const struct tst_clone_args args = { CLONE_NEWNS, SIGCHLD };
>  
>  	SAFE_UNSHARE(CLONE_NEWNS);
>  
> @@ -76,9 +75,10 @@ static void run(void)
>  
>  	SAFE_MOUNT("none", DIRA, "none", MS_SHARED, NULL);
>  
> -	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
> -	if (ret < 0)
> -		tst_brk(TBROK, "clone failed");
> +	if (!SAFE_CLONE(&args)) {
> +		child_func();
> +		return;
> +	}
>  
>  	TST_CHECKPOINT_WAIT(0);
>  
> @@ -104,7 +104,6 @@ static void run(void)
>  
>  static void setup(void)
>  {
> -	check_newns();
>  	create_folders();
>  }
>  
> @@ -118,5 +117,6 @@ static struct tst_test test = {
>  	.cleanup = cleanup,
>  	.test_all = run,
>  	.needs_root = 1,
> +	.forks_child = 1,
>  	.needs_checkpoints = 1,
>  };
> diff --git a/testcases/kernel/containers/mountns/mountns04.c b/testcases/kernel/containers/mountns/mountns04.c
> index fc392f1a7..6a64c2443 100644
> --- a/testcases/kernel/containers/mountns/mountns04.c
> +++ b/testcases/kernel/containers/mountns/mountns04.c
> @@ -22,6 +22,7 @@
>  #include <sys/mount.h>
>  #include "mountns.h"
>  #include "tst_test.h"
> +#include "lapi/sched.h"
>  
>  static void run(void)
>  {
> @@ -46,7 +47,6 @@ static void run(void)
>  
>  static void setup(void)
>  {
> -	check_newns();
>  	create_folders();
>  }
>  
> -- 
> 2.35.3


-- 
Thank you,
Richard.


More information about the ltp mailing list