From: "Ricardo B. Marlière" <ricardo@marliere.net>
To: Linux Test Project <ltp@lists.linux.it>
Cc: "Ricardo B. Marlière" <rbm@suse.com>
Subject: [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API
Date: Tue, 18 Feb 2025 15:07:18 -0300 [thread overview]
Message-ID: <20250218-conversions-pause-v2-2-8c72960fe1ec@suse.com> (raw)
In-Reply-To: <20250218-conversions-pause-v2-0-8c72960fe1ec@suse.com>
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
next prev parent reply other threads:[~2025-02-18 18:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Ricardo B. Marlière [this message]
2025-02-21 10:39 ` [LTP] [PATCH v2 2/3] syscalls/pause02: Refactor into new API 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250218-conversions-pause-v2-2-8c72960fe1ec@suse.com \
--to=ricardo@marliere.net \
--cc=ltp@lists.linux.it \
--cc=rbm@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.