All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
To: ltp-list@lists.sourceforge.net
Cc: vasily.isaenko@oracle.com
Subject: [LTP] [PATCH V3 1/2] setpgid03: handle children errors and cleanup
Date: Thu, 12 Dec 2013 13:21:54 +0400	[thread overview]
Message-ID: <1386840115-9703-1-git-send-email-stanislav.kholmanskikh@oracle.com> (raw)
In-Reply-To: <1383124058-13133-3-git-send-email-stanislav.kholmanskikh@oracle.com>

If one of the children exits with non zero value we can't see
it until DEBUG is set. Now if the exit value is not 0, we
print this value with tst_resm(TFAIL).

Also performed minor cleanup.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 testcases/kernel/syscalls/setpgid/setpgid03.c |  160 +++++++++----------------
 1 files changed, 58 insertions(+), 102 deletions(-)

diff --git a/testcases/kernel/syscalls/setpgid/setpgid03.c b/testcases/kernel/syscalls/setpgid/setpgid03.c
index 4429fe4..2c47bc4 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid03.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid03.c
@@ -1,38 +1,25 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   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 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.
  *
- *   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
+ * 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
  */
 
 /*
- * NAME
- * 	setpgid03.c
- *
- * DESCRIPTION
- * 	Test to check the error and trivial conditions in setpgid system call
- *
- * USAGE
- * 	setuid03
- *
- * RESTRICTIONS
- * 	This test is not completely written in the LTP format - PLEASE FIX!
+ * Test to check the error and trivial conditions in setpgid system call
  */
 
-#define DEBUG 0
-
 #include <wait.h>
 #include <limits.h>
 #include <signal.h>
@@ -47,16 +34,15 @@
 char *TCID = "setpgid03";
 int TST_TOTAL = 1;
 
-void do_child(void);
-void setup(void);
-void cleanup(void);
+static void do_child(void);
+static void setup(void);
+static void cleanup(void);
 
 int main(int ac, char **av)
 {
 	int pid;
-	int rval, fail = 0;
-	int ret, status;
-	int exno = 0;
+	int rval;
+	int status;
 
 	int lc;
 	char *msg;
@@ -68,14 +54,10 @@ int main(int ac, char **av)
 	maybe_run_child(&do_child, "");
 #endif
 
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 //test1:
@@ -92,35 +74,27 @@ int main(int ac, char **av)
 #else
 			do_child();
 #endif
-		} else {	/* parent */
-			sleep(1);
-			rval = setpgid(pid, getppid());
-			if (errno == EPERM) {
-				tst_resm(TPASS, "setpgid SUCCESS to set "
-					 "errno to EPERM");
-			} else {
-				tst_resm(TFAIL, "setpgid FAILED, "
-					 "expect %d, return %d", EPERM, errno);
-				fail = 1;
-			}
-			sleep(1);
-			if ((ret = wait(&status)) > 0) {
-				if (DEBUG)
-					tst_resm(TINFO, "Test {%d} exited "
-						 "status 0x%0x", ret, status);
-
-				if (status != 0) {
-					fail = 1;
-				}
-			}
 		}
