public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Edward Liaw <edliaw@google.com>
Cc: kernel-team@android.com, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] pipe07: close /proc/self/fd after counting fds
Date: Sat, 30 Sep 2023 08:34:38 +0200	[thread overview]
Message-ID: <20230930063438.GB414289@pevik> (raw)
In-Reply-To: <20230930000007.4052837-1-edliaw@google.com>

Hi Edward,

> Leaving the directory fd open will count against the max number of fds
> opened, so the final expected count will be off.

> Also, removed the halving / doubling of exp_num_pipes since it is
> redundant.

> Signed-off-by: Edward Liaw <edliaw@google.com>
> ---
>  testcases/kernel/syscalls/pipe/pipe07.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

> diff --git a/testcases/kernel/syscalls/pipe/pipe07.c b/testcases/kernel/syscalls/pipe/pipe07.c
> index 196485684..01f6b78f8 100644
> --- a/testcases/kernel/syscalls/pipe/pipe07.c
> +++ b/testcases/kernel/syscalls/pipe/pipe07.c
> @@ -45,6 +45,8 @@ static int record_open_fds(void)
>  		opened_fds[num_opened_fds++] = fd;
>  	}

> +	SAFE_CLOSEDIR(dir);
IMHO this changes counting from 1020:

pipe07.c:56: TINFO: getdtablesize() = 1024
pipe07.c:60: TINFO: expected max fds to be opened by pipe(): 1020
pipe07.c:75: TPASS: errno == EMFILE (24)
pipe07.c:76: TPASS: exp_num_pipes * 2 == num_pipe_fds (1020)

to 1021, which leads to failure:

pipe07.c:58: TINFO: getdtablesize() = 1024
pipe07.c:62: TINFO: expected max fds to be opened by pipe(): 1021
pipe07.c:77: TPASS: errno == EMFILE (24)
pipe07.c:78: TFAIL: exp_num_pipes (1021) != num_pipe_fds (1020)

> +
>  	return num_opened_fds;
This is not elegant, but get's the correct count. Will it fail on AOSP?

return num_opened_fds + 1;
>  }

> @@ -56,8 +58,8 @@ static void setup(void)
>  	tst_res(TINFO, "getdtablesize() = %d", max_fds);
>  	pipe_fds = SAFE_MALLOC(max_fds * sizeof(int));

> -	exp_num_pipes = (max_fds - record_open_fds()) / 2;
> -	tst_res(TINFO, "expected max fds to be opened by pipe(): %d", exp_num_pipes * 2);
> +	exp_num_pipes = max_fds - record_open_fds();
> +	tst_res(TINFO, "expected max fds to be opened by pipe(): %d", exp_num_pipes);

It'd be slightly more readable if this was in separate patch
(as it modifies the same variable), but it's up to you.

Kind regards,
Petr

>  }

>  static void run(void)
> @@ -73,7 +75,7 @@ static void run(void)
>  	} while (!TST_RET);

>  	TST_EXP_EQ_LI(errno, EMFILE);
> -	TST_EXP_EQ_LI(exp_num_pipes * 2, num_pipe_fds);
> +	TST_EXP_EQ_LI(exp_num_pipes, num_pipe_fds);

>  	for (int i = 0; i < num_pipe_fds; i++)
>  		SAFE_CLOSE(pipe_fds[i]);

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2023-09-30  6:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30  0:00 [LTP] [PATCH] pipe07: close /proc/self/fd after counting fds Edward Liaw via ltp
2023-09-30  6:34 ` Petr Vorel [this message]
2023-10-01  4:21   ` Edward Liaw via ltp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230930063438.GB414289@pevik \
    --to=pvorel@suse.cz \
    --cc=edliaw@google.com \
    --cc=kernel-team@android.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox