diff mbox series

[v2] ksefltest: pidfd: Fix wait_states: Test terminated by timeout

Message ID 20211217093040.9530-1-lizhijian@cn.fujitsu.com
State New
Headers show
Series [v2] ksefltest: pidfd: Fix wait_states: Test terminated by timeout | expand

Commit Message

Li Zhijian Dec. 17, 2021, 9:30 a.m. UTC
0Day/LKP observed that the kselftest blocks foever since one of the
pidfd_wait doesn't terminate in 1 of 30 runs. After digging into
the source, we found that it blocks at:
ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WCONTINUED, NULL), 0);

we can reproduce it by:
$ while true; do make run_tests -C pidfd; done

Introduce a blocking read in child process to make sure the parent can
check its WCONTINUED.

CC: Philip Li <philip.li@intel.com>
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
---
V2: rewrite with pipe to avoid usleep
---
 tools/testing/selftests/pidfd/pidfd_wait.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Li Zhijian Jan. 13, 2022, 5:51 a.m. UTC | #1
ping


On 17/12/2021 17:30, Li Zhijian wrote:
> 0Day/LKP observed that the kselftest blocks foever since one of the
> pidfd_wait doesn't terminate in 1 of 30 runs. After digging into
> the source, we found that it blocks at:
> ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WCONTINUED, NULL), 0);
>
> we can reproduce it by:
> $ while true; do make run_tests -C pidfd; done
>
> Introduce a blocking read in child process to make sure the parent can
> check its WCONTINUED.
>
> CC: Philip Li <philip.li@intel.com>
> Reported-by: kernel test robot <lkp@intel.com>
> Signed-off-by: Li Zhijian <lizhijian@cn.fujitsu.com>
> ---
> V2: rewrite with pipe to avoid usleep
> ---
>   tools/testing/selftests/pidfd/pidfd_wait.c | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
> index be2943f072f6..d5c0ffa26c32 100644
> --- a/tools/testing/selftests/pidfd/pidfd_wait.c
> +++ b/tools/testing/selftests/pidfd/pidfd_wait.c
> @@ -96,21 +96,26 @@ TEST(wait_states)
>   		.flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
>   		.exit_signal = SIGCHLD,
>   	};
> -	int ret;
> +	int ret, pfd[2];
>   	pid_t pid;
>   	siginfo_t info = {
>   		.si_signo = 0,
>   	};
> -
> +	ASSERT_EQ(pipe(pfd), 0);
>   	pid = sys_clone3(&args);
>   	ASSERT_GE(pid, 0);
>   
>   	if (pid == 0) {
> +		char buf[2];
> +		close(pfd[1]);
>   		kill(getpid(), SIGSTOP);
> +		ASSERT_EQ(read(pfd[0], buf, 1), 1);
> +		close(pfd[0]);
>   		kill(getpid(), SIGSTOP);
>   		exit(EXIT_SUCCESS);
>   	}
>   
> +	close(pfd[0]);
>   	ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WSTOPPED, NULL), 0);
>   	ASSERT_EQ(info.si_signo, SIGCHLD);
>   	ASSERT_EQ(info.si_code, CLD_STOPPED);
> @@ -119,6 +124,8 @@ TEST(wait_states)
>   	ASSERT_EQ(sys_pidfd_send_signal(pidfd, SIGCONT, NULL, 0), 0);
>   
>   	ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WCONTINUED, NULL), 0);
> +	ASSERT_EQ(write(pfd[1], "C", 1), 1);
> +	close(pfd[1]);
>   	ASSERT_EQ(info.si_signo, SIGCHLD);
>   	ASSERT_EQ(info.si_code, CLD_CONTINUED);
>   	ASSERT_EQ(info.si_pid, parent_tid);
diff mbox series

Patch

diff --git a/tools/testing/selftests/pidfd/pidfd_wait.c b/tools/testing/selftests/pidfd/pidfd_wait.c
index be2943f072f6..d5c0ffa26c32 100644
--- a/tools/testing/selftests/pidfd/pidfd_wait.c
+++ b/tools/testing/selftests/pidfd/pidfd_wait.c
@@ -96,21 +96,26 @@  TEST(wait_states)
 		.flags = CLONE_PIDFD | CLONE_PARENT_SETTID,
 		.exit_signal = SIGCHLD,
 	};
-	int ret;
+	int ret, pfd[2];
 	pid_t pid;
 	siginfo_t info = {
 		.si_signo = 0,
 	};
-
+	ASSERT_EQ(pipe(pfd), 0);
 	pid = sys_clone3(&args);
 	ASSERT_GE(pid, 0);
 
 	if (pid == 0) {
+		char buf[2];
+		close(pfd[1]);
 		kill(getpid(), SIGSTOP);
+		ASSERT_EQ(read(pfd[0], buf, 1), 1);
+		close(pfd[0]);
 		kill(getpid(), SIGSTOP);
 		exit(EXIT_SUCCESS);
 	}
 
+	close(pfd[0]);
 	ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WSTOPPED, NULL), 0);
 	ASSERT_EQ(info.si_signo, SIGCHLD);
 	ASSERT_EQ(info.si_code, CLD_STOPPED);
@@ -119,6 +124,8 @@  TEST(wait_states)
 	ASSERT_EQ(sys_pidfd_send_signal(pidfd, SIGCONT, NULL, 0), 0);
 
 	ASSERT_EQ(sys_waitid(P_PIDFD, pidfd, &info, WCONTINUED, NULL), 0);
+	ASSERT_EQ(write(pfd[1], "C", 1), 1);
+	close(pfd[1]);
 	ASSERT_EQ(info.si_signo, SIGCHLD);
 	ASSERT_EQ(info.si_code, CLD_CONTINUED);
 	ASSERT_EQ(info.si_pid, parent_tid);