Skip to contentSkip to conversation

pty09: Cap RLIMIT_NOFILE-based slave PTY opens

PATCH In review Runli via ltp 3 participants 4 messages Jul 14 – Jul 20

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

Fixes 20aa13dbd8a68 ("Add pty09 test")

---
Changes in v2:
- Print the uncapped available count before applying the cap.
- Add a separate TINFO message when the open count is capped.

 testcases/kernel/pty/pty09.c | 8 ++++++++
 1 file changed, 8 insertions(+)
testcases/kernel/pty/pty09.c +8 -0
index f3ade2381..80da475e9 100644
@@ -14,6 +14,8 @@
 
 static int masterfd = -1;
 
+#define MAX_SLAVE_OPENS 4096
+
 static unsigned int count_avail_pid(void)
 {
 	DIR *dir;
@@ -34,6 +36,12 @@ static unsigned int count_avail_pid(void)
 
 	tst_res(TINFO, "Available number of pids: %u", max_pid_num);
 
+	if (max_pid_num > MAX_SLAVE_OPENS) {
+		max_pid_num = MAX_SLAVE_OPENS;
+		tst_res(TINFO, "Number of pids is too large, capped at: %u",
+			max_pid_num);
+	}
+
 	return max_pid_num;
 }
 
Signature · 4 lines
2.47.0

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Runli,

testcases/kernel/pty/pty09.c static unsigned int count_avail_pid(void) · line 43

Quoted 7 lines · Runli

pty09: Cap RLIMIT_NOFILE-based slave PTY opens

testcases/kernel/pty/pty09.c +5 -0
+	if (max_pid_num > MAX_SLAVE_OPENS) {
+		max_pid_num = MAX_SLAVE_OPENS;
+		tst_res(TINFO, "Number of pids is too large, capped at: %u",
+			max_pid_num);
+	}

The value being capped is derived from RLIMIT_NOFILE (open file descriptor slots), not process IDs. "Number of pids is too large" describes the wrong resource.

The commit message itself uses the accurate term ("slave opens"). Suggest aligning the TINFO message with that:

tst_res(TINFO, "Number of slave opens is too large, capped at: %u",
max_pid_num);

Pre-existing issue: the containing function count_avail_pid() and its local variable max_pid_num carry the same "pid" misnomer for what is really an open-fd-slot count. Not introduced by this patch, but worth noting.

Verdict - Needs revision

---
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
#2 lore raw
In reply to Runli via ltp

Hi,

Gentle ping for this patch.

Thanks,
Runli

Quoted 50 lines · Runli

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.

Fixes 20aa13dbd8a68 ("Add pty09 test")

---
Changes in v2:
- Print the uncapped available count before applying the cap.
- Add a separate TINFO message when the open count is capped.

 testcases/kernel/pty/pty09.c | 8 ++++++++
 1 file changed, 8 insertions(+)
testcases/kernel/pty/pty09.c +8 -1
index f3ade2381..80da475e9 100644
@@ -14,6 +14,8 @@
 
 static int masterfd = -1;
 
+#define MAX_SLAVE_OPENS 4096
+
 static unsigned int count_avail_pid(void)
 {
        DIR *dir;
@@ -34,6 +36,12 @@ static unsigned int count_avail_pid(void)
 
        tst_res(TINFO, "Available number of pids: %u", max_pid_num);
 
+       if (max_pid_num > MAX_SLAVE_OPENS) {
+               max_pid_num = MAX_SLAVE_OPENS;
+               tst_res(TINFO, "Number of pids is too large, capped at: %u",
+                       max_pid_num);
+       }
+
        return max_pid_num;
 }
 
--

2.47.0

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp