[PATCH v3] pipe13: Scale child reap window with LTP_TIMEOUT_MUL

Stephen Bertram via ltp <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <[email protected]>
The post-close wait used a fixed 1000000 us cap on exponential backoff.
Scale that cap with tst_multiply_timeout() so debug
kernels and LTP_TIMEOUT_MUL apply, fixing failures under parallel
Kirk workers without changing default behavior on non-debug systems.

Before (only with case 100):

pipe13.c:50: TINFO: Creating 100 child processes
pipe13.c:81: TINFO: pid 435007 still sleeps
...
pipe13.c:81: TINFO: pid 435300 still sleeps
pipe13.c:89: TFAIL: Closed pipe didn't wake up everyone
The list varied but sometimes up to 20 would remained asleep.

Test is passing after using TST_RETRY_FN_EXP_BACKOFF() so timeout
scaling follows the standard LTP path (tst_multiply_timeout, debug
kconfig, LTP_TIMEOUT_MUL).

The failure before would happen, when using 4 parallel workers
on a debug kernel, about 1 to 2 times when iterated 5 times.
Tested on aarch64 debug+PREEMPT_RT: kirk -w 4 pipe13 -i 100, 400 runs,
0 fail.

Signed-off-by: Stephen Bertram <[email protected]>
---
 testcases/kernel/syscalls/pipe/pipe13.c | 44 +++++++++++++++----------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/testcases/kernel/syscalls/pipe/pipe13.c b/testcases/kernel/syscalls/pipe/pipe13.c
index 5d76e1f00..7f7685a2c 100644
--- a/testcases/kernel/syscalls/pipe/pipe13.c
+++ b/testcases/kernel/syscalls/pipe/pipe13.c
@@ -26,6 +26,28 @@ static unsigned int tcases[] = {
 };
 
 static int fds[2];
+static unsigned int reap_child_num;
+static unsigned int reap_count;
+static int *reap_pids;
+
+static int reap_children_once(void)
+{
+	unsigned int i;
+	int ret;
+
+	while ((ret = waitpid(-1, NULL, WNOHANG)) > 0) {
+		reap_count++;
+		for (i = 0; i < reap_child_num; i++) {
+			if (reap_pids[i] == ret)
+				reap_pids[i] = 0;
+		}
+	}
+	if (ret < 0 && errno != ECHILD)
+		tst_brk(TBROK | TERRNO, "waitpid()");
+	return reap_count;
+}
+
+#define ALL_CHILDREN_REAPED(cnt) ((unsigned int)(cnt) >= reap_child_num)
 
 static void do_child(unsigned int i)
 {
@@ -41,8 +63,7 @@ static void do_child(unsigned int i)
 
 static void verify_pipe(unsigned int n)
 {
-	int ret;
-	unsigned int i, cnt = 0, sleep_us = 1, fail = 0;
+	unsigned int i, fail = 0;
 	unsigned int child_num = tcases[n];
 	int pid[child_num];
 
@@ -60,21 +81,10 @@ static void verify_pipe(unsigned int n)
 	SAFE_CLOSE(fds[0]);
 	SAFE_CLOSE(fds[1]);
 
-	while (cnt < child_num && sleep_us < 1000000) {
-		ret = waitpid(-1, NULL, WNOHANG);
-		if (ret < 0)
-			tst_brk(TBROK | TERRNO, "waitpid()");
-		if (ret > 0) {
-			cnt++;
-			for (i = 0; i < child_num; i++) {
-				if (pid[i] == ret)
-					pid[i] = 0;
-			}
-			continue;
-		}
-		usleep(sleep_us);
-		sleep_us *= 2;
-	}
+	reap_child_num = child_num;
+	reap_count = 0;
+	reap_pids = pid;
+	TST_RETRY_FN_EXP_BACKOFF(reap_children_once(), ALL_CHILDREN_REAPED, 1);
 
 	for (i = 0; i < child_num; i++) {
 		if (pid[i]) {
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.