public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API
@ 2016-10-31  2:54 Guangwen Feng
  2016-10-31  2:54 ` [LTP] [PATCH 2/3] syscalls/umask02: " Guangwen Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Guangwen Feng @ 2016-10-31  2:54 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umask/umask01.c | 165 +++++-------------------------
 1 file changed, 28 insertions(+), 137 deletions(-)

diff --git a/testcases/kernel/syscalls/umask/umask01.c b/testcases/kernel/syscalls/umask/umask01.c
index 9677539..b2a09de 100644
--- a/testcases/kernel/syscalls/umask/umask01.c
+++ b/testcases/kernel/syscalls/umask/umask01.c
@@ -1,153 +1,44 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ *  Ported by William Roske and Dave Fenner
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * 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 would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ * This program is distributed in the hope that it would 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 the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * Basic test for umask(2).
  */
-/* $Id: umask01.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: umask01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for umask(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.) umask(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 umask(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
- *	umask(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
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "umask01";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-int main(int ac, char **av)
+static void verify_umask(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	TEST(umask(022));
 
-		tst_count = 0;
-
-		TEST(umask(022));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "umask(022) Failed, errno=%d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "umask(022) returned %ld",
-				 TEST_RETURN);
-		}
+	if (TEST_RETURN < 0) {
+		tst_res(TFAIL | TTERRNO, "umask(022) failed unexpectedly");
+		return;
 	}
-	tst_exit();
-}
 
-void setup(void)
-{
-	TEST_PAUSE;
+	tst_res(TPASS, "umask(022) returned %ld", TEST_RETURN);
 }
+
+static struct tst_test test = {
+	.tid = "umask01",
+	.test_all = verify_umask,
+};
-- 
1.8.4.2




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

* [LTP] [PATCH 2/3] syscalls/umask02: Cleanup && Convert to new API
  2016-10-31  2:54 [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Guangwen Feng
@ 2016-10-31  2:54 ` Guangwen Feng
  2016-10-31 11:35   ` Cyril Hrubis
  2016-10-31  2:54 ` [LTP] [PATCH 3/3] syscalls/umask03: " Guangwen Feng
  2016-10-31 11:26 ` [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Cyril Hrubis
  2 siblings, 1 reply; 11+ messages in thread
From: Guangwen Feng @ 2016-10-31  2:54 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umask/umask02.c | 143 +++++++++---------------------
 1 file changed, 41 insertions(+), 102 deletions(-)

diff --git a/testcases/kernel/syscalls/umask/umask02.c b/testcases/kernel/syscalls/umask/umask02.c
index 0ba797c..9ec94a0 100644
--- a/testcases/kernel/syscalls/umask/umask02.c
+++ b/testcases/kernel/syscalls/umask/umask02.c
@@ -1,118 +1,57 @@
 /*
- *
- *   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 John George
+ *
+ * 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 would 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 the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
- * NAME
- *	umask02.c
- *
- * DESCRIPTION
- *	Check that umask changes the mask, and that the previous
- *	value of the mask is returned correctly for each value.
- *
- * ALGORITHM
- *	For each mask value (9 bits) set mask, and check that the return
- *	corresponds to the previous value set.
- *
- * USAGE:  <for command-line>
- *	umask02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
+ * umask(2) changes the mask from 0000 to 0777, the previous value
+ * of the mask should be returned correctly for each value.
  */
 
+#include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include "test.h"
-
-char *TCID = "umask02";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-void setup(void);
-void cleanup(void);
-
-int main(int argc, char **argv)
+static void verify_umask(void)
 {
-	int lc;
-
-	int uret = 0, i, mskval = 0000;
-	int failcnt = 0;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	/* Check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+	int mskval = 0000;
+	int failflag = 0;
+
+	for (umask(mskval++); mskval < 01000; mskval++) {
+		TEST(umask(mskval));
+		if (TEST_RETURN < 0) {
+			tst_res(TFAIL | TTERRNO,
+				"umask(%o) failed unexpectedly", mskval);
+			return;
+		}
 
-		for (umask(++mskval), i = 1; mskval < 01000;
-		     uret = umask(++mskval), i++) {
-			if ((uret != mskval - 1) && (mskval != 0000)) {
-				failcnt = 1;
-				tst_resm(TFAIL, "umask(%d) returned bad mask "
-					 "value %d.", mskval, uret);
-			}
+		if (TEST_RETURN != mskval - 1) {
+			failflag = 1;
+			tst_res(TFAIL, "umask(%o) returned %ld, expected %d",
+				mskval, TEST_RETURN, mskval - 1);
 		}
-		if (!failcnt)
-			tst_resm(TPASS, "All umask values return correct "
-				 "values");
 	}
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
+	if (!failflag)
+		tst_res(TPASS, "All umask values returned correctly");
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tid = "umask02",
+	.test_all = verify_umask,
+};
-- 
1.8.4.2




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

* [LTP] [PATCH 3/3] syscalls/umask03: Cleanup && Convert to new API
  2016-10-31  2:54 [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Guangwen Feng
  2016-10-31  2:54 ` [LTP] [PATCH 2/3] syscalls/umask02: " Guangwen Feng
