From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/3] getpgid01.c: Rewrite using new LTP API
Date: Tue, 4 Apr 2023 11:14:46 +0530 [thread overview]
Message-ID: <20230404054448.23095-1-akumar@suse.de> (raw)
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
testcases/kernel/syscalls/getpgid/getpgid01.c | 157 ++++--------------
1 file changed, 30 insertions(+), 127 deletions(-)
diff --git a/testcases/kernel/syscalls/getpgid/getpgid01.c b/testcases/kernel/syscalls/getpgid/getpgid01.c
index 060486e7e..a5a9a813b 100644
--- a/testcases/kernel/syscalls/getpgid/getpgid01.c
+++ b/testcases/kernel/syscalls/getpgid/getpgid01.c
@@ -1,145 +1,48 @@
+// 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
+ * Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2023 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
*/
-/*
- * NAME
- * getpgid01.c
- *
- * DESCRIPTION
- * Testcase to check the basic functionality of getpgid().
- *
- * ALGORITHM
- * block1: Does getpgid(0), and checks for error.
- * block2: Does getpgid(getpid()) and checks for error.
- * block3: Does getpgid(getppid()) and checks for error.
- * block4: Verifies that getpgid(getpgid(0)) == getpgid(0).
- * block5: Does getpgid(1) and checks for error.
+/*\
+ * [Description]
*
- * USAGE
- * getpgid01
- *
- * HISTORY
- * 07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * Expects that there are no EPERM limitations on getting the
- * process group ID from proc 1 (init).
+ * Verify the basic functionality of getpgid(2) syscall.
*/
-#define _GNU_SOURCE 1
-
-#include <errno.h>
-#include <unistd.h>
-#include <stdarg.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include "test.h"
-
-void setup(void);
-void cleanup(void);
-char *TCID = "getpgid01";
-int TST_TOTAL = 1;
+#include "tst_test.h"
-int main(int ac, char **av)
+static void run(void)
{
- int lc;
-
- register int pgid_0, pgid_1;
- register int my_pid, my_ppid;
- int ex_stat;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
+ pid_t pid_1, ppid, child_pid;
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
+ pid_1 = SAFE_FORK();
+ if (!pid_1) {
+ child_pid = getpid();
+ ppid = getppid();
- if ((pgid_0 = FORK_OR_VFORK()) == -1)
- tst_brkm(TBROK, cleanup, "fork failed");
- if (pgid_0 > 0) {
- while ((pgid_0 = wait(&ex_stat)) != -1) ;
+ tst_res(TINFO, "getpid() in child = %d", child_pid);
+ tst_res(TINFO, "getppid() in child = %d", ppid);
+ tst_res(TINFO, "Running getpgid() in child");
- if (WEXITSTATUS(ex_stat) == 0)
- tst_resm(TPASS, "%s PASSED", TCID);
- else
- tst_resm(TFAIL, "%s FAILED", TCID);
+ TST_EXP_POSITIVE(getpgid(0));
+ TST_EXP_EQ_LI(TST_RET, ppid);
- exit(0);
- }
+ TST_EXP_POSITIVE(getpgid(child_pid), "getpgid(%d)", child_pid);
+ TST_EXP_EQ_LI(TST_RET, ppid);
- if ((pgid_0 = getpgid(0)) == -1)
- tst_resm(TFAIL | TERRNO, "getpgid(0) failed");
- else
- tst_resm(TPASS, "getpgid(0) PASSED");
+ TST_EXP_POSITIVE(getpgid(ppid), "getpgid(%d)", ppid);
+ TST_EXP_EQ_LI(TST_RET, ppid);
-//block2:
- my_pid = getpid();
- if ((pgid_1 = getpgid(my_pid)) == -1)
- tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", my_pid);
-
- if (pgid_0 != pgid_1) {
- tst_resm(TFAIL, "getpgid(my_pid=%d) != getpgid(0) "
- "[%d != %d]", my_pid, pgid_1, pgid_0);
- } else
- tst_resm(TPASS, "getpgid(getpid()) PASSED");
-
-//block3:
- my_ppid = getppid();
- if ((pgid_1 = getpgid(my_ppid)) == -1)
- tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", my_ppid);
-
- if (pgid_0 != pgid_1) {
- tst_resm(TFAIL, "getpgid(%d) != getpgid(0) [%d != %d]",
- my_ppid, pgid_1, pgid_0);
- } else
- tst_resm(TPASS, "getpgid(getppid()) PASSED");
-
-//block4:
- if ((pgid_1 = getpgid(pgid_0)) < 0)
- tst_resm(TFAIL | TERRNO, "getpgid(%d) failed", pgid_0);
-
- if (pgid_0 != pgid_1) {
- tst_resm(TFAIL, "getpgid(%d) != getpgid(0) [%d != %d]",
- pgid_0, pgid_1, pgid_0);
- } else
- tst_resm(TPASS, "getpgid(%d) PASSED", pgid_0);
-
-//block5:
- if (getpgid(1) < 0)
- tst_resm(TFAIL | TERRNO, "getpgid(1) failed");
- else
- tst_resm(TPASS, "getpgid(1) PASSED");
+ TST_EXP_POSITIVE(getpgid(1));
+ TST_EXP_EQ_LI(TST_RET, 1);
}
- cleanup();
- tst_exit();
+ tst_reap_children();
}
-void setup(void)
-{
-
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1
+};
--
2.40.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2023-04-04 5:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-04 5:44 Avinesh Kumar [this message]
2023-04-04 5:44 ` [LTP] [PATCH 2/3] getpgid02.c: Rewrite using new LTP API Avinesh Kumar
2023-04-11 14:52 ` Cyril Hrubis
2023-04-04 5:44 ` [LTP] [PATCH 3/3] getpgrp01: Convert to " Avinesh Kumar
2023-04-05 10:55 ` [LTP] [PATCH 1/3] getpgid01.c: Rewrite using " Cyril Hrubis
2023-04-12 8:52 ` Avinesh Kumar
2023-04-13 8:40 ` 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=20230404054448.23095-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.