[LTP] [PATCH] containers/utsname04: don't use TST_EXP_EQ_LI for tst_clone

Andrea Cervesato andrea.cervesato@suse.com
Tue Feb 28 10:06:32 CET 2023


Hi!

On 2/28/23 09:44, Yang Xu wrote:

> For old kernel that doesn't support clone3, tst_clone returns
it would be nice to add unsupported kernel version inside patch comment 
(in this case, anything below 5.3).
> -2 instead of -1. So we can't use TST_EXP_EQ_LI api.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>   testcases/kernel/containers/utsname/utsname04.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/containers/utsname/utsname04.c b/testcases/kernel/containers/utsname/utsname04.c
> index e8d636d0d..1adc4542c 100644
> --- a/testcases/kernel/containers/utsname/utsname04.c
> +++ b/testcases/kernel/containers/utsname/utsname04.c
> @@ -22,6 +22,7 @@ static void run(void)
>   {
>   	const struct tst_clone_args cargs = { CLONE_NEWUTS, SIGCHLD };
>   	struct passwd *pw;
> +	pid_t pid;
>   
>   	tst_res(TINFO, "Dropping root privileges");
>   
> @@ -29,7 +30,11 @@ static void run(void)
>   	SAFE_SETRESUID(pw->pw_uid, pw->pw_uid, pw->pw_uid);
>   
>   	if (!str_op || !strcmp(str_op, "clone")) {
> -		TST_EXP_EQ_LI(tst_clone(&cargs), -1);

Did you try this?

TST_EXP_FAIL(tst_clone(&cargs), EPERM);

> +		pid = tst_clone(&cargs);
> +		if (pid == -1 || pid == -2)
> +			tst_res(TPASS, "clone() returns an expected value %d", pid);
> +		else
> +			tst_res(TFAIL, "clone() returns an unexpected value %d", pid);
>   		TST_EXP_PASS(errno == EPERM);
>   	} else {
>   		if (!SAFE_FORK()) {

Regards,
Andrea



More information about the ltp mailing list