@ 2016-10-31  2:54 ` Guangwen Feng
  2016-10-31 11:40   ` Cyril Hrubis
  2016-10-31 11:26 ` [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Cyril Hrubis
  2 siblings, 1 reply; 11+ messages in thread
From: Guangwen Feng @ 2016-10-31  2:54 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/umask/umask03.c | 172 +++++++++---------------------
 1 file changed, 48 insertions(+), 124 deletions(-)

diff --git a/testcases/kernel/syscalls/umask/umask03.c b/testcases/kernel/syscalls/umask/umask03.c
index e10009c..30c28ca 100644
--- a/testcases/kernel/syscalls/umask/umask03.c
+++ b/testcases/kernel/syscalls/umask/umask03.c
@@ -1,155 +1,79 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by John George
  *
- *   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 would 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 the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
- * NAME
- *	umask03.c
- *
- * DESCRIPTION
- *	Check that umask changes the mask, and that the previous
- *	value of the mask is returned correctly for each value.
- *
- * ALGORITHM
- *	For each mask value (9 bits) set mask, and check that the return
- *	corresponds to the previous value set.
- *
- * USAGE:  <for command-line>
- *		umask03 [-c n] [-i n] [-I x] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
+ * umask(2) sets the mask from 0000 to 0777 while we create files,
+ * then the file mode should be correct for each creation mask.
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
+#include <errno.h>
 #include <stdio.h>
-#include "test.h"
 #include <sys/types.h>
 #include <sys/stat.h>
+#include "tst_test.h"
 
-char *TCID = "umask03";
-int TST_TOTAL = 1;
-
-char filname[40];
-
-void setup(void);
-void cleanup(void);
+static char filename[40];
 
-int main(int argc, char **argv)
+static void verify_umask(void)
 {
-	int lc;
-
 	struct stat statbuf;
-	int mskval = 0000;
-	int failcnt = 0;
-	int fildes, i;
+	int mskval;
+	int fd;
+	int failflag = 0;
 	unsigned low9mode;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	for (mskval = 0000; mskval < 01000; mskval++) {
+		TEST(umask(mskval));
+		if (TEST_RETURN < 0) {
+			tst_res(TFAIL | TTERRNO,
+				"umask(%o) failed unexpectedly", mskval);
+			return;
+		}
 
-	setup();		/* global setup */
+		fd = SAFE_CREAT(filename, 0777);
+		SAFE_CLOSE(fd);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		SAFE_STAT(filename, &statbuf);
 
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+		low9mode = statbuf.st_mode & 0777;
 
-		for (umask(mskval = 0077), i = 1; mskval < 01000;
-		     i++, umask(++mskval)) {
-			unlink(filname);
-			if ((fildes = creat(filname, 0777)) == -1) {
-				tst_resm(TBROK, "cannot create "
-					 "file with mskval 0%o %d",
-					 mskval, mskval);
-			} else {
-				if (fstat(fildes, &statbuf) != 0) {
-					tst_resm(TBROK, "cannot fstat file");
-				} else {
-					low9mode = statbuf.st_mode & 0777;
-					if (low9mode != (~mskval & 0777)) {
-						tst_resm(TFAIL,
-							 "got %o expected %o"
-							 "mask didnot take",
-							 low9mode,
-							 (~mskval & 0777));
-					}
-				}
-			}
-			close(fildes);
+		if (low9mode != (~mskval & 0777)) {
+			failflag = 1;
+			tst_res(TFAIL, "File mode got %o, expected %o",
+				low9mode, ~mskval & 0777);
 		}
-		if (!failcnt)
-			tst_resm(TPASS, "umask correctly returns the "
-				 "previous value for all masks");
+
+		SAFE_UNLINK(filename);
 	}
-	cleanup();
-	tst_exit();
 
+	if (!failflag)
+		tst_res(TPASS, "All files' mode created correctly");
 }
 
-/*
- * setup
- *	performs all ONE TIME setup for this test
- */
 void setup(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	/* make temp dir and cd to it */
-	tst_tmpdir();
-
-	sprintf(filname, "umask2.%d", getpid());
+	sprintf(filename, "umask03.%d", getpid());
 }
 
-/*
- * cleanup
- *	performs all ONE TIME cleanup for this test@completion or
- *	premature exit
- */
-void cleanup(void)
-{
-
-	/*
-	 * cleanup the temporary files and the temporary directory
-	 */
-	unlink(filname);
-	tst_rmdir();
-
-	/*
-	 * exit with return code appropriate for results
-	 */
-
-}
+static struct tst_test test = {
+	.tid = "umask03",
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.test_all = verify_umask,
+};
-- 
1.8.4.2




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

* [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API
  2016-10-31  2:54 [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Guangwen Feng
  2016-10-31  2:54 ` [LTP] [PATCH 2/3] syscalls/umask02: " Guangwen Feng
  2016-10-31  2:54 ` [LTP] [PATCH 3/3] syscalls/umask03: " Guangwen Feng
@ 2016-10-31 11:26 ` Cyril Hrubis
  2 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2016-10-31 11:26 UTC (permalink / raw)
  To: ltp

