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

Richard Palethorpe rpalethorpe@suse.de
Tue Mar 7 09:35:29 CET 2023


Hello,

Yang Xu <xuyang2018.jy@fujitsu.com> writes:

> For old kernel(below 5.3) that doesn't support clone3, tst_clone returns
> -2 instead of -1. So we can't use TST_EXP_EQ_LI api.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

Thanks, I suppose this could be avoided in the future by hinting that
the return type is more complex than the usual for clone

typedef tst_clone_return_t pid_t;

enum tst_clone_error {
  TST_CLONE_ERROR = -2,
  TST_CLONE3_ERROR = -1
};

Possibly we could force a cast somehow? Otherwise it's just a hint.

> ---
>  testcases/kernel/containers/utsname/utsname04.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/testcases/kernel/containers/utsname/utsname04.c b/testcases/kernel/containers/utsname/utsname04.c
> index e8d636d0d..61cc066d8 100644
> --- a/testcases/kernel/containers/utsname/utsname04.c
> +++ b/testcases/kernel/containers/utsname/utsname04.c
> @@ -29,7 +29,13 @@ 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);
> +		TEST(tst_clone(&cargs));
> +		if (TST_RET == -1)
> +			tst_res(TPASS, "clone3() fails as expected");
> +		else if (TST_RET == -2)
> +			tst_res(TPASS, "clone() fails as expected");
> +		else
> +			tst_res(TFAIL, "tst_clone returns %ld", TST_RET);
>  		TST_EXP_PASS(errno == EPERM);
>  	} else {
>  		if (!SAFE_FORK()) {
> -- 
> 2.39.1


-- 
Thank you,
Richard.


More information about the ltp mailing list