-		if (DEBUG) {
-			if (fail || exno) {
-				tst_resm(TINFO, "Test test 1: FAILED");
-			} else {
-				tst_resm(TINFO, "Test test 1: PASSED");
-			}
+
+		sleep(1);
+		rval = setpgid(pid, getppid());
+		if (errno == EPERM) {
+			tst_resm(TPASS,
+				"setpgid SUCCESS to set errno to EPERM");
+		} else {
+			tst_resm(TFAIL,
+				"setpgid FAILED, expect %d, return %d",
+				EPERM, errno);
 		}
+		sleep(1);
+
+		if (wait(&status) < 0)
+			tst_resm(TFAIL | TERRNO, "wait() for child 1 failed");
+
+		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
+			tst_resm(TFAIL, "child 1 failed with status %d",
+				WEXITSTATUS(status));
+
 //test2:
 		/*
 		 * Value of pid matches the pid of the child process and
@@ -135,51 +109,43 @@ int main(int ac, char **av)
 				perror("exec failed");
 			}
 			exit(127);
+		}
+
+		sleep(1);
+		rval = setpgid(pid, getppid());
+		if (errno == EACCES) {
+			tst_resm(TPASS,
+				"setpgid SUCCEEDED to set errno to EACCES");
 		} else {
-			sleep(1);
-			rval = setpgid(pid, getppid());
-			if (errno == EACCES) {
-				tst_resm(TPASS, "setpgid SUCCEEDED to set "
-					 "errno to EACCES");
-			} else {
-				tst_resm(TFAIL, "setpgid FAILED, expect EACCES "
-					 "got %d", errno);
-			}
-			if ((ret = wait(&status)) > 0) {
-				if (DEBUG)
-					tst_resm(TINFO, "Test {%d} exited "
-						 "status 0x%0x", ret, status);
-				if (status != 0) {
-					fail = 1;
-				}
-			}
+			tst_resm(TFAIL,
+				"setpgid FAILED, expect EACCES got %d", errno);
 		}
+
+		if (wait(&status) < 0)
+			tst_resm(TFAIL | TERRNO, "wait() for child 2 failed");
+
+		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
+			tst_resm(TFAIL, "child 2 failed with status %d",
+				WEXITSTATUS(status));
 	}
+
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * do_child()
- */
-void do_child()
+static void do_child(void)
 {
 	int exno = 0;
 
 	if (setsid() < 0) {
-		tst_resm(TFAIL, "setsid failed, errno :%d", errno);
+		printf("setsid() failed, errno: %d\n", errno);
 		exno = 1;
 	}
 	sleep(2);
 	exit(exno);
 }
 
-/*
- * setup()
- * 	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
@@ -189,17 +155,7 @@ void setup(void)
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- * 	performs all the ONE TIME cleanup for this test at completion
- * 	or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing status if that option was specified
-	 * print errno log if that option was specified
-	 */
 	TEST_CLEANUP;
-
 }
-- 
1.7.1


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

  parent reply	other threads:[~2013-12-12  9:22 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-29  7:55 [LTP] [PATCH] setpgid03: use SIGUSR1 instead of sleep Stanislav Kholmanskikh
2013-10-29 10:30 ` Jan Stancek
2013-10-29 11:54   ` Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH SERIES V2] " Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH V2 1/2] setpgid03: handle children errors and cleanup Stanislav Kholmanskikh
2013-10-30  9:07   ` [LTP] [PATCH V2 2/2] setpgid03: use SIGUSR1 instead of sleep Stanislav Kholmanskikh
2013-10-30 13:45     ` Jan Stancek
2013-10-31  7:54       ` Stanislav Kholmanskikh
2013-10-31 15:06         ` chrubis
     [not found]           ` <52727305.5070806@oracle.com>
2013-10-31 16:29             ` chrubis
     [not found]               ` <527B7485.2030809@oracle.com>
2013-11-07 11:30                 ` chrubis
2013-11-13  7:52                   ` [LTP] [RFC PATCH] tst_checkpoint_signal_child: implemented timeout Stanislav Kholmanskikh
2013-11-13  8:46                     ` Jan Stancek
2013-11-13  8:58                       ` Stanislav Kholmanskikh
2013-11-13  9:15                         ` [LTP] [RFC PATCH V2] " Stanislav Kholmanskikh
2013-11-13 17:50                           ` chrubis
2013-11-14  6:37                             ` [LTP] [PATCH V3 1/2] tst_res: added ETIME, ETIMEDOUT errno values Stanislav Kholmanskikh
2013-11-14 14:19                               ` chrubis
2013-11-14  6:37                             ` [LTP] [PATCH V3 2/2] tst_checkpoint_signal_child: implemented timeout Stanislav Kholmanskikh
2013-11-14  9:05                               ` Jan Stancek
2013-11-14 14:33                               ` chrubis
2013-12-12  9:21     ` Stanislav Kholmanskikh [this message]
2013-12-12  9:21     ` [LTP] [PATCH V3 2/2] setpgid03: use tst_checkpoint interface Stanislav Kholmanskikh
2014-01-20 16:09       ` chrubis
     [not found]         ` <52DE7063.8070305@oracle.com>
2014-01-21 13:20           ` chrubis
2013-10-30  2:25 ` [LTP] [PATCH] setpgid03: use SIGUSR1 instead of sleep Wanlong Gao

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=1386840115-9703-1-git-send-email-stanislav.kholmanskikh@oracle.com \
    --to=stanislav.kholmanskikh@oracle.com \
    --cc=ltp-list@lists.sourceforge.net \
    --cc=vasily.isaenko@oracle.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.