* [LTP] [PATCH v2 0/3] syscalls/pause: Refactor tests
@ 2025-02-18 18:07 Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up Ricardo B. Marlière
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Ricardo B. Marlière @ 2025-02-18 18:07 UTC (permalink / raw)
To: Linux Test Project; +Cc: Ricardo B. Marlière
Signed-off-by: Ricardo B. Marlière <ricardo@marliere.net>
---
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/20250217-conversions-pause-v1-0-be8be41cb154@marliere.net
---
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,
--
Ricardo B. Marlière <rbm@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up
2025-02-18 18:07 [LTP] [PATCH v2 0/3] syscalls/pause: Refactor tests Ricardo B. Marlière
@ 2025-02-18 18:07 ` Ricardo B. Marlière
2025-02-21 10:17 ` Cyril Hrubis
2025-02-18 18:07 ` [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 3/3] syscalls/pause03: " Ricardo B. Marlière
2 siblings, 1 reply; 8+ messages in thread
From: Ricardo B. Marlière @ 2025-02-18 18:07 UTC (permalink / raw)
To: Linux Test Project; +Cc: Ricardo B. Marlière
From: Ricardo B. Marlière <rbm@suse.com>
Tidy up and add a description.
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
testcases/kernel/syscalls/pause/pause01.c | 34 +++++++++++++------------------
1 file changed, 14 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c
index c88248da0d9961c5414a694a91cf1aef40ff263a..adce0ddcf2e0639407b4e21de0a1be7b30efaa01 100644
--- a/testcases/kernel/syscalls/pause/pause01.c
+++ b/testcases/kernel/syscalls/pause/pause01.c
@@ -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 <rbm@suse.com>
*/
-#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,
};
--
2.48.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
2025-02-18 18:07 [LTP] [PATCH v2 0/3] syscalls/pause: Refactor tests Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up Ricardo B. Marlière
@ 2025-02-18 18:07 ` Ricardo B. Marlière
2025-02-21 10:39 ` Cyril Hrubis
2025-02-18 18:07 ` [LTP] [PATCH v2 3/3] syscalls/pause03: " Ricardo B. Marlière
2 siblings, 1 reply; 8+ messages in thread
From: Ricardo B. Marlière @ 2025-02-18 18:07 UTC (permalink / raw)
To: Linux Test Project; +Cc: Ricardo B. Marlière
From: Ricardo B. Marlière <rbm@suse.com>
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
testcases/kernel/syscalls/pause/pause02.c | 150 ++++++------------------------
1 file changed, 27 insertions(+), 123 deletions(-)
diff --git a/testcases/kernel/syscalls/pause/pause02.c b/testcases/kernel/syscalls/pause/pause02.c
index 0853232fd07b2c6278049dd4472a1ee8e7ab7646..749757d90b471ae65e2880519a396d4fae6ae8f6 100644
--- a/testcases/kernel/syscalls/pause/pause02.c
+++ b/testcases/kernel/syscalls/pause/pause02.c
@@ -1,147 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2001
* Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
- *
- * 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 <rbm@suse.com>
*/
-/*
+/*\
* 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,
+};
--
2.48.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v2 3/3] syscalls/pause03: Refactor into new API
2025-02-18 18:07 [LTP] [PATCH v2 0/3] syscalls/pause: Refactor tests Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API Ricardo B. Marlière
@ 2025-02-18 18:07 ` Ricardo B. Marlière
2025-02-21 10:32 ` Cyril Hrubis
2 siblings, 1 reply; 8+ messages in thread
From: Ricardo B. Marlière @ 2025-02-18 18:07 UTC (permalink / raw)
To: Linux Test Project; +Cc: Ricardo B. Marlière
From: Ricardo B. Marlière <rbm@suse.com>
Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
---
testcases/kernel/syscalls/pause/pause03.c | 115 +++++++-----------------------
1 file changed, 25 insertions(+), 90 deletions(-)
diff --git a/testcases/kernel/syscalls/pause/pause03.c b/testcases/kernel/syscalls/pause/pause03.c
index 459222045c08dc1fc4804efd2ece02316fe55a0e..85c3c18b19d63343c65fa553a65ecb6f9f0c0700 100644
--- a/testcases/kernel/syscalls/pause/pause03.c
+++ b/testcases/kernel/syscalls/pause/pause03.c
@@ -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 <rbm@suse.com>
*/
-/*
- * 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,
+};
--
2.48.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up
2025-02-18 18:07 ` [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up Ricardo B. Marlière
@ 2025-02-21 10:17 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2025-02-21 10:17 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Ricardo B. Marlière, Linux Test Project
Hi!
> Signed-off-by: Ricardo B. Marlière <rbm@suse.com>
> ---
> testcases/kernel/syscalls/pause/pause01.c | 34 +++++++++++++------------------
> 1 file changed, 14 insertions(+), 20 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c
> index c88248da0d9961c5414a694a91cf1aef40ff263a..adce0ddcf2e0639407b4e21de0a1be7b30efaa01 100644
> --- a/testcases/kernel/syscalls/pause/pause01.c
> +++ b/testcases/kernel/syscalls/pause/pause01.c
> @@ -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 <rbm@suse.com>
> */
> -#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);
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:
diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c
index adce0ddcf..680fa2c05 100644
--- a/testcases/kernel/syscalls/pause/pause01.c
+++ b/testcases/kernel/syscalls/pause/pause01.c
@@ -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 = {
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 3/3] syscalls/pause03: Refactor into new API
2025-02-18 18:07 ` [LTP] [PATCH v2 3/3] syscalls/pause03: " Ricardo B. Marlière
@ 2025-02-21 10:32 ` Cyril Hrubis
0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2025-02-21 10:32 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Ricardo B. Marlière, Linux Test Project
Hi!
> ---
> testcases/kernel/syscalls/pause/pause03.c | 115 +++++++-----------------------
> 1 file changed, 25 insertions(+), 90 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/pause/pause03.c b/testcases/kernel/syscalls/pause/pause03.c
> index 459222045c08dc1fc4804efd2ece02316fe55a0e..85c3c18b19d63343c65fa553a65ecb6f9f0c0700 100644
> --- a/testcases/kernel/syscalls/pause/pause03.c
> +++ b/testcases/kernel/syscalls/pause/pause03.c
> @@ -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 <rbm@suse.com>
> */
> -/*
> - * 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.
Maybe this can be shorter, something as:
Verifies that pause() does not return after process recieved SIGKILL.
> + */
>
> -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);
Same as with the pause01 we need the checpoints before we check the
process state.
> + SAFE_KILL(pid, SIGINT);
^
SIGKILL
The test does not even work with 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));
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))
> }
>
> -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,
> +};
>
> --
> 2.48.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
2025-02-18 18:07 ` [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API Ricardo B. Marlière
@ 2025-02-21 10:39 ` Cyril Hrubis
2025-02-24 10:49 ` Ricardo B. Marlière via ltp
0 siblings, 1 reply; 8+ messages in thread
From: Cyril Hrubis @ 2025-02-21 10:39 UTC (permalink / raw)
To: Ricardo B. Marlière; +Cc: Ricardo B. Marlière, Linux Test Project
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:
diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c
index adce0ddcf..74a7e514e 100644
--- a/testcases/kernel/syscalls/pause/pause01.c
+++ b/testcases/kernel/syscalls/pause/pause01.c
@@ -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).
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
2025-02-21 10:39 ` Cyril Hrubis
@ 2025-02-24 10:49 ` Ricardo B. Marlière via ltp
0 siblings, 0 replies; 8+ messages in thread
From: Ricardo B. Marlière via ltp @ 2025-02-24 10:49 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: Linux Test Project
Hello Cyril,
On Fri Feb 21, 2025 at 7:39 AM -03, Cyril Hrubis wrote:
> 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:
>
> diff --git a/testcases/kernel/syscalls/pause/pause01.c b/testcases/kernel/syscalls/pause/pause01.c
> index adce0ddcf..74a7e514e 100644
> --- a/testcases/kernel/syscalls/pause/pause01.c
> +++ b/testcases/kernel/syscalls/pause/pause01.c
> @@ -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).
Thanks for the review and explanations! I'll address your points in the
next revision.
- Ricardo.
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-02-24 10:50 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18 18:07 [LTP] [PATCH v2 0/3] syscalls/pause: Refactor tests Ricardo B. Marlière
2025-02-18 18:07 ` [LTP] [PATCH v2 1/3] syscalls/pause01: Clean up Ricardo B. Marlière
2025-02-21 10:17 ` Cyril Hrubis
2025-02-18 18:07 ` [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API Ricardo B. Marlière
2025-02-21 10:39 ` Cyril Hrubis
2025-02-24 10:49 ` Ricardo B. Marlière via ltp
2025-02-18 18:07 ` [LTP] [PATCH v2 3/3] syscalls/pause03: " Ricardo B. Marlière
2025-02-21 10:32 ` Cyril Hrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.