From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] getsid01.c: Convert to new LTP API
Date: Tue, 30 Aug 2022 12:50:28 +0530 [thread overview]
Message-ID: <20220830072028.1115-1-akumar@suse.de> (raw)
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
testcases/kernel/syscalls/getsid/getsid01.c | 164 +++-----------------
1 file changed, 23 insertions(+), 141 deletions(-)
diff --git a/testcases/kernel/syscalls/getsid/getsid01.c b/testcases/kernel/syscalls/getsid/getsid01.c
index 0857468f1..2bcc10e70 100644
--- a/testcases/kernel/syscalls/getsid/getsid01.c
+++ b/testcases/kernel/syscalls/getsid/getsid01.c
@@ -1,159 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
* Copyright (c) International Business Machines Corp., 2001
- *
- * 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) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
*/
-/*
- * NAME
- * getsid01.c
- *
- * DESCRIPTION
- * getsid01 - call getsid() and make sure it succeeds
- *
- * ALGORITHM
- * loop if that option was specified
- * issue the system call
- * check the return value
- * if return value == -1
- * issue a FAIL message, break remaining tests and cleanup
- * if we are doing functional testing
- * save the return value from the getsid() call - the session ID
- * fork a child and get the child's session ID
- * if the child's session ID == the parent's session ID
- * issue a PASS message
- * else
- * issue a FAIL message
- * else issue a PASS message
- * call cleanup
- *
- * USAGE: <for command-line>
- * getsid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- * where, -c n : Run n copies concurrently.
- * -f : Turn off functionality Testing.
- * -i n : Execute test n times.
- * -I x : Execute test for x seconds.
- * -P x : Pause for x seconds between iterations.
- * -t : Turn on syscall timing.
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
+/*\
+ * [Description]
*
- * RESTRICTIONS
- * none
+ * Verify that session IDs returned by getsid() (with argument pid=0)
+ * are same in parent and child process.
*/
-#define _GNU_SOURCE 1
-#include <errno.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include "test.h"
-void cleanup(void);
-void setup(void);
+#include "tst_test.h"
-char *TCID = "getsid01";
-int TST_TOTAL = 1;
+static pid_t p_sid;
-pid_t p_sid;
-
-int main(int ac, char **av)
+static void run(void)
{
- int lc;
- pid_t pid, c_pid, c_sid;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup(); /* global setup */
-
- /* The following loop checks looping state if -i option given */
+ pid_t pid, c_sid;
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- /* reset tst_count in case we are looping */
- tst_count = 0;
+ TEST(getsid(0));
+ p_sid = TST_RET;
- /* call the system call with the TEST() macro */
+ pid = SAFE_FORK();
+ if (pid == 0) {
TEST(getsid(0));
-
- if (TEST_RETURN == -1) {
- tst_resm(TFAIL, "call failed - errno = %d "
- "- %s", TEST_ERRNO, strerror(TEST_ERRNO));
- continue;
- }
-
- /* save the return value in a global variable */
- p_sid = TEST_RETURN;
-
- if ((pid = FORK_OR_VFORK()) == -1) {
- tst_brkm(TBROK, cleanup, "could not fork");
- }
-
- if (pid == 0) { /* child */
- if ((c_pid = getpid()) == -1) {
- tst_resm(TINFO, "getpid failed in "
- "functionality test");
- exit(1);
- }
-
- /*
- * if the session ID of the child is the
- * same as the parent then things look good
- */
-
- if ((c_sid = getsid(0)) == -1) {
- tst_resm(TINFO, "getsid failed in "
- "functionality test");
- exit(2);
- }
-
- if (c_sid == p_sid) {
- tst_resm(TPASS, "session ID is "
- "correct");
- } else {
- tst_resm(TFAIL, "session ID is "
- "not correct");
- }
- exit(0);
-
- } else {
- waitpid(pid, NULL, 0);
- }
+ c_sid = TST_RET;
+ TST_EXP_EQ_LI(p_sid, c_sid);
+ } else {
+ SAFE_WAITPID(pid, NULL, 0);
}
-
- cleanup();
- tst_exit();
}
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1
+};
--
2.37.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2022-08-30 7:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 7:20 Avinesh Kumar [this message]
2022-08-31 6:35 ` [LTP] [PATCH] getsid01.c: Convert to new LTP API Li Wang
2022-09-01 10:53 ` Avinesh Kumar
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=20220830072028.1115-1-akumar@suse.de \
--to=akumar@suse.de \
--cc=ltp@lists.linux.it \
/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.