Hi!
I guess that this test should be just removed since umask() cannot fail
at all.

To cite the manual page:

...

RETURN VALUE
       This system call always succeeds and the previous value of the
       mask is returned.

...


-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/3] syscalls/umask02: Cleanup && Convert to new API
  2016-10-31  2:54 ` [LTP] [PATCH 2/3] syscalls/umask02: " Guangwen Feng
@ 2016-10-31 11:35   ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2016-10-31 11:35 UTC (permalink / raw)
  To: ltp

Hi!
> +	for (umask(mskval++); mskval < 01000; mskval++) {
> +		TEST(umask(mskval));
> +		if (TEST_RETURN < 0) {
> +			tst_res(TFAIL | TTERRNO,
> +				"umask(%o) failed unexpectedly", mskval);
> +			return;
> +		}

Again umask() cannot fail this way. I guess that what we can do here is
to check that the return value is in a valid range, i.e.

if (TEST_RETURN < 0 || TEST_RETURN > 0777)
	tst_brk(TFAIL, "umask result outside range %i", TEST_RETURN);

> -		for (umask(++mskval), i = 1; mskval < 01000;
> -		     uret = umask(++mskval), i++) {
> -			if ((uret != mskval - 1) && (mskval != 0000)) {
> -				failcnt = 1;
> -				tst_resm(TFAIL, "umask(%d) returned bad mask "
> -					 "value %d.", mskval, uret);
> -			}
> +		if (TEST_RETURN != mskval - 1) {
> +			failflag = 1;
> +			tst_res(TFAIL, "umask(%o) returned %ld, expected %d",
> +				mskval, TEST_RETURN, mskval - 1);
>  		}
> -		if (!failcnt)
> -			tst_resm(TPASS, "All umask values return correct "
> -				 "values");
>  	}
> -	cleanup();
> -	tst_exit();
> -
> -}

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 3/3] syscalls/umask03: Cleanup && Convert to new API
  2016-10-31  2:54 ` [LTP] [PATCH 3/3] syscalls/umask03: " Guangwen Feng
@ 2016-10-31 11:40   ` Cyril Hrubis
  2016-11-01  4:26     ` Guangwen Feng
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2016-10-31 11:40 UTC (permalink / raw)
  To: ltp

