* [LTP] [PATCH] getsid01.c: Convert to new LTP API
@ 2022-08-30 7:20 Avinesh Kumar
2022-08-31 6:35 ` Li Wang
0 siblings, 1 reply; 3+ messages in thread
From: Avinesh Kumar @ 2022-08-30 7:20 UTC (permalink / raw)
To: ltp
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH] getsid01.c: Convert to new LTP API
2022-08-30 7:20 [LTP] [PATCH] getsid01.c: Convert to new LTP API Avinesh Kumar
@ 2022-08-31 6:35 ` Li Wang
2022-09-01 10:53 ` Avinesh Kumar
0 siblings, 1 reply; 3+ messages in thread
From: Li Wang @ 2022-08-31 6:35 UTC (permalink / raw)
To: Avinesh Kumar; +Cc: LTP List
[-- Attachment #1.1: Type: text/plain, Size: 463 bytes --]
Hi Avinesh,
Avinesh Kumar <akumar@suse.de> wrote:
> - 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;
>
We'd better examine TST_RET not equal -1, otherwise, the test can
still report pass with two wrong values (-1) returned. isn't it?
> + c_sid = TST_RET;
>
Here as well.
--
Regards,
Li Wang
[-- Attachment #1.2: Type: text/html, Size: 1451 bytes --]
[-- Attachment #2: Type: text/plain, Size: 60 bytes --]
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [LTP] [PATCH] getsid01.c: Convert to new LTP API
2022-08-31 6:35 ` Li Wang
@ 2022-09-01 10:53 ` Avinesh Kumar
0 siblings, 0 replies; 3+ messages in thread
From: Avinesh Kumar @ 2022-09-01 10:53 UTC (permalink / raw)
To: ltp, Li Wang
Hi Li,
On Wednesday, August 31, 2022 12:05:32 PM IST Li Wang wrote:
> Hi Avinesh,
>
> Avinesh Kumar <akumar@suse.de> wrote:
>
>
> > - 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;
> >
>
> We'd better examine TST_RET not equal -1, otherwise, the test can
> still report pass with two wrong values (-1) returned. isn't it?
>
>
> > + c_sid = TST_RET;
> >
>
> Here as well.
Yes, thank you for pointing this out, sending v2.
>
>
>
Regards,
Avinesh
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-01 10:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-30 7:20 [LTP] [PATCH] getsid01.c: Convert to new LTP API Avinesh Kumar
2022-08-31 6:35 ` Li Wang
2022-09-01 10:53 ` Avinesh Kumar
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.