pty09: Cap RLIMIT_NOFILE-based slave PTY opens
PATCH 1/1 pty09: Cap RLIMIT_NOFILE-based slave PTY opens
pty09 derives the number of slave PTY opens from RLIMIT_NOFILE. When the limit is very large, for example 1048576, the test tries to open nearly one million slave PTYs on the same master. That makes the workload depend on the caller's file descriptor limit instead of the PTY behavior being tested, and can turn a working PTY open path into a timeout-driven TBROK.
The test only needs to verify that a slave pseudo-terminal can be opened multiple times in parallel. Cap the number of slave opens at 4096 so the test remains representative and deterministic even when RLIMIT_NOFILE is set unusually high.
--- testcases/kernel/pty/pty09.c | 4 ++++ 1 file changed, 4 insertions(+)
testcases/kernel/pty/pty09.c +4 -0
@@ -14,6 +14,8 @@static int masterfd =-1 ; +#define MAX_SLAVE_OPENS 4096 +static unsigned int count_avail_pid (void ) {DIR *dir;
@@ -31,6 +33,8 @@ static unsigned int count_avail_pid(void)SAFE_CLOSEDIR (dir); max_pid_num = limit.rlim_cur - count; +if (max_pid_num >MAX_SLAVE_OPENS ) + max_pid_num =MAX_SLAVE_OPENS ;tst_res (TINFO ,"Available number of pids: %u" , max_pid_num);
Signature · 5 lines
2.47.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Runli,
testcases/kernel/pty/pty09.c static unsigned int count_avail_pid(void) · line 39
Quoted 7 lines · Runli
pty09: Cap RLIMIT_NOFILE-based slave PTY opens
testcases/kernel/pty/pty09.c +2
-0max_pid_num = limit.rlim_cur - count; +if (max_pid_num >MAX_SLAVE_OPENS ) + max_pid_num =MAX_SLAVE_OPENS ;tst_res (TINFO ,"Available number of pids: %u" , max_pid_num);
After the cap fires, max_pid_num holds 4096 -- the test's self-imposed limit -- but the TINFO label still says "Available number", which implies the system's available FD count.
On a system where RLIMIT_NOFILE - open_fds is, say, 1048000, the output would read "Available number of pids: 4096", which could mislead anyone comparing it against the system limit.
Consider printing the uncapped available count and a separate note when the cap applies, e.g.:
tst_res(TINFO, "Available number of pids: %u (capped at %d)",
max_pid_num, MAX_SLAVE_OPENS);
or split the TINFO into two calls -- one for the real available count (computed before the cap), one confirming the cap was applied.
Verdict - Needs revision
Pre-existing issues:
1. count_avail_pid() and the variable max_pid_num both say "pid" but the code tracks file-descriptor slots, not PIDs.
2. In run(): tst_res(TPASS, "pty has been opened %d times", max_pid_num) uses %d for an unsigned int argument.
3. In run(): int slavefd[max_pid_num] is a VLA. If max_pid_num == 0 (all FD slots occupied) the zero-length VLA is undefined behaviour.
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 2 lines
tst_res(TINFO, "Available number of pids: %u (capped at %d)",
max_pid_num, MAX_SLAVE_OPENS);
Agree here, the message was confusing and this one looks better.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp