All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v2 1/2] setpgid/setpgid01.c: cleanup
@ 2014-05-16  3:38 Xiaoguang Wang
  2014-05-16  3:38 ` [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0 test Xiaoguang Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Xiaoguang Wang @ 2014-05-16  3:38 UTC (permalink / raw)
  To: ltp-list

Delete some useless comments.

Do some code re-arrangement and remove the 'if (pgid == pid)' check,
which is useless.

Some cleanup.

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setpgid/setpgid01.c | 187 +++++---------------------
 1 file changed, 30 insertions(+), 157 deletions(-)

diff --git a/testcases/kernel/syscalls/setpgid/setpgid01.c b/testcases/kernel/syscalls/setpgid/setpgid01.c
index 57e71fc..700e573 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid01.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid01.c
@@ -31,201 +31,74 @@
  *
  */
 /* $Id: setpgid01.c,v 1.7 2009/11/02 13:57:18 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: setpgid01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for setpgid(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) setpgid(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the setpgid(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	setpgid(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+
+/*
+ * Description:
+ * Verify that:
+ *   1. Basic functionality test for setpgid(2).
+ */
 
 #include <errno.h>
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <sys/wait.h>
 #include "test.h"
 #include "usctest.h"
 
-void setup();
-void cleanup();
+static void setup(void);
+static void cleanup(void);
 
 char *TCID = "setpgid01";
-int TST_TOTAL = 1;
-
-int exp_enos[] = { 0, 0 };
 
-int pgid, pid;
+static void setpgid_test1(void);
+static void (*testfunc[])(void) = { setpgid_test1};
+int TST_TOTAL = ARRAY_SIZE(testfunc);
 
 int main(int ac, char **av)
 {
-	int lc;
+	int i, lc;
 	char *msg;
 
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
 	setup();
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
 		tst_count = 0;
 
-		/*
-		 * Call setpgid(2)
-		 */
-		TEST(setpgid(pid, pgid));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			TEST_ERROR_LOG(TEST_ERRNO);
-			tst_resm(TFAIL, "setpgid(%d, %d) Failed, errno=%d : %s",
-				 pid, pgid, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
-			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
-				tst_resm(TPASS, "setpgid(%d, %d) returned %ld",
-					 pid, pgid, TEST_RETURN);
-			}
-		}
+		for (i = 0; i < TST_TOTAL; i++)
+			(*testfunc[i])();
 	}
 
-    /***************************************************************
-     * cleanup and exit
-     ***************************************************************/
 	cleanup();
 	tst_exit();
-
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void setpgid_test1(void)
 {
-	int status;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Make sure current process is NOT a session or pgrp leader
-	 */
+	pid_t pgid, pid;
 
 	pgid = getpgrp();
 	pid = getpid();
 
-	if (pgid == pid) {
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "fork() in setup() failed - errno %d", errno);
-		}
-
-		if (pid != 0) {	/* parent - sits and waits */
-			wait(&status);
-			exit(WEXITSTATUS(status));
-		} else {	/* child - continues with test */
-			pid = getpid();
-		}
+	TEST(setpgid(pid, pgid));
+	if (TEST_RETURN == -1 || getpgrp() != pgid) {
+		tst_resm(TFAIL | TTERRNO, "test setpgid(%d, %d) fail",
+			 pid, pgid);
+	} else {
+		tst_resm(TPASS, "test setpgid(%d, %d) success", pid, pgid);
 	}
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void setup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	TEST_CLEANUP;
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
+	TEST_PAUSE;
+}
+
+static void cleanup(void)
+{
+	TEST_CLEANUP;
 }
-- 
1.8.2.1


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0 test
  2014-05-16  3:38 [LTP] [PATCH v2 1/2] setpgid/setpgid01.c: cleanup Xiaoguang Wang
@ 2014-05-16  3:38 ` Xiaoguang Wang
  2014-05-16 11:53   ` Jan Stancek
  0 siblings, 1 reply; 3+ messages in thread
From: Xiaoguang Wang @ 2014-05-16  3:38 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/setpgid/setpgid01.c | 47 +++++++++++++++++++++++++--
 1 file changed, 45 insertions(+), 2 deletions(-)

diff --git a/testcases/kernel/syscalls/setpgid/setpgid01.c b/testcases/kernel/syscalls/setpgid/setpgid01.c
index 700e573..23f0508 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid01.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid01.c
@@ -36,12 +36,14 @@
  * Description:
  * Verify that:
  *   1. Basic functionality test for setpgid(2).
+ *   2. Check functioning of setpgid(2) with pid = 0 and pgid = 0.
  */
 
 #include <errno.h>
 #include <string.h>
 #include <signal.h>
 #include <stdlib.h>
+#include <sys/wait.h>
 #include "test.h"
 #include "usctest.h"
 
@@ -51,7 +53,8 @@ static void cleanup(void);
 char *TCID = "setpgid01";
 
 static void setpgid_test1(void);
-static void (*testfunc[])(void) = { setpgid_test1};
+static void setpgid_test2(void);
+static void (*testfunc[])(void) = { setpgid_test1, setpgid_test2};
 int TST_TOTAL = ARRAY_SIZE(testfunc);
 
 int main(int ac, char **av)
@@ -91,9 +94,49 @@ static void setpgid_test1(void)
 	}
 }
 
+static int wait4child(pid_t child)
+{
+	int status;
+
+	if (waitpid(child, &status, 0) == -1)
+		tst_resm(TBROK|TERRNO, "waitpid");
+	if (WIFEXITED(status))
+		return WEXITSTATUS(status);
+	else
+		return status;
+}
+
+static void setpgid_test2(void)
+{
+	int ret;
+	pid_t pgid, pid;
+
+	pid = FORK_OR_VFORK();
+	if (pid == -1)
+		tst_brkm(TBROK | TERRNO, cleanup, "fork()");
+
+	if (pid != 0) {
+		ret = wait4child(pid);
+	} else {
+		pid = getpid();
+		TEST(setpgid(0, 0));
+		pgid = getpgrp();
+		if (TEST_RETURN == -1 || pgid != pid)
+			exit(1);
+		else
+			exit(0);
+	}
+
+	if (ret == 0)
+		tst_resm(TPASS, "test setpgid(0, 0) success");
+	else
+		tst_resm(TFAIL, "test setpgid(0, 0) fail");
+}
+
+
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	tst_sig(FORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 }
-- 
1.8.2.1


------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0 test
  2014-05-16  3:38 ` [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0 test Xiaoguang Wang
@ 2014-05-16 11:53   ` Jan Stancek
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Stancek @ 2014-05-16 11:53 UTC (permalink / raw)
  To: Xiaoguang Wang; +Cc: ltp-list



----- Original Message -----
> From: "Xiaoguang Wang" <wangxg.fnst@cn.fujitsu.com>
> To: ltp-list@lists.sourceforge.net
> Sent: Friday, 16 May, 2014 5:38:37 AM
> Subject: [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0	test
> 
> Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/setpgid/setpgid01.c | 47
>  +++++++++++++++++++++++++--
>  1 file changed, 45 insertions(+), 2 deletions(-)

Hi,

series look good to me.
I have only one small nit, see comment inline.

Regards,
Jan

> 
> diff --git a/testcases/kernel/syscalls/setpgid/setpgid01.c
> b/testcases/kernel/syscalls/setpgid/setpgid01.c
> index 700e573..23f0508 100644
> --- a/testcases/kernel/syscalls/setpgid/setpgid01.c
> +++ b/testcases/kernel/syscalls/setpgid/setpgid01.c
> @@ -36,12 +36,14 @@
>   * Description:
>   * Verify that:
>   *   1. Basic functionality test for setpgid(2).
> + *   2. Check functioning of setpgid(2) with pid = 0 and pgid = 0.
>   */
>  
>  #include <errno.h>
>  #include <string.h>
>  #include <signal.h>
>  #include <stdlib.h>
> +#include <sys/wait.h>
>  #include "test.h"
>  #include "usctest.h"
>  
> @@ -51,7 +53,8 @@ static void cleanup(void);
>  char *TCID = "setpgid01";
>  
>  static void setpgid_test1(void);
> -static void (*testfunc[])(void) = { setpgid_test1};
> +static void setpgid_test2(void);
> +static void (*testfunc[])(void) = { setpgid_test1, setpgid_test2};
>  int TST_TOTAL = ARRAY_SIZE(testfunc);
>  
>  int main(int ac, char **av)
> @@ -91,9 +94,49 @@ static void setpgid_test1(void)
>  	}
>  }
>  
> +static int wait4child(pid_t child)
> +{
> +	int status;
> +
> +	if (waitpid(child, &status, 0) == -1)
> +		tst_resm(TBROK|TERRNO, "waitpid");
> +	if (WIFEXITED(status))
> +		return WEXITSTATUS(status);
> +	else
> +		return status;
> +}
> +
> +static void setpgid_test2(void)
> +{
> +	int ret;
> +	pid_t pgid, pid;
> +
> +	pid = FORK_OR_VFORK();
> +	if (pid == -1)
> +		tst_brkm(TBROK | TERRNO, cleanup, "fork()");
> +
> +	if (pid != 0) {
> +		ret = wait4child(pid);
> +	} else {
> +		pid = getpid();
> +		TEST(setpgid(0, 0));
> +		pgid = getpgrp();
> +		if (TEST_RETURN == -1 || pgid != pid)

^^ I'd suggest to add printf here with TEST_ERRNO. In unlikely
case it fails, it would good to know why.

> +			exit(1);
> +		else
> +			exit(0);
> +	}
> +
> +	if (ret == 0)
> +		tst_resm(TPASS, "test setpgid(0, 0) success");
> +	else
> +		tst_resm(TFAIL, "test setpgid(0, 0) fail");
> +}
> +
> +
>  static void setup(void)
>  {
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
>  
>  	TEST_PAUSE;
>  }
> --
> 1.8.2.1
> 
> 
> ------------------------------------------------------------------------------
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list
> 

------------------------------------------------------------------------------
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-05-16 11:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-16  3:38 [LTP] [PATCH v2 1/2] setpgid/setpgid01.c: cleanup Xiaoguang Wang
2014-05-16  3:38 ` [LTP] [PATCH v2 2/2] setpgid/setpgid01.c: add pid = 0 and pgid = 0 test Xiaoguang Wang
2014-05-16 11:53   ` Jan Stancek

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.