On Mon, Oct 31, 2016 at 10:54:38AM +0800, Guangwen Feng wrote:
> Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/umask/umask03.c | 172 +++++++++---------------------
>  1 file changed, 48 insertions(+), 124 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/umask/umask03.c b/testcases/kernel/syscalls/umask/umask03.c
> index e10009c..30c28ca 100644
> --- a/testcases/kernel/syscalls/umask/umask03.c
> +++ b/testcases/kernel/syscalls/umask/umask03.c
> @@ -1,155 +1,79 @@
>  /*
> + * Copyright (c) International Business Machines  Corp., 2001
> + *  07/2001 Ported by John George
>   *
> - *   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 would 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 the Free Software Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>   */
>  
>  /*
> - * NAME
> - *	umask03.c
> - *
> - * DESCRIPTION
> - *	Check that umask changes the mask, and that the previous
> - *	value of the mask is returned correctly for each value.
> - *
> - * ALGORITHM
> - *	For each mask value (9 bits) set mask, and check that the return
> - *	corresponds to the previous value set.
> - *
> - * USAGE:  <for command-line>
> - *		umask03 [-c n] [-i n] [-I x] [-P x] [-t]
> - *		where,  -c n : Run n copies concurrently.
> - *			-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 John George
> - *		-Ported
> - *
> - * Restrictions
> - *	None
> + * umask(2) sets the mask from 0000 to 0777 while we create files,
> + * then the file mode should be correct for each creation mask.
>   */
>  
> -#include <sys/types.h>
> -#include <sys/stat.h>
> -#include <fcntl.h>
> +#include <errno.h>
>  #include <stdio.h>
> -#include "test.h"
>  #include <sys/types.h>
>  #include <sys/stat.h>
> +#include "tst_test.h"
>  
> -char *TCID = "umask03";
> -int TST_TOTAL = 1;
> -
> -char filname[40];
> -
> -void setup(void);
> -void cleanup(void);
> +static char filename[40];
>  
> -int main(int argc, char **argv)
> +static void verify_umask(void)
>  {
> -	int lc;
> -
>  	struct stat statbuf;
> -	int mskval = 0000;
> -	int failcnt = 0;
> -	int fildes, i;
> +	int mskval;
> +	int fd;
> +	int failflag = 0;
>  	unsigned low9mode;
>  
> -	tst_parse_opts(argc, argv, NULL, NULL);
> +	for (mskval = 0000; mskval < 01000; mskval++) {
> +		TEST(umask(mskval));
> +		if (TEST_RETURN < 0) {
> +			tst_res(TFAIL | TTERRNO,
> +				"umask(%o) failed unexpectedly", mskval);
> +			return;
> +		}

Here as well.

> -	setup();		/* global setup */
> +		fd = SAFE_CREAT(filename, 0777);
> +		SAFE_CLOSE(fd);
>  
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		SAFE_STAT(filename, &statbuf);
>  
> -		/* reset tst_count in case we are looping */
> -		tst_count = 0;
> +		low9mode = statbuf.st_mode & 0777;
>  
> -		for (umask(mskval = 0077), i = 1; mskval < 01000;
> -		     i++, umask(++mskval)) {
> -			unlink(filname);
> -			if ((fildes = creat(filname, 0777)) == -1) {
> -				tst_resm(TBROK, "cannot create "
> -					 "file with mskval 0%o %d",
> -					 mskval, mskval);
> -			} else {
> -				if (fstat(fildes, &statbuf) != 0) {
> -					tst_resm(TBROK, "cannot fstat file");
> -				} else {
> -					low9mode = statbuf.st_mode & 0777;
> -					if (low9mode != (~mskval & 0777)) {
> -						tst_resm(TFAIL,
> -							 "got %o expected %o"
> -							 "mask didnot take",
> -							 low9mode,
> -							 (~mskval & 0777));
> -					}
> -				}

Hmm, so this test is just the same as umask02 but tries to create the
file as well.

What about we remove umask01.c and umask02.c and rename umask03.c to
umask01.c?

It's not like umask01.c or umask02.c adds any more value since umask03.c
is superset of these.

>  
> -/*
> - * setup
> - *	performs all ONE TIME setup for this test
> - */
>  void setup(void)
>  {
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	/* Pause if that option was specified
> -	 * TEST_PAUSE contains the code to fork the test with the -i option.
> -	 * You want to make sure you do this before you create your temporary
> -	 * directory.
> -	 */
> -	TEST_PAUSE;
> -
> -	/* make temp dir and cd to it */
> -	tst_tmpdir();
> -
> -	sprintf(filname, "umask2.%d", getpid());
> +	sprintf(filename, "umask03.%d", getpid());

The test runs in unique temporary directory, there is no need for trying
to create unique filename.

>  }
>  
> -/*
> - * cleanup
> - *	performs all ONE TIME cleanup for this test at completion or
> - *	premature exit
> - */
> -void cleanup(void)
> -{
> -
> -	/*
> -	 * cleanup the temporary files and the temporary directory
> -	 */
> -	unlink(filname);
> -	tst_rmdir();
> -
> -	/*
> -	 * exit with return code appropriate for results
> -	 */
> -
> -}
> +static struct tst_test test = {
> +	.tid = "umask03",
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.test_all = verify_umask,
> +};
> -- 
> 1.8.4.2
> 
> 
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 3/3] syscalls/umask03: Cleanup && Convert to new API
  2016-10-31 11:40   ` Cyril Hrubis
@ 2016-11-01  4:26     ` Guangwen Feng
  2016-11-01 15:05       ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Guangwen Feng @ 2016-11-01  4:26 UTC (permalink / raw)
  To: ltp

Hi!

Thanks for your review.

On 10/31/2016 07:40 PM, Cyril Hrubis wrote:
> On Mon, Oct 31, 2016 at 10:54:38AM +0800, Guangwen Feng wrote:
>> Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
>> ---
>>  testcases/kernel/syscalls/umask/umask03.c | 172 +++++++++---------------------
>>  1 file changed, 48 insertions(+), 124 deletions(-)
>>
>> diff --git a/testcases/kernel/syscalls/umask/umask03.c b/testcases/kernel/syscalls/umask/umask03.c
>> index e10009c..30c28ca 100644
>> --- a/testcases/kernel/syscalls/umask/umask03.c
>> +++ b/testcases/kernel/syscalls/umask/umask03.c
>> @@ -1,155 +1,79 @@
>>  /*
>> + * Copyright (c) International Business Machines  Corp., 2001
>> + *  07/2001 Ported by John George
>>   *
>> - *   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 would 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 the Free Software Foundation,
>> + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
>>   */
>>  
>>  /*
>> - * NAME
>> - *	umask03.c
>> - *
>> - * DESCRIPTION
>> - *	Check that umask changes the mask, and that the previous
>> - *	value of the mask is returned correctly for each value.
>> - *
>> - * ALGORITHM
>> - *	For each mask value (9 bits) set mask, and check that the return
>> - *	corresponds to the previous value set.
>> - *
>> - * USAGE:  <for command-line>
>> - *		umask03 [-c n] [-i n] [-I x] [-P x] [-t]
>> - *		where,  -c n : Run n copies concurrently.
>> - *			-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 John George
>> - *		-Ported
>> - *
>> - * Restrictions
>> - *	None
>> + * umask(2) sets the mask from 0000 to 0777 while we create files,
>> + * then the file mode should be correct for each creation mask.
>>   */
>>  
>> -#include <sys/types.h>
>> -#include <sys/stat.h>
>> -#include <fcntl.h>
>> +#include <errno.h>
>>  #include <stdio.h>
>> -#include "test.h"
>>  #include <sys/types.h>
>>  #include <sys/stat.h>
>> +#include "tst_test.h"
>>  
>> -char *TCID = "umask03";
>> -int TST_TOTAL = 1;
>> -
>> -char filname[40];
>> -
>> -void setup(void);
>> -void cleanup(void);
>> +static char filename[40];
>>  
>> -int main(int argc, char **argv)
>> +static void verify_umask(void)
>>  {
>> -	int lc;
>> -
>>  	struct stat statbuf;
>> -	int mskval = 0000;
>> -	int failcnt = 0;
>> -	int fildes, i;
>> +	int mskval;
>> +	int fd;
>> +	int failflag = 0;
>>  	unsigned low9mode;
>>  
>> -	tst_parse_opts(argc, argv, NULL, NULL);
>> +	for (mskval = 0000; mskval < 01000; mskval++) {
>> +		TEST(umask(mskval));
>> +		if (TEST_RETURN < 0) {
>> +			tst_res(TFAIL | TTERRNO,
>> +				"umask(%o) failed unexpectedly", mskval);
>> +			return;
>> +		}
> 
> Here as well.
> 
>> -	setup();		/* global setup */
>> +		fd = SAFE_CREAT(filename, 0777);
>> +		SAFE_CLOSE(fd);
>>  
>> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
>> +		SAFE_STAT(filename, &statbuf);
>>  
>> -		/* reset tst_count in case we are looping */
>> -		tst_count = 0;
>> +		low9mode = statbuf.st_mode & 0777;
>>  
>> -		for (umask(mskval = 0077), i = 1; mskval < 01000;
>> -		     i++, umask(++mskval)) {
>> -			unlink(filname);
>> -			if ((fildes = creat(filname, 0777)) == -1) {
>> -				tst_resm(TBROK, "cannot create "
>> -					 "file with mskval 0%o %d",
>> -					 mskval, mskval);
>> -			} else {
>> -				if (fstat(fildes, &statbuf) != 0) {
>> -					tst_resm(TBROK, "cannot fstat file");
>> -				} else {
>> -					low9mode = statbuf.st_mode & 0777;
>> -					if (low9mode != (~mskval & 0777)) {
>> -						tst_resm(TFAIL,
>> -							 "got %o expected %o"
>> -							 "mask didnot take",
>> -							 low9mode,
>> -							 (~mskval & 0777));
>> -					}
>> -				}
> 
> Hmm, so this test is just the same as umask02 but tries to create the
> file as well.
> 
> What about we remove umask01.c and umask02.c and rename umask03.c to
> umask01.c?
> 
> It's not like umask01.c or umask02.c adds any more value since umask03.c
> is superset of these.
> 

I think it's a little bit different between umask02 and umask03, manual page
says that umask(2) returns the previous value of the mask, and this is only
checked in umask02.

So what about we just remove umask01.c and rename umask02.c and umask03.c to
umask01.c and umask02.c?

Best Regards,
Guangwen Feng

>>  
>> -/*
>> - * setup
>> - *	performs all ONE TIME setup for this test
>> - */
>>  void setup(void)
>>  {
>> -
>> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
>> -
>> -	/* Pause if that option was specified
>> -	 * TEST_PAUSE contains the code to fork the test with the -i option.
>> -	 * You want to make sure you do this before you create your temporary
>> -	 * directory.
>> -	 */
>> -	TEST_PAUSE;
>> -
>> -	/* make temp dir and cd to it */
>> -	tst_tmpdir();
>> -
>> -	sprintf(filname, "umask2.%d", getpid());
>> +	sprintf(filename, "umask03.%d", getpid());
> 
> The test runs in unique temporary directory, there is no need for trying
> to create unique filename.
> 
>>  }
>>  
>> -/*
>> - * cleanup
>> - *	performs all ONE TIME cleanup for this test at completion or
>> - *	premature exit
>> - */
>> -void cleanup(void)
>> -{
>> -
>> -	/*
>> -	 * cleanup the temporary files and the temporary directory
>> -	 */
>> -	unlink(filname);
>> -	tst_rmdir();
>> -
>> -	/*
>> -	 * exit with return code appropriate for results
>> -	 */
>> -
>> -}
>> +static struct tst_test test = {
>> +	.tid = "umask03",
>> +	.needs_tmpdir = 1,
>> +	.setup = setup,
>> +	.test_all = verify_umask,
>> +};
>> -- 
>> 1.8.4.2
>>
>>
>>
>>
>> -- 
>> Mailing list info: https://lists.linux.it/listinfo/ltp
> 



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

* [LTP] [PATCH 3/3] syscalls/umask03: Cleanup && Convert to new API
  2016-11-01  4:26     ` Guangwen Feng
@ 2016-11-01 15:05       ` Cyril Hrubis
  2016-11-02  2:42         ` Guangwen Feng
  0 siblings, 1 reply; 11+ messages in thread
From: Cyril Hrubis @ 2016-11-01 15:05 UTC (permalink / raw)
  To: ltp

Hi!
> > Hmm, so this test is just the same as umask02 but tries to create the
> > file as well.
> > 
> > What about we remove umask01.c and umask02.c and rename umask03.c to
> > umask01.c?
> > 
> > It's not like umask01.c or umask02.c adds any more value since umask03.c
> > is superset of these.
> > 
> 
> I think it's a little bit different between umask02 and umask03, manual page
> says that umask(2) returns the previous value of the mask, and this is only
> checked in umask02.
> 
> So what about we just remove umask01.c and rename umask02.c and umask03.c to
> umask01.c and umask02.c?

Hmm, right, the umask03 is not checking the return value. But still,
it's trivial enough to both check the return value and to try to create
the file in one test. There is no real need to have two when thing could
be easily done in just one.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 3/3] syscalls/umask03: Cleanup && Convert to new API
  2016-11-01 15:05       ` Cyril Hrubis
@ 2016-11-02  2:42         ` Guangwen Feng
  2016-11-02  7:14           ` [LTP] [PATCH v2] syscalls/umask01: Cleanup && Use the new API && Rename Guangwen Feng
  0 siblings, 1 reply; 11+ messages in thread
From: Guangwen Feng @ 2016-11-02  2:42 UTC (permalink / raw)
  To: ltp

Hi!

On 11/01/2016 11:05 PM, Cyril Hrubis wrote:
> Hi!
>>> Hmm, so this test is just the same as umask02 but tries to create the
>>> file as well.
>>>
>>> What about we remove umask01.c and umask02.c and rename umask03.c to
>>> umask01.c?
>>>
>>> It's not like umask01.c or umask02.c adds any more value since umask03.c
>>> is superset of these.
>>>
>>
>> I think it's a little bit different between umask02 and umask03, manual page
>> says that umask(2) returns the previous value of the mask, and this is only
>> checked in umask02.
>>
>> So what about we just remove umask01.c and rename umask02.c and umask03.c to
>> umask01.c and umask02.c?
> 
> Hmm, right, the umask03 is not checking the return value. But still,
> it's trivial enough to both check the return value and to try to create
> the file in one test. There is no real need to have two when thing could
> be easily done in just one.

OK, I see, I will rewrite the patch as you said, thanks.

Best Regards,
Guangwen Feng



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

* [LTP] [PATCH v2] syscalls/umask01: Cleanup && Use the new API && Rename
  2016-11-02  2:42         ` Guangwen Feng
@ 2016-11-02  7:14           ` Guangwen Feng
  2016-11-02 11:13             ` Cyril Hrubis
  0 siblings, 1 reply; 11+ messages in thread
From: Guangwen Feng @ 2016-11-02  7:14 UTC (permalink / raw)
  To: ltp

Cleanup umask03 and convert it to new API, then remove
umask01 and umask02, rename the new umask03 to umask01.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/ltplite                           |   2 -
 runtest/stress.part3                      |   2 -
 runtest/syscalls                          |   2 -
 testcases/kernel/syscalls/.gitignore      |   2 -
 testcases/kernel/syscalls/umask/umask01.c | 194 +++++++++---------------------
 testcases/kernel/syscalls/umask/umask02.c | 118 ------------------
 testcases/kernel/syscalls/umask/umask03.c | 155 ------------------------
 7 files changed, 59 insertions(+), 416 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/umask/umask02.c
 delete mode 100644 testcases/kernel/syscalls/umask/umask03.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 338d6eb..4ad77f3 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -972,8 +972,6 @@ truncate03 truncate03
 # ulimit01 ulimit01
 
 umask01 umask01
-umask02 umask02
-umask03 umask03
 
 uname01 uname01
 uname02 uname02
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 8abed95..6b48316 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -849,8 +849,6 @@ truncate03 truncate03
 # ulimit01 ulimit01
 
 umask01 umask01
-umask02 umask02
-umask03 umask03
 
 uname01 uname01
 uname02 uname02
diff --git a/runtest/syscalls b/runtest/syscalls
index 7c84296..1bd6252 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1334,8 +1334,6 @@ truncate03_64 truncate03_64
 ulimit01 ulimit01
 
 umask01 umask01
-umask02 umask02
-umask03 umask03
 
 uname01 uname01
 uname02 uname02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index f53cc05..77d150a 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1040,8 +1040,6 @@
 /truncate/truncate03_64
 /ulimit/ulimit01
 /umask/umask01
-/umask/umask02
-/umask/umask03
 /umount/umount01
 /umount/umount02
 /umount/umount03
diff --git a/testcases/kernel/syscalls/umask/umask01.c b/testcases/kernel/syscalls/umask/umask01.c
index 9677539..7d9334e 100644
--- a/testcases/kernel/syscalls/umask/umask01.c
+++ b/testcases/kernel/syscalls/umask/umask01.c
@@ -1,153 +1,77 @@
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by John George
+ *
+ * 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 would 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 the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+/*
+ * umask(2) sets the mask from 0000 to 0777 while we create files,
+ * the previous value of the mask should be returned correctly,
+ * and the file mode should be correct for each creation mask.
  */
-/* $Id: umask01.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: umask01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for umask(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.) umask(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 umask(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
- *	umask(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
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
-#include <string.h>
-#include <signal.h>
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "umask01";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-int main(int ac, char **av)
+static void verify_umask(void)
 {
-	int lc;
+	struct stat statbuf;
+	int mskval;
+	int fd;
+	int failflag = 0;
+	unsigned low9mode;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	for (mskval = 0000; mskval < 01000; mskval++) {
+		TEST(umask(mskval));
+		if (TEST_RETURN < 0 || TEST_RETURN > 0777) {
+			tst_brk(TFAIL, "umask(%o) result outside range %ld",
+				mskval, TEST_RETURN);
+		}
 
-	setup();
+		if (mskval > 0000 && TEST_RETURN != mskval - 1) {
+			failflag = 1;
+			tst_res(TFAIL, "umask(%o) returned %ld, expected %d",
+				mskval, TEST_RETURN, mskval - 1);
+		}
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		fd = SAFE_CREAT("testfile", 0777);
+		SAFE_CLOSE(fd);
 
-		tst_count = 0;
+		SAFE_STAT("testfile", &statbuf);
 
-		TEST(umask(022));
+		low9mode = statbuf.st_mode & 0777;
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "umask(022) Failed, errno=%d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "umask(022) returned %ld",
-				 TEST_RETURN);
+		if (low9mode != (~mskval & 0777)) {
+			failflag = 1;
+			tst_res(TFAIL, "File mode got %o, expected %o",
+				low9mode, ~mskval & 0777);
 		}
+
+		SAFE_UNLINK("testfile");
 	}
-	tst_exit();
-}
 
-void setup(void)
-{
-	TEST_PAUSE;
+	if (!failflag)
+		tst_res(TPASS, "All files' mode created correctly");
 }
+
+static struct tst_test test = {
+	.tid = "umask01",
+	.test_all = verify_umask,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/umask/umask02.c b/testcases/kernel/syscalls/umask/umask02.c
deleted file mode 100644
index 0ba797c..0000000
--- a/testcases/kernel/syscalls/umask/umask02.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- *
- *   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
- */
-
-/*
- * NAME
- *	umask02.c
- *
- * DESCRIPTION
- *	Check that umask changes the mask, and that the previous
- *	value of the mask is returned correctly for each value.
- *
- * ALGORITHM
- *	For each mask value (9 bits) set mask, and check that the return
- *	corresponds to the previous value set.
- *
- * USAGE:  <for command-line>
- *	umask02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include "test.h"
-
-char *TCID = "umask02";
-int TST_TOTAL = 1;
-
-void setup(void);
-void cleanup(void);
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	int uret = 0, i, mskval = 0000;
-	int failcnt = 0;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	/* Check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (umask(++mskval), i = 1; mskval < 01000;
-		     uret = umask(++mskval), i++) {
-			if ((uret != mskval - 1) && (mskval != 0000)) {
-				failcnt = 1;
-				tst_resm(TFAIL, "umask(%d) returned bad mask "
-					 "value %d.", mskval, uret);
-			}
-		}
-		if (!failcnt)
-			tst_resm(TPASS, "All umask values return correct "
-				 "values");
-	}
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
diff --git a/testcases/kernel/syscalls/umask/umask03.c b/testcases/kernel/syscalls/umask/umask03.c
deleted file mode 100644
index e10009c..0000000
--- a/testcases/kernel/syscalls/umask/umask03.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- *
- *   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
- */
-
-/*
- * NAME
- *	umask03.c
- *
- * DESCRIPTION
- *	Check that umask changes the mask, and that the previous
- *	value of the mask is returned correctly for each value.
- *
- * ALGORITHM
- *	For each mask value (9 bits) set mask, and check that the return
- *	corresponds to the previous value set.
- *
- * USAGE:  <for command-line>
- *		umask03 [-c n] [-i n] [-I x] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-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 John George
- *		-Ported
- *
- * Restrictions
- *	None
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include "test.h"
-#include <sys/types.h>
-#include <sys/stat.h>
-
-char *TCID = "umask03";
-int TST_TOTAL = 1;
-
-char filname[40];
-
-void setup(void);
-void cleanup(void);
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	struct stat statbuf;
-	int mskval = 0000;
-	int failcnt = 0;
-	int fildes, i;
-	unsigned low9mode;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();		/* global setup */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (umask(mskval = 0077), i = 1; mskval < 01000;
-		     i++, umask(++mskval)) {
-			unlink(filname);
-			if ((fildes = creat(filname, 0777)) == -1) {
-				tst_resm(TBROK, "cannot create "
-					 "file with mskval 0%o %d",
-					 mskval, mskval);
-			} else {
-				if (fstat(fildes, &statbuf) != 0) {
-					tst_resm(TBROK, "cannot fstat file");
-				} else {
-					low9mode = statbuf.st_mode & 0777;
-					if (low9mode != (~mskval & 0777)) {
-						tst_resm(TFAIL,
-							 "got %o expected %o"
-							 "mask didnot take",
-							 low9mode,
-							 (~mskval & 0777));
-					}
-				}
-			}
-			close(fildes);
-		}
-		if (!failcnt)
-			tst_resm(TPASS, "umask correctly returns the "
-				 "previous value for all masks");
-	}
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	/* make temp dir and cd to it */
-	tst_tmpdir();
-
-	sprintf(filname, "umask2.%d", getpid());
-}
-
-/*
- * cleanup
- *	performs all ONE TIME cleanup for this test@completion or
- *	premature exit
- */
-void cleanup(void)
-{
-
-	/*
-	 * cleanup the temporary files and the temporary directory
-	 */
-	unlink(filname);
-	tst_rmdir();
-
-	/*
-	 * exit with return code appropriate for results
-	 */
-
-}
-- 
1.8.4.2




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

* [LTP] [PATCH v2] syscalls/umask01: Cleanup && Use the new API && Rename
  2016-11-02  7:14           ` [LTP] [PATCH v2] syscalls/umask01: Cleanup && Use the new API && Rename Guangwen Feng
@ 2016-11-02 11:13             ` Cyril Hrubis
  0 siblings, 0 replies; 11+ messages in thread
From: Cyril Hrubis @ 2016-11-02 11:13 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with small change in the TPASS message, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2016-11-02 11:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-31  2:54 [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Guangwen Feng
2016-10-31  2:54 ` [LTP] [PATCH 2/3] syscalls/umask02: " Guangwen Feng
2016-10-31 11:35   ` Cyril Hrubis
2016-10-31  2:54 ` [LTP] [PATCH 3/3] syscalls/umask03: " Guangwen Feng
2016-10-31 11:40   ` Cyril Hrubis
2016-11-01  4:26     ` Guangwen Feng
2016-11-01 15:05       ` Cyril Hrubis
2016-11-02  2:42         ` Guangwen Feng
2016-11-02  7:14           ` [LTP] [PATCH v2] syscalls/umask01: Cleanup && Use the new API && Rename Guangwen Feng
2016-11-02 11:13             ` Cyril Hrubis
2016-10-31 11:26 ` [LTP] [PATCH 1/3] syscalls/umask01: Cleanup && Convert to new API Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox