Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH -next] selftests/ptrace: Fix Test terminated by timeout in ptrace_attach
@ 2022-11-28  7:04 limin
  2022-11-28  7:56 ` Bernd Edlinger
  0 siblings, 1 reply; 4+ messages in thread
From: limin @ 2022-11-28  7:04 UTC (permalink / raw)
  To: shuah, keescook, bernd.edlinger, ebiederm, linux-kselftest,
	linux-kernel
  Cc: songmuchun, lizefan.x

That is an open issue
Bernd Edlinger wrote the test case in anticipation that all of
patch series got accepted,but the last patch was not picked up
for inclusion in the linux kernel.
How to reproduce warning:
$ make -C tools/testing/selftests TARGETS=ptrace run_tests
Example vmaccess from 6.1.0-next source tree run fail on bare metal
  RUN global.attach ...
  attach: Test terminated by timeout
  FAIL  global.attach

Link:https://lore.kernel.org/all/AM8PR10MB4708E6FF0E155261455064C2E4209@AM8PR10MB4708.EURPRD10.PROD.OUTLOOK.COM/
Fixes: 2de4e82318c7 ("selftests/ptrace: add test cases for dead-locks")
Signed-off-by: limin <limin100@huawei.com>
---
 tools/testing/selftests/ptrace/vmaccess.c | 37 ++++++++---------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/tools/testing/selftests/ptrace/vmaccess.c b/tools/testing/selftests/ptrace/vmaccess.c
index 4db327b44586..751a41f1163c 100644
--- a/tools/testing/selftests/ptrace/vmaccess.c
+++ b/tools/testing/selftests/ptrace/vmaccess.c
@@ -45,42 +45,31 @@ TEST(vmaccess)
 
 TEST(attach)
 {
-	int s, k, pid = fork();
+	int k;
+	int s;
 
+	pid_t pid = fork();
 	if (!pid) {
-		pthread_t pt;
-
-		pthread_create(&pt, NULL, thread, NULL);
-		pthread_join(pt, NULL);
+		ptrace(PTRACE_TRACEME, 0, NULL, NULL);
 		execlp("sleep", "sleep", "2", NULL);
 	}
 
 	sleep(1);
 	k = ptrace(PTRACE_ATTACH, pid, 0L, 0L);
-	ASSERT_EQ(errno, EAGAIN);
+	printf("k1:%d\n", k);
+	ASSERT_EQ(k, -1);
+	waitpid(pid, &s, WNOHANG);
 	ASSERT_EQ(k, -1);
-	k = waitpid(-1, &s, WNOHANG);
-	ASSERT_NE(k, -1);
 	ASSERT_NE(k, 0);
 	ASSERT_NE(k, pid);
-	ASSERT_EQ(WIFEXITED(s), 1);
-	ASSERT_EQ(WEXITSTATUS(s), 0);
-	sleep(1);
-	k = ptrace(PTRACE_ATTACH, pid, 0L, 0L);
-	ASSERT_EQ(k, 0);
-	k = waitpid(-1, &s, 0);
-	ASSERT_EQ(k, pid);
+	if (WIFEXITED(s))
+		ASSERT_EQ(WEXITSTATUS(s), 0);
+	if (WIFSTOPPED(s))
+		ASSERT_EQ(WSTOPSIG(s), SIGTRAP);
 	ASSERT_EQ(WIFSTOPPED(s), 1);
-	ASSERT_EQ(WSTOPSIG(s), SIGSTOP);
-	k = ptrace(PTRACE_DETACH, pid, 0L, 0L);
-	ASSERT_EQ(k, 0);
-	k = waitpid(-1, &s, 0);
-	ASSERT_EQ(k, pid);
-	ASSERT_EQ(WIFEXITED(s), 1);
-	ASSERT_EQ(WEXITSTATUS(s), 0);
-	k = waitpid(-1, NULL, 0);
+	sleep(1);
+	ptrace(PTRACE_CONT, pid, NULL, NULL);
 	ASSERT_EQ(k, -1);
-	ASSERT_EQ(errno, ECHILD);
 }
 
 TEST_HARNESS_MAIN
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-07-01  3:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-28  7:04 [PATCH -next] selftests/ptrace: Fix Test terminated by timeout in ptrace_attach limin
2022-11-28  7:56 ` Bernd Edlinger
2022-12-02  0:48   ` Kees Cook
2023-07-01 14:58     ` Zheng Yejian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox