syscalls/ptrace: Merge ptrace01 and ptrace02
PATCH 1/1 syscalls/ptrace: Merge ptrace01 and ptrace02
Combine ptrace01 and ptrace02 into one.
Signed-off-by Jorik Cronenberg <[email protected]>
--- testcases/kernel/syscalls/ptrace/ptrace01.c | 54 ++-- testcases/kernel/syscalls/ptrace/ptrace02.c | 288 -------------------- 2 files changed, 38 insertions(+), 304 deletions(-) delete mode 100644 testcases/kernel/syscalls/ptrace/ptrace02.c
testcases/kernel/syscalls/ptrace/ptrace01.c +38 -16
@@ -1,20 +1,22 @@// SPDX-License-Identifier: GPL-2.0 /* * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved. -* Copyright (c) 2019 Jorik Cronenberg <[email protected]> +* Copyright (c) 2019 SUSE LLC * * Author: Saji Kumar.V.R <[email protected]> * Ported to new library: Jorik Cronenberg <[email protected]> * -* Test the functionality of ptrace() for PTRACE_TRACEME & PTRACE_KILL requests. +* Test the functionality of ptrace() for PTRACE_TRACEME in combination with +* PTRACE_KILL and PTRACE_CONT requests. * Forked child does ptrace(PTRACE_TRACEME, ...). * Then a signal is delivered to the child and verified that parent * is notified via wait(). -* After parent does ptrace(PTRACE_KILL, ..) to kill the child -* and parent wait() for child to finish. -* Test passes if child finished abnormally. +* Afterwards parent does ptrace(PTRACE_KILL, ..)/ptrace(PTRACE_CONT, ..) +* and then parent does wait() for child to finish. +* Test passes if child exits with SIGKILL for PTRACE_KILL. +* Test passes if child exits normally for PTRACE_CONT. * -* Testing two cases: +* Testing two cases for each: * 1) child ignore SIGUSR2 signal * 2) using a signal handler for child for SIGUSR2 * In both cases, child should stop & notify parent on reception of SIGUSR2.
@@ -28,6 +30,19 @@#include "ptrace.h" #include "tst_test.h" +static struct tcase { +int handler; +int request; +int exp_wifexited; +int exp_wtermsig; +char *message; +} tcases[] = { + {0 ,PTRACE_KILL ,0 ,9 ,"Testing PTRACE_KILL without child handler" }, + {1 ,PTRACE_KILL ,0 ,9 ,"Testing PTRACE_KILL with child handler" }, + {0 ,PTRACE_CONT ,1 ,0 ,"Testing PTRACE_CONT without child handler" }, + {1 ,PTRACE_CONT ,1 ,0 ,"Testing PTRACE_CONT with child handler" }, +}; +static volatile int got_signal; static void child_handler(int sig LTP_ATTRIBUTE_UNUSED)
@@ -64,13 +79,16 @@ static void do_child(unsigned int i)static void run (unsigned int i) { +struct tcase *tc = &tcases[i];pid_t child_pid;int status;struct sigaction parent_act; got_signal =0 ; -if (i ==1 ) { +tst_res (TINFO , tc->message); + +if (tc->handler ==1 ) { parent_act.sa_handler = parent_handler; parent_act.sa_flags =SA_RESTART ;sigemptyset (&parent_act.sa_mask);
@@ -80,28 +98,32 @@ static void run(unsigned int i) child_pid =SAFE_FORK ();if (!child_pid) -do_child (i); +do_child (tc->handler);SAFE_WAITPID (child_pid, &status,0 );if (((WIFEXITED (status)) && (WEXITSTATUS (status))) || (got_signal ==1 ))tst_res (TFAIL ,"Test Failed" ); -else if ((ptrace (PTRACE_KILL , child_pid,0 ,0 )) ==-1 ) -tst_res (TFAIL |TERRNO ,"ptrace(PTRACE_KILL, %i, 0, 0) failed" , - child_pid); +else if ((ptrace (tc->request, child_pid,0 ,0 )) ==-1 ) +tst_res (TFAIL |TERRNO ,"ptrace(%i, %i, 0, 0) failed" , + tc->request, child_pid);SAFE_WAITPID (child_pid, &status,0 ); -if (WTERMSIG (status) ==9 ) -tst_res (TPASS ,"Child %s as expected" ,tst_strstatus (status)); -else -tst_res (TFAIL ,"Child %s unexpectedly" ,tst_strstatus (status)); +if (WIFEXITED (status) == tc->exp_wifexited + &&WTERMSIG (status) == tc->exp_wtermsig) { +tst_res (TPASS ,"Child %s as expected" , +tst_strstatus (status)); + }else { +tst_res (TFAIL ,"Child %s unexpectedly" , +tst_strstatus (status)); + } }static struct tst_test test = { .test = run, - .tcnt =2 , + .tcnt =ARRAY_SIZE (tcases), .forks_child =1 , };
testcases/kernel/syscalls/ptrace/ptrace02.c deleted +0 -288
288 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH 1/1 syscalls/ptrace: Merge ptrace01 and ptrace02
Hi!
Pushed with minor adjustements, thanks.
* Removed the runtest entry for ptrace02
* Removed the .gitignore entry for ptrace02
* Fixed the status handling at the end of the test
We should adjust our expectations based on which ptrace() call we did, e.g. for PTRACE_CONT the child killed by sigkill is still a failure. Also you have to call WIF*() first and only then you can get the exit/term signal value.
Signature · 2 lines
Cyril Hrubis [email protected]