syscalls/pause: Refactor tests
v2 cover syscalls/pause: Refactor tests
---
Changes in v2:
- Added a cleanup commit for pause01
- Made use of LTP_ATTRIBUTE_UNUSED, TST_EXP_FAIL, TST_EXP_EXPR, SAFE_KILL
as suggested by Andrea.
- Fixed test descriptions
- Added 2025 copyright
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Ricardo B. Marlière (3):
syscalls/pause01: Clean up
syscalls/pause02: Refactor into new API
syscalls/pause03: Refactor into new API
testcases/kernel/syscalls/pause/pause01.c | 34 +++---- testcases/kernel/syscalls/pause/pause02.c | 150 ++++++------------------------ testcases/kernel/syscalls/pause/pause03.c | 115 +++++------------------ 3 files changed, 66 insertions(+), 233 deletions(-)
---
base-commit: 459b3cdf157f9d6be51f3a610dff3855f5e9ff36
change-id: 20250217-conversions-pause-4b9d4be3f876
Best regards,
Signature · 5 lines
Ricardo B. Marlière <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/3 syscalls/pause01: Clean up
From: Ricardo B. Marlière <[email protected]>
Tidy up and add a description.
--- testcases/kernel/syscalls/pause/pause01.c | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-)
testcases/kernel/syscalls/pause/pause01.c +14 -20
@@ -1,10 +1,14 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2016 Linux Test Project +* Copyright (c) 2025 Ricardo B. Marlière <[email protected]> */ -#include <errno.h> -#include <signal.h> -#include <stdlib.h> + +/*\ +* Verify that, pause() returns -1 and sets errno to EINTR after receipt of a +* signal which is caught by the calling process. +*/ +#include "tst_test.h" static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)
@@ -14,32 +18,22 @@ static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)static void do_child (void ) {SAFE_SIGNAL (SIGINT , sig_handler); - +TST_EXP_FAIL (pause (),EINTR );TST_CHECKPOINT_WAKE (0 ); - -TEST (pause ()); -if (TST_RET !=-1 ) -tst_res (TFAIL ,"pause() succeeded unexpectedly" ); -else if (TST_ERR ==EINTR ) -tst_res (TPASS ,"pause() interrupted with EINTR" ); -else -tst_res (TFAIL |TTERRNO ,"pause() unexpected errno" ); - -TST_CHECKPOINT_WAKE (0 ); -exit (0 ); } -static void do_test (void ) +static void run (void ) {int pid, status; pid =SAFE_FORK (); -if (pid ==0 ) +if (!pid) {do_child (); +exit (0 ); + } -TST_CHECKPOINT_WAIT (0 );TST_PROCESS_STATE_WAIT (pid,'S' ,0 ); -kill (pid,SIGINT ); +SAFE_KILL (pid,SIGINT );/* * TST_CHECKPOINT_WAIT has built-in timeout, if pause() doesn't return,
@@ -52,5 +46,5 @@ static void do_test(void)static struct tst_test test = { .forks_child =1 , .needs_checkpoints =1 , - .test_all = do_test, + .test_all = run, };
Signature · 5 lines
2.48.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up
Hi!
Quoted 35 lines
Signed-off-by Ricardo B. Marlière <[email protected]>--- testcases/kernel/syscalls/pause/pause01.c | 34 +++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-)testcases/kernel/syscalls/pause/pause01.c +8
-5@@ -1,10 +1,14 @@// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2016 Linux Test Project +* Copyright (c) 2025 Ricardo B. Marlière <[email protected]> */ -#include <errno.h> -#include <signal.h> -#include <stdlib.h> + +/*\ +* Verify that, pause() returns -1 and sets errno to EINTR after receipt of a +* signal which is caught by the calling process. +*/ +#include "tst_test.h" static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)@@ -14,32 +18,22 @@ static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)static void do_child (void ) {SAFE_SIGNAL (SIGINT , sig_handler); - +TST_EXP_FAIL (pause (),EINTR );TST_CHECKPOINT_WAKE (0 ); -
testcases/kernel/syscalls/pause/pause01.c static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED) · line 29
Quoted 10 lines
testcases/kernel/syscalls/pause/pause01.c +0
-10-TEST (pause ()); -if (TST_RET !=-1 ) -tst_res (TFAIL ,"pause() succeeded unexpectedly" ); -else if (TST_ERR ==EINTR ) -tst_res (TPASS ,"pause() interrupted with EINTR" ); -else -tst_res (TFAIL |TTERRNO ,"pause() unexpected errno" ); - -TST_CHECKPOINT_WAKE (0 ); -exit (0 );
This reorders how things are called which is wrong. The checkpoint wake call before the pause() is there for a reason. The process may sleep in kernel for any other reason not related to the test, so we need to ensure that we are just about to call the pause() syscall before we wait for the process state to change in the run() function.
If anything should be removed it's the second pair of checkpoints after the pause() because the new test library has build-in timeout and there is no reason to depend on checkpoint timeouts at the end of the test.
And there is no reason to wait() the child in the new test library either. So (on the top of your patch) we can do:
testcases/kernel/syscalls/pause/pause01.c +2 -8
@@ -18,8 +18,8 @@ static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED)static void do_child (void ) {SAFE_SIGNAL (SIGINT , sig_handler); -TST_EXP_FAIL (pause (),EINTR );TST_CHECKPOINT_WAKE (0 ); +TST_EXP_FAIL (pause (),EINTR ); }static void run (void )
@@ -32,15 +32,9 @@ static void run(void)exit (0 ); } +TST_CHECKPOINT_WAIT (0 );TST_PROCESS_STATE_WAIT (pid,'S' ,0 );SAFE_KILL (pid,SIGINT ); - -/* -* TST_CHECKPOINT_WAIT has built-in timeout, if pause() doesn't return, -* this checkpoint call will reliably end the test. -*/ -TST_CHECKPOINT_WAIT (0 ); -SAFE_WAIT (&status); }static struct tst_test test = {
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/3 syscalls/pause02: Refactor into new API
In reply to Ricardo B. MarlièreFrom: Ricardo B. Marlière <[email protected]>
--- testcases/kernel/syscalls/pause/pause02.c | 150 ++++++------------------------ 1 file changed, 27 insertions(+), 123 deletions(-)
testcases/kernel/syscalls/pause/pause02.c +27 -123
@@ -1,147 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 * Copyright (c) 2012 Cyril Hrubis <[email protected]> -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* Copyright (c) 2025 Ricardo B. Marlière <[email protected]> */ -/* +/*\ * Verify that, pause() returns -1 and sets errno to EINTR after receipt of a * signal which is caught by the calling process. Also, verify that the calling * process will resume execution from the point of suspension. */ -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/wait.h> - -#include "test.h" - -char *TCID ="pause02" ; -int TST_TOTAL =1 ; -static pid_t cpid; +#include "tst_test.h" -static void do_child (void ); -static void setup (void ); -static void cleanup (void ); - -int main (int ac,char **av) -{ -int lc; -int status; - -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - - cpid =tst_fork (); -switch (cpid) { -case -1 : -tst_brkm (TBROK , cleanup,"fork() failed" ); -break ; -case 0 : -do_child (); -break ; -default : -break ; - } - -/* -* Wait for child to enter pause(). -*/ -TST_PROCESS_STATE_WAIT (cleanup, cpid,'S' ); - -/* -* Send the SIGINT signal now, so that child -* returns from pause and resumes execution. -*/ -kill (cpid,SIGINT ); - -wait (&status); - -if (WIFEXITED (status)) { -if (WEXITSTATUS (status) ==0 ) -tst_resm (TPASS ,"pause was interrupted correctly" ); -else -tst_resm (TFAIL ,"pause was interrupted but the " -"retval and/or errno was wrong" ); -continue ; - } - -if (WIFSIGNALED (status)) { -switch (WTERMSIG (status)) { -case SIGALRM : -tst_resm (TFAIL ,"Timeout: SIGINT wasn't received by child" ); -break ; -default : -tst_resm (TFAIL ,"Child killed by signal" ); - } - -continue ; - } - -tst_resm (TFAIL ,"Pause was not interrupted" ); - } - -cleanup (); -tst_exit (); -} - -static void sig_handle (int sig) +static void sig_handler(int sig LTP_ATTRIBUTE_UNUSED) { }static void do_child (void ) { -/* avoid LTP framework to do whatever it likes */ -signal (SIGALRM ,SIG_DFL ); - -if (signal (SIGINT , sig_handle) ==SIG_ERR ) { -fprintf (stderr,"Child: Failed to setup signal handler\n" ); -exit (1 ); - } - -/* Commit suicide after 10 seconds */ +SAFE_SIGNAL (SIGALRM ,SIG_DFL ); +SAFE_SIGNAL (SIGINT , sig_handler);alarm (10 ); +TST_EXP_FAIL (pause (),EINTR ); +} -TEST (pause ()); - -if (TEST_RETURN ==-1 ) { -if (TEST_ERRNO ==EINTR ) -exit (0 ); +void run (void ) +{ +int status; +pid_t pid; -fprintf (stderr,"Child: Pause returned -1 but errno is %d (%s)\n" , -TEST_ERRNO ,strerror (TEST_ERRNO )); -exit (1 ); + pid =SAFE_FORK (); +if (!pid) { +do_child (); +exit (0 ); } -fprintf (stderr,"Child: Pause returned %ld\n" ,TEST_RETURN ); -exit (1 ); -} - -static void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); +TST_PROCESS_STATE_WAIT (pid,'S' ,10000 ); +SAFE_KILL (pid,SIGINT ); +SAFE_WAITPID (pid, &status,0 ); -TEST_PAUSE ; +TST_EXP_EXPR (WIFEXITED (status) && !WEXITSTATUS (status), +"pause() was interrupted correctly" ); +tst_res (TFAIL ,"pause() was not interrupted" ); } -static void cleanup (void ) -{ -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 , +};
Signature · 5 lines
2.48.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
Hi!
This is the same as pause01.c there is no point in having two tests that do the same.
So rather than rewriting this test we should add a check to the pause01.c that the process resumed after the signal. Which should be as easy as:
testcases/kernel/syscalls/pause/pause01.c +2 -0
@@ -20,6 +20,8 @@ static void do_child(void)SAFE_SIGNAL (SIGINT , sig_handler);TST_EXP_FAIL (pause (),EINTR );TST_CHECKPOINT_WAKE (0 ); + +tst_res (TPASS ,"Process resumed from pause()" ); }
And it would also make sense to add more coverage to pause01 in a subsequent patch. Currently it tests only a single signal, we should iterate over all signals instead (minus the SIGKILL that is covered by pause03).
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
Hello Cyril,
Quoted 21 lines · Cyril Hrubis
Hi!
This is the same aspause01.cthere is no point in having two tests that do the same.So rather than rewriting this test we should add a check to the
pause01.cthat the process resumed after the signal. Which should be as easy as:testcases/kernel/syscalls/pause/pause01.c +2
-0@@ -20,6 +20,8 @@ static void do_child(void)SAFE_SIGNAL (SIGINT , sig_handler);TST_EXP_FAIL (pause (),EINTR );TST_CHECKPOINT_WAKE (0 ); + +tst_res (TPASS ,"Process resumed from pause()" ); }
Quoted 4 lines
And it would also make sense to add more coverage to pause01 in a subsequent patch. Currently it tests only a single signal, we should iterate over all signals instead (minus the SIGKILL that is covered by pause03).
Thanks for the review and explanations! I'll address your points in the next revision.
- Ricardo.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 3/3 syscalls/pause03: Refactor into new API
In reply to Ricardo B. MarlièreFrom: Ricardo B. Marlière <[email protected]>
--- testcases/kernel/syscalls/pause/pause03.c | 115 +++++++----------------------- 1 file changed, 25 insertions(+), 90 deletions(-)
testcases/kernel/syscalls/pause/pause03.c +25 -90
@@ -1,104 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 -* 07/2001 Ported by Wayne Boyer -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2025 Ricardo B. Marlière <[email protected]> */ -/* -* Test Description: -* pause() does not return due to receipt of SIGKILL signal and specified -* process should be terminated. -*/ -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/wait.h> - -#include "test.h" -#include "safe_macros.h" - -static pid_t cpid; -char *TCID ="pause03" ; -int TST_TOTAL =1 ; +/*\ +* This test verifies that pause() does not return after receiving a SIGKILL +* signal, at which point the process should be terminated. +*/ -static void do_child (void ); -static void setup (void ); -static void cleanup (void ); +#include "tst_test.h" -int main (int ac,char **av) +void run (void ) { -int lc;int status; +pid_t pid; -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -if ((cpid =tst_fork ()) ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL ,"fork() failed" ); - -if (cpid ==0 ) -do_child (); - -TST_PROCESS_STATE_WAIT (cleanup, cpid,'S' ); - -kill (cpid,SIGKILL ); - -SAFE_WAIT (NULL , &status); - -if (WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL ) { -tst_resm (TPASS ,"pause() did not return after SIGKILL" ); -continue ; - } - -if (WIFSIGNALED (status)) { -tst_resm (TFAIL ,"child killed by %s unexpectedly" , -tst_strsig (WTERMSIG (status))); -continue ; - } - -tst_resm (TFAIL ,"child exited with %i" ,WEXITSTATUS (status)); + pid =SAFE_FORK (); +if (!pid) { +TST_EXP_PASS (pause ()); +exit (0 ); } -cleanup (); -tst_exit (); +TST_PROCESS_STATE_WAIT (pid,'S' ,10000 ); +SAFE_KILL (pid,SIGINT ); +SAFE_WAITPID (pid, &status,0 ); +if (WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL ) +tst_res (TPASS ,"pause() did not return after SIGKILL" ); +else +tst_res (TFAIL ,"Child exited with %i" ,WEXITSTATUS (status)); } -void do_child (void ) -{ -TEST (pause ()); - -tst_resm (TFAIL ,"Unexpected return from pause()" ); - -exit (0 ); -} - -void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - - -void cleanup (void ) -{ -kill (cpid,SIGKILL ); -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 , +};
Signature · 5 lines
2.48.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 3/3] syscalls/pause03: Refactor into new API
Hi!
Quoted 40 lines
--- testcases/kernel/syscalls/pause/pause03.c | 115 +++++++----------------------- 1 file changed, 25 insertions(+), 90 deletions(-)testcases/kernel/syscalls/pause/pause03.c +3
-25@@ -1,104 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 -* 07/2001 Ported by Wayne Boyer -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See -* the GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software Foundation, -* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +* 07/2001 Ported by Wayne Boyer +* Copyright (c) 2025 Ricardo B. Marlière <[email protected]> */ -/* -* Test Description: -* pause() does not return due to receipt of SIGKILL signal and specified -* process should be terminated. -*/ -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#include <sys/wait.h> -
testcases/kernel/syscalls/pause/pause03.c line 10
Quoted 10 lines
testcases/kernel/syscalls/pause/pause03.c +3
-6-#include "test.h" -#include "safe_macros.h" - -static pid_t cpid; -char *TCID ="pause03" ; -int TST_TOTAL =1 ; +/*\ +* This test verifies that pause() does not return after receiving a SIGKILL +* signal, at which point the process should be terminated.
Maybe this can be shorter, something as:
Verifies that pause() does not return after process recieved SIGKILL.
Quoted 44 lines
testcases/kernel/syscalls/pause/pause03.c +4
-35+*/ -static void do_child (void ); -static void setup (void ); -static void cleanup (void ); +#include "tst_test.h" -int main (int ac,char **av) +void run (void ) { -int lc;int status; +pid_t pid; -tst_parse_opts (ac, av,NULL ,NULL ); - -setup (); - -for (lc =0 ;TEST_LOOPING (lc); lc++) { - tst_count =0 ; - -if ((cpid =tst_fork ()) ==-1 ) -tst_brkm (TBROK |TERRNO ,NULL ,"fork() failed" ); - -if (cpid ==0 ) -do_child (); - -TST_PROCESS_STATE_WAIT (cleanup, cpid,'S' ); - -kill (cpid,SIGKILL ); - -SAFE_WAIT (NULL , &status); - -if (WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL ) { -tst_resm (TPASS ,"pause() did not return after SIGKILL" ); -continue ; - } - -if (WIFSIGNALED (status)) { -tst_resm (TFAIL ,"child killed by %s unexpectedly" , -tst_strsig (WTERMSIG (status))); -continue ; - } -
testcases/kernel/syscalls/pause/pause03.c line 26
Quoted 10 lines
testcases/kernel/syscalls/pause/pause03.c +5
-3-tst_resm (TFAIL ,"child exited with %i" ,WEXITSTATUS (status)); + pid =SAFE_FORK (); +if (!pid) { +TST_EXP_PASS (pause ()); +exit (0 ); } -cleanup (); -tst_exit (); +TST_PROCESS_STATE_WAIT (pid,'S' ,10000 );
Same as with the pause01 we need the checpoints before we check the process state.
testcases/kernel/syscalls/pause/pause03.c line 27
Quoted 1 line
testcases/kernel/syscalls/pause/pause03.c +1
-0+SAFE_KILL (pid,SIGINT );
^ SIGKILL
The test does not even work with SIGINT...
testcases/kernel/syscalls/pause/pause03.c line 33
Quoted 6 lines
testcases/kernel/syscalls/pause/pause03.c +5
-0+SAFE_WAITPID (pid, &status,0 ); +if (WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL ) +tst_res (TPASS ,"pause() did not return after SIGKILL" ); +else +tst_res (TFAIL ,"Child exited with %i" ,WEXITSTATUS (status));
This is not correct, you should use tst_strstatus(status) that covers all the possible cases, as:
tst_res(TFAIL, "Child %s", tst_strstatus(status))
Quoted 34 lines
testcases/kernel/syscalls/pause/pause03.c +4
-21} -void do_child (void ) -{ -TEST (pause ()); - -tst_resm (TFAIL ,"Unexpected return from pause()" ); - -exit (0 ); -} - -void setup (void ) -{ -tst_sig (FORK ,DEF_HANDLER , cleanup); - -TEST_PAUSE ; -} - - -void cleanup (void ) -{ -kill (cpid,SIGKILL ); -} +static struct tst_test test = { + .test_all = run, + .forks_child =1 , +};Signature · 6 lines
-- 2.48.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp