[LTP] [PATCH] open04: add EMFILE check

Petr Vorel pvorel@suse.cz
Thu Sep 15 14:52:21 CEST 2022


Hi LI,

> [pre-release testing fix]

> Test in automation easily get EMFILE error before reaching the fds_limit,
> but hard to reproduce it again manually. The possible reason is that some
> shared fd being opened in the parent shell and occupying the fd numbers
> which inherited by test then results in open failed with EMFILE early.

> This patch adds back of the EMFILE check in the open() loops, to flexible
> test fd limitation.

>   open04.c:36: TBROK: open(open04.1020,66,0777) failed: EMFILE (24)
>   open04.c:53: TWARN: close(0) failed: EBADF (9)

> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  testcases/kernel/syscalls/open/open04.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)

> diff --git a/testcases/kernel/syscalls/open/open04.c b/testcases/kernel/syscalls/open/open04.c
> index d452405d4..01a8b12d6 100644
> --- a/testcases/kernel/syscalls/open/open04.c
> +++ b/testcases/kernel/syscalls/open/open04.c
> @@ -33,7 +33,12 @@ static void setup(void)

>  	for (i = first + 1; i < fds_limit; i++) {
>  		sprintf(fname, FNAME ".%d", i);
> -		fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0777);
> +		fd = open(fname, O_RDWR | O_CREAT, 0777);
> +		if (fd == -1) {
> +			if (errno != EMFILE)
> +				tst_brk(TBROK, "Expected EMFILE but got %d", errno);
> +			break;
> +		}
>  		fds[i - first] = fd;
>  	}
>  }

LGTM.
Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr



More information about the ltp mailing list