All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API
@ 2018-02-09  7:56 Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
                   ` (3 more replies)
  0 siblings, 4 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-09  7:56 UTC (permalink / raw)
  To: ltp

Make sure get_high_address() can be used by new API.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/old/test.h             |  4 +---
 include/tst_get_high_address.h | 31 +++++++++++++++++++++++++++++++
 include/tst_test.h             |  1 +
 lib/get_high_address.c         |  1 +
 4 files changed, 34 insertions(+), 3 deletions(-)
 create mode 100644 include/tst_get_high_address.h

diff --git a/include/old/test.h b/include/old/test.h
index 137ebb1..21f7db9 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -63,6 +63,7 @@
 #include "old_device.h"
 #include "old_tmpdir.h"
 #include "tst_minmax.h"
+#include "tst_get_high_address.h"
 
 /*
  * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;
 /* lib/tst_sig.c */
 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
 
-/* lib/get_high_address.c */
-char *get_high_address(void);
-
 /* lib/self_exec.c */
 void maybe_run_child(void (*child)(), const char *fmt, ...);
 int self_exec(const char *argv0, const char *fmt, ...);
diff --git a/include/tst_get_high_address.h b/include/tst_get_high_address.h
new file mode 100644
index 0000000..84e0257
--- /dev/null
+++ b/include/tst_get_high_address.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+#ifndef TST_GET_HIGH_ADDRESS_H__
+#define TST_GET_HIGH_ADDRESS_H__
+
+/* Functions from lib/get_high_address.c */
+
+char *get_high_address(void);
+
+#endif	/* TST_GET_HIGH_ADDRESS_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index eaf7a1f..c539d38 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -40,6 +40,7 @@
 #include "tst_clone.h"
 #include "tst_kernel.h"
 #include "tst_minmax.h"
+#include "tst_get_high_address.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/get_high_address.c b/lib/get_high_address.c
index eed9cf1..0e1e225 100644
--- a/lib/get_high_address.c
+++ b/lib/get_high_address.c
@@ -33,6 +33,7 @@
  */
 
 #include <unistd.h>
+#include "tst_get_high_address.h"
 
 char *get_high_address(void)
 {
-- 
1.8.3.1




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

* [LTP] [PATCH 2/4] syscalls/unlink05, 06: Cleanup && Convert to new API
  2018-02-09  7:56 [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API Xiao Yang
@ 2018-02-09  7:56 ` Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 3/4] syscalls/unlink07: " Xiao Yang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-09  7:56 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Merge unlink06 into unlink05

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/quickhit                            |   2 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/unlink/unlink05.c | 216 +++++++---------------------
 testcases/kernel/syscalls/unlink/unlink06.c | 215 ---------------------------
 7 files changed, 53 insertions(+), 384 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 5418495..986e5e7 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -965,7 +965,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/quickhit b/runtest/quickhit
index 2a42769..8264b22 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -255,8 +255,6 @@ uname01 uname01
 # Basic test for uname(2)
 unlink05 unlink05
 # Basic test for unlink(2)
-unlink06 unlink06
-# unlink(2) of a FIFO
 unlink07 unlink07
 # unlink(2) negative testcases
 unlink08 unlink08
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 242b696..889f0d8 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -841,7 +841,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 2a4fad0..d7aab87 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1384,7 +1384,6 @@ cve-2012-0957 cve-2012-0957
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 67211ca..31b717b 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1083,7 +1083,6 @@
 /uname/uname02
 /uname/uname03
 /unlink/unlink05
-/unlink/unlink06
 /unlink/unlink07
 /unlink/unlink08
 /unlinkat/unlinkat01
diff --git a/testcases/kernel/syscalls/unlink/unlink05.c b/testcases/kernel/syscalls/unlink/unlink05.c
index aa49316..2aca611 100644
--- a/testcases/kernel/syscalls/unlink/unlink05.c
+++ b/testcases/kernel/syscalls/unlink/unlink05.c
@@ -28,182 +28,72 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink05.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for unlink(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.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
 
-void setup();
-void cleanup();
-void create_file();
-
-char *TCID = "unlink05";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
+/*
+ * Description:
+ * The testcase checks the basic functionality of the unlink(2).
+ * 1) unlink() can delete regular file successfully.
+ * 2) unlink() can delete fifo file successfully.
+ */
 
-int main(int ac, char **av)
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+
+static void file_create(char *);
+static void fifo_create(char *);
+
+static struct test_case_t {
+	void (*setupfunc)(char *);
+	char *desc;
+} tcases[] = {
+	{file_create, "file"},
+	{fifo_create, "fifo"},
+};
+
+static void file_create(char *name)
 {
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	int fd;
 
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "unlink(%s) returned %ld",
-				 fname, TEST_RETURN);
-			/* recreate file for next loop */
-			create_file();
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	sprintf(name, "tfile_%d", getpid());
+	fd = SAFE_OPEN(name, O_RDWR | O_CREAT, 0777);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void fifo_create(char *name)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	create_file();
+	sprintf(name, "tfifo_%d", getpid());
+	SAFE_MKFIFO(name, 0777);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void verify_unlink(unsigned int n)
 {
+	char fname[255];
+	struct test_case_t *tc = &tcases[n];
 
-	tst_rmdir();
+	tc->setupfunc(fname);
 
-}
-
-void create_file(void)
-{
-	sprintf(fname, "tfile_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+	TEST(unlink(fname));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "unlink(%s) failed", tc->desc);
+		return;
 	}
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+
+	if (!access(fname, F_OK)) {
+		tst_res(TFAIL, "unlink(%s) succeeded, but %s still existed",
+			tc->desc, tc->desc);
+		return;
 	}
+
+	tst_res(TPASS, "unlink(%s) succeeded", tc->desc);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
diff --git a/testcases/kernel/syscalls/unlink/unlink06.c b/testcases/kernel/syscalls/unlink/unlink06.c
deleted file mode 100644
index 0e38480..0000000
--- a/testcases/kernel/syscalls/unlink/unlink06.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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/
- *
- */
-/* $Id: unlink06.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink06
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) of a FIFO
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void create_file();
-void cleanup();
-
-char *TCID = "unlink06";
-int TST_TOTAL = 1;
-
-char Fname[255];
-
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		create_file();
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(Fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 Fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			if (access(Fname, F_OK) != -1) {
-				tst_resm(TFAIL,
-					 "unlink(%s) returned %ld, but access says file still exists.",
-					 Fname, TEST_RETURN);
-			} else {
-				tst_resm(TPASS, "unlink(%s) returned %ld",
-					 Fname, TEST_RETURN);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(Fname, "fifo_unlink%d", getpid());
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-void create_file(void)
-{
-	SAFE_MKFIFO(cleanup, Fname, 0777);
-}
-- 
1.8.3.1




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

* [LTP] [PATCH 3/4] syscalls/unlink07: Cleanup && Convert to new API
  2018-02-09  7:56 [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
@ 2018-02-09  7:56 ` Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 4/4] syscalls/unlink08: " Xiao Yang
  2018-02-12 16:22 ` [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for " Cyril Hrubis
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-09  7:56 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove unused code

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink07.c | 306 +++++-----------------------
 1 file changed, 52 insertions(+), 254 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 66e4db8..72a21c6 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -28,281 +28,79 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink07
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-8) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns ENOENT if file doesn't exist.
+ * 2) unlink() returns ENOENT if path is empty.
+ * 3) unlink() returns ENOENT if path contains a non-existent file.
+ * 4) unlink() returns EFAULT if address beyond address space.
+ * 5) unlink() returns ENOTDIR if path contains a regular file.
+ * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+ * 7) unlink() returns EFAULT if address is negative.
+ */
+
 #include <errno.h>
 #include <string.h>
-#include <signal.h>
 #include <unistd.h>
-#include <sys/param.h>		/* for PATH_MAX */
-#include "test.h"
-
-void setup();
-void cleanup();
+#include <sys/param.h>	/* for PATH_MAX */
+#include "tst_test.h"
 
-extern char *get_high_address();
+static char longpathname[PATH_MAX + 2];
 
-char *TCID = "unlink07";
-int TST_TOTAL = 6;
-
-char *bad_addr = 0;
-
-int longpath_setup();
-int no_setup();
-int filepath_setup();
-char Longpathname[PATH_MAX + 2];
-char High_address[64];
-
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{
-	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
-	"", "path is empty string", ENOENT, no_setup}, {
-	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
-	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
-	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	(char *)-1, "negative address", EFAULT, no_setup}, {
-	NULL, NULL, 0, no_setup}
+} tcases[] = {
+	{"nonexistfile", "non-existent file", ENOENT},
+	{"", "path is empty string", ENOENT},
+	{"nefile/file", "path contains a non-existent file", ENOENT},
+	{NULL, "address beyond address space", EFAULT},
+	{"file/file", "path contains a regular file", ENOTDIR},
+	{longpathname, "pathname too long", ENAMETOOLONG},
+	{(char *) -1, "negative address", EFAULT},
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-#if !defined(UCLINUX)
-			if (fname == High_address)
-				fname = get_high_address();
-#endif
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO ==
-				    Test_cases[ind].exp_errno)
-					tst_resm(TPASS,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				else
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-						 desc, TEST_ERRNO,
-						 Test_cases
-						 [ind].exp_errno);
-			} else {
-				tst_resm(TFAIL,
-					 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-					 desc, TEST_RETURN,
-					 Test_cases[ind].exp_errno);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void verify_unlink(unsigned int n)
 {
-	int ind;
+	struct test_case_t *tc = &tcases[n];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	if (!tc->name)
+		tc->name = get_high_address();
 
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
-	Test_cases[7].pathname = bad_addr;
 
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		Test_cases[ind].setupfunc();
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(void)
-{
-	return 0;
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int longpath_setup(void)
+static void setup(void)
 {
-	int ind;
+	int fd;
 
-	for (ind = 0; ind <= PATH_MAX + 1; ind++) {
-		Longpathname[ind] = 'a';
-	}
-	return 0;
+	fd = SAFE_CREAT("file", 0777);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 
+	memset(longpathname, 'a', PATH_MAX + 2);
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int filepath_setup(void)
-{
-	int fd;
-
-	if ((fd = creat("file", 0777)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s",
-			 errno, strerror(errno));
-	}
-	close(fd);
-	return 0;
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 4/4] syscalls/unlink08: Cleanup && Convert to new API
  2018-02-09  7:56 [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
  2018-02-09  7:56 ` [LTP] [PATCH 3/4] syscalls/unlink07: " Xiao Yang
@ 2018-02-09  7:56 ` Xiao Yang
  2018-02-12 16:22 ` [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for " Cyril Hrubis
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-09  7:56 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove unused code

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink08.c | 365 ++++++----------------------
 1 file changed, 71 insertions(+), 294 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index 9829a7c..b280af5 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -28,328 +28,105 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink08
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-3) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
 
-void setup(void);
-void cleanup(void);
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns EACCES when deleting file in unwritable directory
+ *    as an unprivileged user.
+ * 2) unlink() returns EACCES when deleting file in "unsearchable directory
+ *    as an unprivileged user.
+ * 3) unlink() returns EISDIR when deleting directory in linux.
+ * 4) unlink() returns EPERM when deleting directory in non-linux.
+ */
 
-char *TCID = "unlink08";
-int TST_TOTAL = 3;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
 
-int unwrite_dir_setup(int flag);
-int unsearch_dir_setup(int flag);
-int dir_setup(int flag);
-int no_setup(int flag);
+static struct passwd *pw;
 
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
-	int (*setupfunc) (int flag);
-	int exp_ret;		/* -1 means error, 0 means != -1 */
 	int exp_errno;
-} Test_cases[] = {
-	{
-	"unwrite_dir/file", "unwritable directory", unwrite_dir_setup,
-		    -1, EACCES}, {
-	"unsearch_dir/file", "unsearchable directory",
-		    unsearch_dir_setup, -1, EACCES},
-#ifdef linux
-	{
-	"regdir", "directory", dir_setup, -1, EISDIR},
+	int exp_user;
+} tcases[] = {
+	{"unwrite_dir/file", "unwritable directory", EACCES, 1},
+	{"unsearch_dir/file", "unsearchable directory", EACCES, 1},
+#ifdef __linux__
+	{"regdir", "directory", EISDIR, 0},
 #else
-	{
-	"regdir", "directory", dir_setup, -1, EPERM},
+	{"regdir", "directory", EPERM, 0},
 #endif
-	{
-	NULL, NULL, no_setup, -1, 0}
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
+static void verify_unlink(struct test_case_t *tc)
 {
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (Test_cases[ind].exp_ret == -1) {	/* neg test */
-					if (TEST_ERRNO ==
-					    Test_cases[ind].exp_errno)
-						tst_resm(TPASS,
-							 "unlink(<%s>) Failed, errno=%d",
-							 desc,
-							 TEST_ERRNO);
-					else
-						tst_resm(TFAIL,
-							 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-							 desc,
-							 TEST_ERRNO,
-							 Test_cases
-							 [ind].exp_errno);
-				} else {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				}
-			} else {
-				if (Test_cases[ind].exp_ret == -1) {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-						 desc, TEST_RETURN,
-						 Test_cases[ind].exp_errno);
-				} else {
-					tst_resm(TPASS,
-						 "unlink(<%s>) returned %ld",
-						 desc, TEST_RETURN);
-				}
-				Test_cases[ind].setupfunc(1);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int ind;
-	int postest = 0;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (geteuid() == 0) {
-		postest++;
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (Test_cases[ind].exp_errno == EACCES && postest)
-			Test_cases[ind].exp_ret = 0;	/* set as a pos test */
-		Test_cases[ind].setupfunc(0);
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unwrite_dir_setup(int flag)
+static void do_unlink(unsigned int n)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
+	struct test_case_t *cases = &tcases[n];
+	pid_t pid;
+
+	if (cases->exp_user) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			SAFE_SETUID(pw->pw_uid);
+			verify_unlink(cases);
+			exit(0);
 		}
-		close(fd);
 
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		verify_unlink(cases);
 	}
-	return 0;
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unsearch_dir_setup(int flag)
+static void setup(void)
 {
 	int fd;
 
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unsearch_dir", 0777);
-
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0777);
+	SAFE_MKDIR("unwrite_dir", 0777);
+	fd = SAFE_CREAT("unwrite_dir/file", 0777);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+	SAFE_CHMOD("unwrite_dir", 0555);
 
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("unsearch_dir", 0777);
+	fd = SAFE_CREAT("unsearch_dir/file", 0777);
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+	SAFE_CHMOD("unsearch_dir", 0666);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	}
-	return 0;
-}
+	SAFE_MKDIR("regdir", 0777);
 
-/******************************************************************
- *
- ******************************************************************/
-int dir_setup(int flag)
-{
-	SAFE_MKDIR(cleanup, "regdir", 0777);
-	return 0;
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(int flag)
-{
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = do_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API
  2018-02-09  7:56 [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API Xiao Yang
                   ` (2 preceding siblings ...)
  2018-02-09  7:56 ` [LTP] [PATCH 4/4] syscalls/unlink08: " Xiao Yang
@ 2018-02-12 16:22 ` Cyril Hrubis
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
  3 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-12 16:22 UTC (permalink / raw)
  To: ltp

Hi!
> Make sure get_high_address() can be used by new API.

I would he happier if we created better API for the new library. If
nothing else the function name is poorly choosen.

I would suggest naming it as tst_get_bad_addr() which better explains
what the return value.

Also looking at the code we seem to use several different ways of
triggering EFAULT:

* (void*)-1;

* get_high_address() which is sbrk(0) + 4 * PAGE_SIZE

* mmap() with PROT_NONE

I gueess that we may as well unify on one of these, all of them should
work but I suppose that mmap() with PROT_NONE would be safest bet here.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap()
  2018-02-12 16:22 ` [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for " Cyril Hrubis
@ 2018-02-13  8:41   ` Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API Xiao Yang
                       ` (4 more replies)
  0 siblings, 5 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-13  8:41 UTC (permalink / raw)
  To: ltp

Running mremap03 -i n got the following errors:
-----------------------------------------------
mremap03    1  TPASS  :  mremap() Fails, 'old region not mapped', errno 14
mremap03    1  TFAIL  :  mremap03.c:137: mremap() Fails, 'Unexpected errno 22
...
-----------------------------------------------

When running mremap03 in loops, we passed MAP_FAILED instead of bad
address into mremap().

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/mremap/mremap03.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c
index 12e3829..5cd1a67 100644
--- a/testcases/kernel/syscalls/mremap/mremap03.c
+++ b/testcases/kernel/syscalls/mremap/mremap03.c
@@ -84,7 +84,8 @@
 
 char *TCID = "mremap03";
 int TST_TOTAL = 1;
-char *addr;			/* addr of memory mapped region */
+static char *bad_addr;
+static char *addr;		/* addr of memory mapped region */
 int memsize;			/* memory mapped size */
 int newsize;			/* new size of virtual memory block */
 
@@ -111,7 +112,7 @@ int main(int ac, char **av)
 		 * virtual address was not mapped.
 		 */
 		errno = 0;
-		addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE);
+		addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE);
 		TEST_ERRNO = errno;
 
 		/* Check for the return value of mremap() */
@@ -173,7 +174,7 @@ void setup(void)
 	 * Set the old virtual address point to some address
 	 * which is not mapped.
 	 */
-	addr = (char *)get_high_address();
+	bad_addr = (char *)get_high_address();
 }
 
 /*
-- 
1.8.3.1




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

* [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
@ 2018-02-13  8:41     ` Xiao Yang
  2018-02-13 13:42       ` Cyril Hrubis
  2018-02-13  8:41     ` [LTP] [PATCH v2 3/5] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
                       ` (3 subsequent siblings)
  4 siblings, 1 reply; 25+ messages in thread
From: Xiao Yang @ 2018-02-13  8:41 UTC (permalink / raw)
  To: ltp

1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address
   as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/old/test.h                              |  4 +-
 include/tst_get_bad_addr.h                      | 31 ++++++++++++++++
 include/tst_test.h                              |  1 +
 lib/get_high_address.c                          | 40 --------------------
 lib/tst_get_bad_addr.c                          | 49 +++++++++++++++++++++++++
 testcases/kernel/syscalls/lchown/lchown02.c     | 19 +---------
 testcases/kernel/syscalls/link/link04.c         | 25 ++-----------
 testcases/kernel/syscalls/lstat/lstat02.c       | 10 +----
 testcases/kernel/syscalls/mkdir/mkdir01.c       | 39 +-------------------
 testcases/kernel/syscalls/mknod/mknod06.c       | 23 ++----------
 testcases/kernel/syscalls/mremap/mremap03.c     |  2 +-
 testcases/kernel/syscalls/msync/msync03.c       |  2 +-
 testcases/kernel/syscalls/stat/stat03.c         | 17 +--------
 testcases/kernel/syscalls/symlink/symlink03.c   | 21 ++---------
 testcases/kernel/syscalls/truncate/truncate03.c |  8 +---
 testcases/kernel/syscalls/unlink/unlink07.c     | 28 ++------------
 16 files changed, 103 insertions(+), 216 deletions(-)
 create mode 100644 include/tst_get_bad_addr.h
 delete mode 100644 lib/get_high_address.c
 create mode 100644 lib/tst_get_bad_addr.c

diff --git a/include/old/test.h b/include/old/test.h
index 137ebb1..74d11a1 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -63,6 +63,7 @@
 #include "old_device.h"
 #include "old_tmpdir.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;
 /* lib/tst_sig.c */
 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
 
-/* lib/get_high_address.c */
-char *get_high_address(void);
-
 /* lib/self_exec.c */
 void maybe_run_child(void (*child)(), const char *fmt, ...);
 int self_exec(const char *argv0, const char *fmt, ...);
diff --git a/include/tst_get_bad_addr.h b/include/tst_get_bad_addr.h
new file mode 100644
index 0000000..9bf157b
--- /dev/null
+++ b/include/tst_get_bad_addr.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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.
+ */
+
+#ifndef TST_GET_BAD_ADDR_H__
+#define TST_GET_BAD_ADDR_H__
+
+/* Functions from lib/tst_get_bad_addr.c */
+
+void *tst_get_bad_addr(void);
+
+#endif	/* TST_GET_BAD_ADDR_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index eaf7a1f..af97b89 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -40,6 +40,7 @@
 #include "tst_clone.h"
 #include "tst_kernel.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/get_high_address.c b/lib/get_high_address.c
deleted file mode 100644
index eed9cf1..0000000
--- a/lib/get_high_address.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
-
-/*
- * 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/
- */
-
-#include <unistd.h>
-
-char *get_high_address(void)
-{
-	return (char *)sbrk(0) + (4 * getpagesize());
-}
diff --git a/lib/tst_get_bad_addr.c b/lib/tst_get_bad_addr.c
new file mode 100644
index 0000000..ab12ad1
--- /dev/null
+++ b/lib/tst_get_bad_addr.c
@@ -0,0 +1,49 @@
+/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
+
+/*
+ * 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/
+ */
+
+#include <sys/mman.h>
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_get_bad_addr.h"
+
+void *tst_get_bad_addr(void)
+{
+	void *bad_addr;
+
+	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (bad_addr == MAP_FAILED)
+		tst_brk(TBROK, "mmap() failed to get bad address");
+
+	return bad_addr;
+}
diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
index 326e584..77b03a3 100644
--- a/testcases/kernel/syscalls/lchown/lchown02.c
+++ b/testcases/kernel/syscalls/lchown/lchown02.c
@@ -79,7 +79,6 @@ static void setup_eacces(int pos);
 static void setup_enotdir(int pos);
 static void setup_longpath(int pos);
 static void setup_efault(int pos);
-static void setup_highaddress(int pos);
 
 static char path[PATH_MAX + 2];
 
@@ -93,7 +92,6 @@ struct test_case_t {
 static struct test_case_t test_cases[] = {
 	{SFILE1, "Process is not owner/root", EPERM, setup_eperm},
 	{SFILE2, "Search permission denied", EACCES, setup_eacces},
-	{NULL, "Address beyond address space", EFAULT, setup_highaddress},
 	{NULL, "Unaccessible address space", EFAULT, setup_efault},
 	{path, "Pathname too long", ENAMETOOLONG, setup_longpath},
 	{SFILE3, "Path contains regular file", ENOTDIR, setup_enotdir},
@@ -254,27 +252,12 @@ static void setup_efault(int pos)
 {
 	char *bad_addr = 0;
 
-	bad_addr = mmap(NULL, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, -1, 0);
-
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
+	bad_addr = (char *)tst_get_bad_addr();
 
 	test_cases[pos].pathname = bad_addr;
 }
 
 /*
- * setup_efault() -- setup for a test condition where lchown(2) returns -1 and
- *                   sets errno to EFAULT.
- *
- * Use ltp function get_high_address() to compute high address.
- */
-static void setup_highaddress(int pos)
-{
-	test_cases[pos].pathname = get_high_address();
-}
-
-/*
  * setup_enotdir() - setup function for a test condition for which chown(2)
  *	             returns -1 and sets errno to ENOTDIR.
  *
diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c
index 679753f..ead9935 100644
--- a/testcases/kernel/syscalls/link/link04.c
+++ b/testcases/kernel/syscalls/link/link04.c
@@ -54,9 +54,6 @@
 static char *bad_addr = 0;
 
 static char longpath[PATH_MAX + 2];
-#if !defined(UCLINUX)
-char high_addr[64];
-#endif
 
 struct test_case_t {
 	char *file1;
@@ -73,9 +70,6 @@ struct test_case_t {
 	{"regfile/file", "path contains a regular file", "nefile", "nefile",
 	 ENOTDIR},
 	{longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{high_addr, "address beyond address space", "nefile", "nefile", EFAULT},
-#endif
 	{(char *)-1, "negative address", "nefile", "nefile", EFAULT},
 	/* second path is invalid */
 	{"regfile", "regfile", "", "empty string", ENOENT},
@@ -84,10 +78,6 @@ struct test_case_t {
 	{"regfile", "regfile", "file/file",
 		    "path contains a regular file", ENOENT},
 	{"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{"regfile", "regfile", high_addr,
-		    "address beyond address space", EFAULT},
-#endif
 	{"regfile", "regfile", (char *)-1, "negative address", EFAULT},
 	/* two existing files */
 	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
@@ -121,14 +111,6 @@ int main(int ac, char **av)
 			fname2 = test_cases[i].file2;
 			desc2 = test_cases[i].desc2;
 
-#if !defined(UCLINUX)
-			if (fname1 == high_addr)
-				fname1 = get_high_address();
-
-			if (fname2 == high_addr)
-				fname2 = get_high_address();
-#endif
-
 			TEST(link(fname1, fname2));
 
 			if (TEST_RETURN == -1) {
@@ -167,10 +149,9 @@ static void setup(void)
 	tst_tmpdir();
 
 #if !defined(UCLINUX)
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-	                     MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[6].file1 = bad_addr;
-	test_cases[12].file2 = bad_addr;
+	bad_addr = (char *)tst_get_bad_addr(),
+	test_cases[5].file1 = bad_addr;
+	test_cases[10].file2 = bad_addr;
 #endif
 
 	memset(longpath, 'a', PATH_MAX+1);
diff --git a/testcases/kernel/syscalls/lstat/lstat02.c b/testcases/kernel/syscalls/lstat/lstat02.c
index ab46787..2ea2dc9 100644
--- a/testcases/kernel/syscalls/lstat/lstat02.c
+++ b/testcases/kernel/syscalls/lstat/lstat02.c
@@ -61,7 +61,6 @@ static char elooppathname[sizeof(TEST_ELOOP) * 43] = ".";
 
 #if !defined(UCLINUX)
 static void bad_addr_setup(int);
-static void high_address_setup(int);
 #endif
 
 static struct test_case_t {
@@ -73,7 +72,6 @@ static struct test_case_t {
 	{TEST_ENOENT, ENOENT, NULL},
 #if !defined(UCLINUX)
 	{NULL, EFAULT, bad_addr_setup},
-	{NULL, EFAULT, high_address_setup},
 #endif
 	{longpathname, ENAMETOOLONG, NULL},
 	{TEST_ENOTDIR, ENOTDIR, NULL},
@@ -143,13 +141,7 @@ static void setup(void)
 #if !defined(UCLINUX)
 static void bad_addr_setup(int i)
 {
-	test_cases[i].pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-					   MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-}
-
-static void high_address_setup(int i)
-{
-	test_cases[i].pathname = (char *)get_high_address();
+	test_cases[i].pathname = (char *)tst_get_bad_addr();
 }
 #endif
 
diff --git a/testcases/kernel/syscalls/mkdir/mkdir01.c b/testcases/kernel/syscalls/mkdir/mkdir01.c
index 9839a09..d4d1fca 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir01.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir01.c
@@ -116,7 +116,7 @@ void setup();
 void cleanup();
 
 char *TCID = "mkdir01";
-int TST_TOTAL = 2;
+int TST_TOTAL = 1;
 
 char *bad_addr = 0;
 
@@ -161,37 +161,6 @@ int main(int ac, char **av)
 				 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");
 
 		}
-#if !defined(UCLINUX)
-		/*
-		 * TEST CASE: 2
-		 * mkdir() call with pointer above allocated address space.
-		 */
-
-		/* Call mkdir(2) */
-		TEST(mkdir(get_high_address(), 0777));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-		}
-
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT) {
-				tst_resm(TPASS,
-					 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EFAULT);
-			}
-		} else {
-			tst_resm(TFAIL,
-				 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");
-
-		}
-#endif /* if !defined(UCLINUX) */
 
 	}
 
@@ -212,11 +181,7 @@ void setup(void)
 	/* Create a temporary directory and make it current. */
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
+	bad_addr = (char *)tst_get_bad_addr();
 }
 
 /***************************************************************
diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c
index a8ee5ba..22a73af 100644
--- a/testcases/kernel/syscalls/mknod/mknod06.c
+++ b/testcases/kernel/syscalls/mknod/mknod06.c
@@ -93,7 +93,6 @@ int setup3();			/* setup function to test mknod for ENOTDIR */
 int longpath_setup();		/* setup function to test mknod for ENAMETOOLONG */
 int no_setup();			/* simply returns 0 to the caller */
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -105,9 +104,7 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	"tnode_1", "Specified node already exists", EEXIST, setup1},
 #if !defined(UCLINUX)
 	{
-	(char *)-1, "Negative address", EFAULT, no_setup}, {
-	High_address_node, "Address beyond address space", EFAULT,
-		    no_setup},
+	(char *)-1, "Negative address", EFAULT, no_setup},
 #endif
 	{
 	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
@@ -119,10 +116,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 
 char *TCID = "mknod06";
 int TST_TOTAL = ARRAY_SIZE(Test_cases);
-#if !defined(UCLINUX)
-extern char *get_high_address();
-#else
-#endif
 
 char *bad_addr = 0;
 
@@ -152,12 +145,6 @@ int main(int ac, char **av)
 			node_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (node_name == High_address_node) {
-				node_name = get_high_address();
-			}
-#endif
-
 			/*
 			 * Call mknod(2) to test different test conditions.
 			 * verify that it fails with -1 return value and
@@ -218,12 +205,8 @@ void setup(void)
 	tst_tmpdir();
 
 #if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
+	bad_addr = (char *)tst_get_bad_addr();
+	Test_cases[1].pathname = bad_addr;
 #endif
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c
index 5cd1a67..689da34 100644
--- a/testcases/kernel/syscalls/mremap/mremap03.c
+++ b/testcases/kernel/syscalls/mremap/mremap03.c
@@ -174,7 +174,7 @@ void setup(void)
 	 * Set the old virtual address point to some address
 	 * which is not mapped.
 	 */
-	bad_addr = (char *)get_high_address();
+	bad_addr = (char *)tst_get_bad_addr();
 }
 
 /*
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 2e072ca..23ca0a9 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -137,7 +137,7 @@ static void setup(void)
 
 #if !defined(UCLINUX)
 	/* memory pointed to by addr4 was not mapped */
-	addr4 = get_high_address();
+	addr4 = (char *)sbrk(0) + (4 * page_sz);
 #endif
 }
 
diff --git a/testcases/kernel/syscalls/stat/stat03.c b/testcases/kernel/syscalls/stat/stat03.c
index ef3d937..0dcab78 100644
--- a/testcases/kernel/syscalls/stat/stat03.c
+++ b/testcases/kernel/syscalls/stat/stat03.c
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -115,8 +114,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	TEST_FILE1, "No Search permissions to process", EACCES, setup1},
 #if !defined(UCLINUX)
 	{
-	High_address_node, "Address beyond address space", EFAULT, no_setup},
-	{
 	(char *)-1, "Negative address", EFAULT, no_setup},
 #endif
 	{
@@ -158,12 +155,6 @@ int main(int ac, char **av)
 			file_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (file_name == High_address_node) {
-				file_name = (char *)get_high_address();
-			}
-#endif
-
 			/*
 			 * Call stat(2) to test different test conditions.
 			 * verify that it fails with -1 return value and
@@ -238,12 +229,8 @@ void setup(void)
 	tst_tmpdir();
 
 #if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
+	bad_addr = (char *)tst_get_bad_addr();
+	Test_cases[1].pathname = bad_addr;
 #endif
 
 	/* call individual setup functions */
diff --git a/testcases/kernel/syscalls/symlink/symlink03.c b/testcases/kernel/syscalls/symlink/symlink03.c
index 89f23c9..dc10e59 100644
--- a/testcases/kernel/syscalls/symlink/symlink03.c
+++ b/testcases/kernel/syscalls/symlink/symlink03.c
@@ -125,13 +125,7 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	TEST_FILE1, SYM_FILE1, "No Search permissions to process",
 		    EACCES, setup1}, {
 	TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
-		    EEXIST, setup2},
-#if !defined(UCLINUX)
-	{
-	TESTFILE, High_address_node, "Address beyond address space",
-		    EFAULT, no_setup},
-#endif
-	{
+		    EEXIST, setup2}, {
 	TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, {
 	TESTFILE, Longpathname, "Symlink path too long", ENAMETOOLONG,
 		    longpath_setup}, {
@@ -171,11 +165,6 @@ int main(int ac, char **av)
 			test_file = Test_cases[ind].file;
 			sym_file = Test_cases[ind].link;
 			test_desc = Test_cases[ind].desc;
-#if !defined(UCLINUX)
-			if (sym_file == High_address_node) {
-				sym_file = (char *)get_high_address();
-			}
-#endif
 			/*
 			 * Call symlink(2) to test different test conditions.
 			 * verify that it fails with -1 return value and sets
@@ -242,12 +231,8 @@ void setup(void)
 	tst_tmpdir();
 
 #if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[3].link = bad_addr;
+	bad_addr = (char *)tst_get_bad_addr();
+	Test_cases[2].link = bad_addr;
 #endif
 
 	/* call individual setup functions */
diff --git a/testcases/kernel/syscalls/truncate/truncate03.c b/testcases/kernel/syscalls/truncate/truncate03.c
index 0aa7b3e..32b0038 100644
--- a/testcases/kernel/syscalls/truncate/truncate03.c
+++ b/testcases/kernel/syscalls/truncate/truncate03.c
@@ -77,7 +77,6 @@ static struct test_case_t {
 	{ TEST_FILE1, TRUNC_LEN, EACCES },
 	{ TEST_FILE2, TRUNC_LEN, ENOTDIR },
 #if !defined(UCLINUX)
-	{ NULL, TRUNC_LEN, EFAULT },
 	{ (char *)-1, TRUNC_LEN, EFAULT },
 #endif
 	{ long_pathname, TRUNC_LEN, ENAMETOOLONG },
@@ -117,7 +116,6 @@ int main(int ac, char **av)
 void setup(void)
 {
 	struct passwd *ltpuser;
-	char *bad_addr;
 	struct rlimit rlim;
 	sigset_t signalset;
 
@@ -137,11 +135,7 @@ void setup(void)
 	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);
 
 #if !defined(UCLINUX)
-	test_cases[2].pathname = (char *)get_high_address();
-
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[3].pathname = bad_addr;
+	test_cases[2].pathname = (char *)tst_get_bad_addr();
 #endif
 
 	memset(long_pathname, 'a', PATH_MAX + 1);
diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 66e4db8..9651eda 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -123,13 +123,9 @@
 void setup();
 void cleanup();
 
-extern char *get_high_address();
-
 char *TCID = "unlink07";
 int TST_TOTAL = 6;
 
-char *bad_addr = 0;
-
 int longpath_setup();
 int no_setup();
 int filepath_setup();
@@ -146,19 +142,9 @@ struct test_case_t {
 	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
 	"", "path is empty string", ENOENT, no_setup}, {
 	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOENT, no_setup}, {
 	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOTDIR, filepath_setup}, {
 	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
 	(char *)-1, "negative address", EFAULT, no_setup}, {
 	NULL, NULL, 0, no_setup}
@@ -196,10 +182,6 @@ int main(int ac, char **av)
 			fname = Test_cases[ind].pathname;
 			desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (fname == High_address)
-				fname = get_high_address();
-#endif
 			/*
 			 *  Call unlink(2)
 			 */
@@ -245,11 +227,7 @@ void setup(void)
 
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[7].pathname = bad_addr;
+	Test_cases[5].pathname = (char *)tst_get_bad_addr();
 
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
 		Test_cases[ind].setupfunc();
-- 
1.8.3.1




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

* [LTP] [PATCH v2 3/5] syscalls/unlink05, 06: Cleanup && Convert to new API
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API Xiao Yang
@ 2018-02-13  8:41     ` Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 4/5] syscalls/unlink07: " Xiao Yang
                       ` (2 subsequent siblings)
  4 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-13  8:41 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Merge unlink06 into unlink05

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/quickhit                            |   2 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/unlink/unlink05.c | 215 +++++++---------------------
 testcases/kernel/syscalls/unlink/unlink06.c | 215 ----------------------------
 7 files changed, 52 insertions(+), 384 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 49d2b11..21d31ad 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -964,7 +964,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/quickhit b/runtest/quickhit
index 2a42769..8264b22 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -255,8 +255,6 @@ uname01 uname01
 # Basic test for uname(2)
 unlink05 unlink05
 # Basic test for unlink(2)
-unlink06 unlink06
-# unlink(2) of a FIFO
 unlink07 unlink07
 # unlink(2) negative testcases
 unlink08 unlink08
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 004bbad..261c5f9 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -840,7 +840,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/syscalls b/runtest/syscalls
index ca84c10..7c3cd5b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 684f5e7..e67d726 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1082,7 +1082,6 @@
 /uname/uname02
 /uname/uname03
 /unlink/unlink05
-/unlink/unlink06
 /unlink/unlink07
 /unlink/unlink08
 /unlinkat/unlinkat01
diff --git a/testcases/kernel/syscalls/unlink/unlink05.c b/testcases/kernel/syscalls/unlink/unlink05.c
index aa49316..e61f9bc 100644
--- a/testcases/kernel/syscalls/unlink/unlink05.c
+++ b/testcases/kernel/syscalls/unlink/unlink05.c
@@ -28,182 +28,71 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink05.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for unlink(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.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
 
-void setup();
-void cleanup();
-void create_file();
-
-char *TCID = "unlink05";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
+/*
+ * Description:
+ * The testcase checks the basic functionality of the unlink(2).
+ * 1) unlink() can delete regular file successfully.
+ * 2) unlink() can delete fifo file successfully.
+ */
 
-int main(int ac, char **av)
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+
+static void file_create(char *);
+static void fifo_create(char *);
+
+static struct test_case_t {
+	void (*setupfunc)(char *);
+	char *desc;
+} tcases[] = {
+	{file_create, "file"},
+	{fifo_create, "fifo"},
+};
+
+static void file_create(char *name)
 {
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
+	int fd;
 
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "unlink(%s) returned %ld",
-				 fname, TEST_RETURN);
-			/* recreate file for next loop */
-			create_file();
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	sprintf(name, "tfile_%d", getpid());
+	fd = SAFE_OPEN(name, O_RDWR | O_CREAT, 0777);
+	SAFE_CLOSE(fd);
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void fifo_create(char *name)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	create_file();
+	sprintf(name, "tfifo_%d", getpid());
+	SAFE_MKFIFO(name, 0777);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void verify_unlink(unsigned int n)
 {
+	char fname[255];
+	struct test_case_t *tc = &tcases[n];
 
-	tst_rmdir();
+	tc->setupfunc(fname);
 
-}
-
-void create_file(void)
-{
-	sprintf(fname, "tfile_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+	TEST(unlink(fname));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "unlink(%s) failed", tc->desc);
+		return;
 	}
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+
+	if (!access(fname, F_OK)) {
+		tst_res(TFAIL, "unlink(%s) succeeded, but %s still existed",
+			tc->desc, tc->desc);
+		return;
 	}
+
+	tst_res(TPASS, "unlink(%s) succeeded", tc->desc);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
diff --git a/testcases/kernel/syscalls/unlink/unlink06.c b/testcases/kernel/syscalls/unlink/unlink06.c
deleted file mode 100644
index 0e38480..0000000
--- a/testcases/kernel/syscalls/unlink/unlink06.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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/
- *
- */
-/* $Id: unlink06.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink06
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) of a FIFO
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void create_file();
-void cleanup();
-
-char *TCID = "unlink06";
-int TST_TOTAL = 1;
-
-char Fname[255];
-
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		create_file();
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(Fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 Fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			if (access(Fname, F_OK) != -1) {
-				tst_resm(TFAIL,
-					 "unlink(%s) returned %ld, but access says file still exists.",
-					 Fname, TEST_RETURN);
-			} else {
-				tst_resm(TPASS, "unlink(%s) returned %ld",
-					 Fname, TEST_RETURN);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(Fname, "fifo_unlink%d", getpid());
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-void create_file(void)
-{
-	SAFE_MKFIFO(cleanup, Fname, 0777);
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v2 4/5] syscalls/unlink07: Cleanup && Convert to new API
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 3/5] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
@ 2018-02-13  8:41     ` Xiao Yang
  2018-02-13  8:41     ` [LTP] [PATCH v2 5/5] syscalls/unlink08: " Xiao Yang
  2018-02-13 13:04     ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Cyril Hrubis
  4 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-13  8:41 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove duplicate tests for EFAULT

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink07.c | 282 +++++-----------------------
 1 file changed, 50 insertions(+), 232 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 9651eda..1ef0816 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -28,259 +28,77 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink07
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-8) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns ENOENT if file doesn't exist.
+ * 2) unlink() returns ENOENT if path is empty.
+ * 3) unlink() returns ENOENT if path contains a non-existent file.
+ * 4) unlink() returns EFAULT if address beyond address space.
+ * 5) unlink() returns ENOTDIR if path contains a regular file.
+ * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+ * 7) unlink() returns EFAULT if address is negative.
+ */
+
 #include <errno.h>
 #include <string.h>
-#include <signal.h>
 #include <unistd.h>
-#include <sys/param.h>		/* for PATH_MAX */
-#include "test.h"
+#include <sys/param.h>	/* for PATH_MAX */
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+static char longpathname[PATH_MAX + 2];
 
-char *TCID = "unlink07";
-int TST_TOTAL = 6;
-
-int longpath_setup();
-int no_setup();
-int filepath_setup();
-char Longpathname[PATH_MAX + 2];
-char High_address[64];
-
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{
-	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
-	"", "path is empty string", ENOENT, no_setup}, {
-	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup}, {
-	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup}, {
-	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	(char *)-1, "negative address", EFAULT, no_setup}, {
-	NULL, NULL, 0, no_setup}
+} tcases[] = {
+	{"nonexistfile", "non-existent file", ENOENT},
+	{"", "path is empty string", ENOENT},
+	{"nefile/file", "path contains a non-existent file", ENOENT},
+	{NULL, "negative address", EFAULT},
+	{"file/file", "path contains a regular file", ENOTDIR},
+	{longpathname, "pathname too long", ENAMETOOLONG},
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
+static void verify_unlink(unsigned int n)
 {
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
+	struct test_case_t *tc = &tcases[n];
 
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO ==
-				    Test_cases[ind].exp_errno)
-					tst_resm(TPASS,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				else
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-						 desc, TEST_ERRNO,
-						 Test_cases
-						 [ind].exp_errno);
-			} else {
-				tst_resm(TFAIL,
-					 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-					 desc, TEST_RETURN,
-					 Test_cases[ind].exp_errno);
-			}
-		}
+	if (!tc->name)
+		tc->name = tst_get_bad_addr();
 
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int ind;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	Test_cases[5].pathname = (char *)tst_get_bad_addr();
-
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		Test_cases[ind].setupfunc();
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(void)
+static void setup(void)
 {
-	return 0;
-}
+	int fd;
 
-/******************************************************************
- *
- ******************************************************************/
-int longpath_setup(void)
-{
-	int ind;
-
-	for (ind = 0; ind <= PATH_MAX + 1; ind++) {
-		Longpathname[ind] = 'a';
-	}
-	return 0;
+	fd = SAFE_CREAT("file", 0777);
+	SAFE_CLOSE(fd);
 
+	memset(longpathname, 'a', PATH_MAX + 2);
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int filepath_setup(void)
-{
-	int fd;
-
-	if ((fd = creat("file", 0777)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s",
-			 errno, strerror(errno));
-	}
-	close(fd);
-	return 0;
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 5/5] syscalls/unlink08: Cleanup && Convert to new API
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
                       ` (2 preceding siblings ...)
  2018-02-13  8:41     ` [LTP] [PATCH v2 4/5] syscalls/unlink07: " Xiao Yang
@ 2018-02-13  8:41     ` Xiao Yang
  2018-02-13 13:04     ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Cyril Hrubis
  4 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-13  8:41 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove unused code

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink08.c | 363 ++++++----------------------
 1 file changed, 69 insertions(+), 294 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index 9829a7c..ed4cd32 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -28,328 +28,103 @@
  * For further information regarding this notice, see:
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
-/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink08
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-3) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
 
-void setup(void);
-void cleanup(void);
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns EACCES when deleting file in unwritable directory
+ *    as an unprivileged user.
+ * 2) unlink() returns EACCES when deleting file in "unsearchable directory
+ *    as an unprivileged user.
+ * 3) unlink() returns EISDIR when deleting directory in linux.
+ * 4) unlink() returns EPERM when deleting directory in non-linux.
+ */
 
-char *TCID = "unlink08";
-int TST_TOTAL = 3;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
 
-int unwrite_dir_setup(int flag);
-int unsearch_dir_setup(int flag);
-int dir_setup(int flag);
-int no_setup(int flag);
+static struct passwd *pw;
 
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
-	int (*setupfunc) (int flag);
-	int exp_ret;		/* -1 means error, 0 means != -1 */
 	int exp_errno;
-} Test_cases[] = {
-	{
-	"unwrite_dir/file", "unwritable directory", unwrite_dir_setup,
-		    -1, EACCES}, {
-	"unsearch_dir/file", "unsearchable directory",
-		    unsearch_dir_setup, -1, EACCES},
-#ifdef linux
-	{
-	"regdir", "directory", dir_setup, -1, EISDIR},
+	int exp_user;
+} tcases[] = {
+	{"unwrite_dir/file", "unwritable directory", EACCES, 1},
+	{"unsearch_dir/file", "unsearchable directory", EACCES, 1},
+#ifdef __linux__
+	{"regdir", "directory", EISDIR, 0},
 #else
-	{
-	"regdir", "directory", dir_setup, -1, EPERM},
+	{"regdir", "directory", EPERM, 0},
 #endif
-	{
-	NULL, NULL, no_setup, -1, 0}
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
+static void verify_unlink(struct test_case_t *tc)
 {
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (Test_cases[ind].exp_ret == -1) {	/* neg test */
-					if (TEST_ERRNO ==
-					    Test_cases[ind].exp_errno)
-						tst_resm(TPASS,
-							 "unlink(<%s>) Failed, errno=%d",
-							 desc,
-							 TEST_ERRNO);
-					else
-						tst_resm(TFAIL,
-							 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-							 desc,
-							 TEST_ERRNO,
-							 Test_cases
-							 [ind].exp_errno);
-				} else {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				}
-			} else {
-				if (Test_cases[ind].exp_ret == -1) {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-						 desc, TEST_RETURN,
-						 Test_cases[ind].exp_errno);
-				} else {
-					tst_resm(TPASS,
-						 "unlink(<%s>) returned %ld",
-						 desc, TEST_RETURN);
-				}
-				Test_cases[ind].setupfunc(1);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int ind;
-	int postest = 0;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (geteuid() == 0) {
-		postest++;
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (Test_cases[ind].exp_errno == EACCES && postest)
-			Test_cases[ind].exp_ret = 0;	/* set as a pos test */
-		Test_cases[ind].setupfunc(0);
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unwrite_dir_setup(int flag)
+static void do_unlink(unsigned int n)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
+	struct test_case_t *cases = &tcases[n];
+	pid_t pid;
+
+	if (cases->exp_user) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			SAFE_SETUID(pw->pw_uid);
+			verify_unlink(cases);
+			exit(0);
 		}
-		close(fd);
 
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		verify_unlink(cases);
 	}
-	return 0;
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unsearch_dir_setup(int flag)
+static void setup(void)
 {
 	int fd;
 
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unsearch_dir", 0777);
-
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0777);
+	SAFE_MKDIR("unwrite_dir", 0777);
+	fd = SAFE_CREAT("unwrite_dir/file", 0777);
+	SAFE_CLOSE(fd);
+	SAFE_CHMOD("unwrite_dir", 0555);
 
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("unsearch_dir", 0777);
+	fd = SAFE_CREAT("unsearch_dir/file", 0777);
+	SAFE_CLOSE(fd);
+	SAFE_CHMOD("unsearch_dir", 0666);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	}
-	return 0;
-}
+	SAFE_MKDIR("regdir", 0777);
 
-/******************************************************************
- *
- ******************************************************************/
-int dir_setup(int flag)
-{
-	SAFE_MKDIR(cleanup, "regdir", 0777);
-	return 0;
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(int flag)
-{
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = do_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap()
  2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
                       ` (3 preceding siblings ...)
  2018-02-13  8:41     ` [LTP] [PATCH v2 5/5] syscalls/unlink08: " Xiao Yang
@ 2018-02-13 13:04     ` Cyril Hrubis
  4 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-13 13:04 UTC (permalink / raw)
  To: ltp

Hi!
Applied, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-13  8:41     ` [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API Xiao Yang
@ 2018-02-13 13:42       ` Cyril Hrubis
  2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
  0 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-13 13:42 UTC (permalink / raw)
  To: ltp

Hi!
> --- /dev/null
> +++ b/include/tst_get_bad_addr.h
> @@ -0,0 +1,31 @@
> +/*
> + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
> + * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
> + *
> + * 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.

GPLv2+ is slightly pefered, see the license text in the tst_test.h.

> + * 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.
> + */
> +
> +#ifndef TST_GET_BAD_ADDR_H__
> +#define TST_GET_BAD_ADDR_H__
> +
> +/* Functions from lib/tst_get_bad_addr.c */
> +
> +void *tst_get_bad_addr(void);
> +
> +#endif	/* TST_GET_BAD_ADDR_H__ */
> diff --git a/include/tst_test.h b/include/tst_test.h
> index eaf7a1f..af97b89 100644
> --- a/include/tst_test.h
> +++ b/include/tst_test.h
> @@ -40,6 +40,7 @@
>  #include "tst_clone.h"
>  #include "tst_kernel.h"
>  #include "tst_minmax.h"
> +#include "tst_get_bad_addr.h"
>  
>  /*
>   * Reports testcase result.
> diff --git a/lib/get_high_address.c b/lib/get_high_address.c
> deleted file mode 100644
> index eed9cf1..0000000
> --- a/lib/get_high_address.c
> +++ /dev/null
> @@ -1,40 +0,0 @@
> -/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
> -
> -/*
> - * 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/
> - */
> -
> -#include <unistd.h>
> -
> -char *get_high_address(void)
> -{
> -	return (char *)sbrk(0) + (4 * getpagesize());
> -}
> diff --git a/lib/tst_get_bad_addr.c b/lib/tst_get_bad_addr.c
> new file mode 100644
> index 0000000..ab12ad1
> --- /dev/null
> +++ b/lib/tst_get_bad_addr.c
> @@ -0,0 +1,49 @@
> +/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
> +
> +/*
> + * 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/
> + */

Here as well, we do not use a single line from the original file so we
may as well put GPLv2+ header here.

> +#include <sys/mman.h>
> +#define TST_NO_DEFAULT_MAIN
> +#include "tst_test.h"
> +#include "tst_get_bad_addr.h"
> +
> +void *tst_get_bad_addr(void)
> +{
> +	void *bad_addr;
> +
> +	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> +	if (bad_addr == MAP_FAILED)
> +		tst_brk(TBROK, "mmap() failed to get bad address");

I suppose that we have to actually use tst_brkm() and the old test.h if
this is supposed to be called from the old library tests. Otherwise
things will crash and burn once this tst_brk() gets called.

That is because we route tst_brkm() to the tst_brk() if new library is
detected but not the other way around.

> +	return bad_addr;
> +}
> diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
> index 326e584..77b03a3 100644
> --- a/testcases/kernel/syscalls/lchown/lchown02.c
> +++ b/testcases/kernel/syscalls/lchown/lchown02.c
> @@ -79,7 +79,6 @@ static void setup_eacces(int pos);
>  static void setup_enotdir(int pos);
>  static void setup_longpath(int pos);
>  static void setup_efault(int pos);
> -static void setup_highaddress(int pos);
>  
>  static char path[PATH_MAX + 2];
>  
> @@ -93,7 +92,6 @@ struct test_case_t {
>  static struct test_case_t test_cases[] = {
>  	{SFILE1, "Process is not owner/root", EPERM, setup_eperm},
>  	{SFILE2, "Search permission denied", EACCES, setup_eacces},
> -	{NULL, "Address beyond address space", EFAULT, setup_highaddress},
>  	{NULL, "Unaccessible address space", EFAULT, setup_efault},
>  	{path, "Pathname too long", ENAMETOOLONG, setup_longpath},
>  	{SFILE3, "Path contains regular file", ENOTDIR, setup_enotdir},
> @@ -254,27 +252,12 @@ static void setup_efault(int pos)
>  {
>  	char *bad_addr = 0;
>  
> -	bad_addr = mmap(NULL, 1, PROT_NONE,
> -			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, -1, 0);
> -
> -	if (bad_addr == MAP_FAILED)
> -		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
> +	bad_addr = (char *)tst_get_bad_addr();
                    ^
		    Plese get rid of useless casts like this one.

>  	test_cases[pos].pathname = bad_addr;
>  }
>  
>  /*
> - * setup_efault() -- setup for a test condition where lchown(2) returns -1 and
> - *                   sets errno to EFAULT.
> - *
> - * Use ltp function get_high_address() to compute high address.
> - */
> -static void setup_highaddress(int pos)
> -{
> -	test_cases[pos].pathname = get_high_address();
> -}
> -
> -/*
>   * setup_enotdir() - setup function for a test condition for which chown(2)
>   *	             returns -1 and sets errno to ENOTDIR.
>   *
> diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c
> index 679753f..ead9935 100644
> --- a/testcases/kernel/syscalls/link/link04.c
> +++ b/testcases/kernel/syscalls/link/link04.c
> @@ -54,9 +54,6 @@
>  static char *bad_addr = 0;
>  
>  static char longpath[PATH_MAX + 2];
> -#if !defined(UCLINUX)
> -char high_addr[64];
> -#endif
>  
>  struct test_case_t {
>  	char *file1;
> @@ -73,9 +70,6 @@ struct test_case_t {
>  	{"regfile/file", "path contains a regular file", "nefile", "nefile",
>  	 ENOTDIR},
>  	{longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG},
> -#if !defined(UCLINUX)
> -	{high_addr, "address beyond address space", "nefile", "nefile", EFAULT},
> -#endif
>  	{(char *)-1, "negative address", "nefile", "nefile", EFAULT},
>  	/* second path is invalid */
>  	{"regfile", "regfile", "", "empty string", ENOENT},
> @@ -84,10 +78,6 @@ struct test_case_t {
>  	{"regfile", "regfile", "file/file",
>  		    "path contains a regular file", ENOENT},
>  	{"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG},
> -#if !defined(UCLINUX)
> -	{"regfile", "regfile", high_addr,
> -		    "address beyond address space", EFAULT},
> -#endif
>  	{"regfile", "regfile", (char *)-1, "negative address", EFAULT},
>  	/* two existing files */
>  	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
> @@ -121,14 +111,6 @@ int main(int ac, char **av)
>  			fname2 = test_cases[i].file2;
>  			desc2 = test_cases[i].desc2;
>  
> -#if !defined(UCLINUX)
> -			if (fname1 == high_addr)
> -				fname1 = get_high_address();
> -
> -			if (fname2 == high_addr)
> -				fname2 = get_high_address();
> -#endif
> -
>  			TEST(link(fname1, fname2));
>  
>  			if (TEST_RETURN == -1) {
> @@ -167,10 +149,9 @@ static void setup(void)
>  	tst_tmpdir();
>  
>  #if !defined(UCLINUX)
> -	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
> -	                     MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	test_cases[6].file1 = bad_addr;
> -	test_cases[12].file2 = bad_addr;
> +	bad_addr = (char *)tst_get_bad_addr(),
                    ^
		    Here as well.

And the same applies to the rest of the patchset.

> +	test_cases[5].file1 = bad_addr;
> +	test_cases[10].file2 = bad_addr;

Also assigning to random array members here is kind of ugly, we usually
go for pointer to a pointer and assignd &bad_addr in the test structure.

But given that it has been there already, if we want to fix it, it
should be done in a follow up patch...


-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-13 13:42       ` Cyril Hrubis
@ 2018-02-14  6:19         ` Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
                             ` (3 more replies)
  0 siblings, 4 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-14  6:19 UTC (permalink / raw)
  To: ltp

1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address
   as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03
5) remove UCLINUX

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/old/test.h                              |  4 +--
 include/tst_get_bad_addr.h                      | 37 +++++++++++++++++++++
 include/tst_test.h                              |  1 +
 lib/get_high_address.c                          | 40 ----------------------
 lib/tst_get_bad_addr.c                          | 31 +++++++++++++++++
 testcases/kernel/syscalls/lchown/lchown02.c     | 28 ++--------------
 testcases/kernel/syscalls/link/link04.c         | 33 ++++---------------
 testcases/kernel/syscalls/lstat/lstat02.c       | 23 +++----------
 testcases/kernel/syscalls/mkdir/mkdir01.c       | 39 ++--------------------
 testcases/kernel/syscalls/mknod/mknod06.c       | 33 +++----------------
 testcases/kernel/syscalls/mremap/mremap03.c     | 13 +-------
 testcases/kernel/syscalls/msync/msync03.c       |  9 +----
 testcases/kernel/syscalls/rmdir/rmdir05.c       | 44 ++-----------------------
 testcases/kernel/syscalls/stat/stat03.c         | 30 +++--------------
 testcases/kernel/syscalls/symlink/symlink03.c   | 32 ++++--------------
 testcases/kernel/syscalls/truncate/truncate03.c | 15 ++-------
 testcases/kernel/syscalls/unlink/unlink07.c     | 33 ++++---------------
 17 files changed, 112 insertions(+), 333 deletions(-)
 create mode 100644 include/tst_get_bad_addr.h
 delete mode 100644 lib/get_high_address.c
 create mode 100644 lib/tst_get_bad_addr.c

diff --git a/include/old/test.h b/include/old/test.h
index 137ebb1..74d11a1 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -63,6 +63,7 @@
 #include "old_device.h"
 #include "old_tmpdir.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;
 /* lib/tst_sig.c */
 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
 
-/* lib/get_high_address.c */
-char *get_high_address(void);
-
 /* lib/self_exec.c */
 void maybe_run_child(void (*child)(), const char *fmt, ...);
 int self_exec(const char *argv0, const char *fmt, ...);
diff --git a/include/tst_get_bad_addr.h b/include/tst_get_bad_addr.h
new file mode 100644
index 0000000..85035c3
--- /dev/null
+++ b/include/tst_get_bad_addr.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_GET_BAD_ADDR_H__
+#define TST_GET_BAD_ADDR_H__
+
+/* Functions from lib/tst_get_bad_addr.c */
+void *tst_get_bad_addr_(void (*cleanup_fn) (void));
+
+#ifdef TST_TEST_H__
+static inline void *tst_get_bad_addr(void)
+{
+	return tst_get_bad_addr_(NULL);
+}
+#else
+static inline void *tst_get_bad_addr(void (*cleanup_fn)(void))
+{
+	return tst_get_bad_addr_(cleanup_fn);
+}
+#endif
+
+#endif	/* TST_GET_BAD_ADDR_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index eaf7a1f..af97b89 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -40,6 +40,7 @@
 #include "tst_clone.h"
 #include "tst_kernel.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/get_high_address.c b/lib/get_high_address.c
deleted file mode 100644
index eed9cf1..0000000
--- a/lib/get_high_address.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
-
-/*
- * 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/
- */
-
-#include <unistd.h>
-
-char *get_high_address(void)
-{
-	return (char *)sbrk(0) + (4 * getpagesize());
-}
diff --git a/lib/tst_get_bad_addr.c b/lib/tst_get_bad_addr.c
new file mode 100644
index 0000000..4e6f1ca
--- /dev/null
+++ b/lib/tst_get_bad_addr.c
@@ -0,0 +1,31 @@
+/*
+ * 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 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mman.h>
+#include "test.h"
+#include "tst_get_bad_addr.h"
+
+void *tst_get_bad_addr_(void (*cleanup_fn) (void))
+{
+	void *bad_addr;
+
+	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (bad_addr == MAP_FAILED)
+		tst_brkm(TBROK, cleanup_fn, "mmap() failed to get bad address");
+
+	return bad_addr;
+}
diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
index 326e584..97966f6 100644
--- a/testcases/kernel/syscalls/lchown/lchown02.c
+++ b/testcases/kernel/syscalls/lchown/lchown02.c
@@ -74,12 +74,13 @@
 TCID_DEFINE(lchown02);
 int TST_TOTAL = 7;
 
+static void setup(void);
+static void cleanup(void);
 static void setup_eperm(int pos);
 static void setup_eacces(int pos);
 static void setup_enotdir(int pos);
 static void setup_longpath(int pos);
 static void setup_efault(int pos);
-static void setup_highaddress(int pos);
 
 static char path[PATH_MAX + 2];
 
@@ -93,7 +94,6 @@ struct test_case_t {
 static struct test_case_t test_cases[] = {
 	{SFILE1, "Process is not owner/root", EPERM, setup_eperm},
 	{SFILE2, "Search permission denied", EACCES, setup_eacces},
-	{NULL, "Address beyond address space", EFAULT, setup_highaddress},
 	{NULL, "Unaccessible address space", EFAULT, setup_efault},
 	{path, "Pathname too long", ENAMETOOLONG, setup_longpath},
 	{SFILE3, "Path contains regular file", ENOTDIR, setup_enotdir},
@@ -103,9 +103,6 @@ static struct test_case_t test_cases[] = {
 
 static struct passwd *ltpuser;
 
-static void setup(void);
-static void cleanup(void);
-
 int main(int argc, char *argv[])
 {
 	int lc;
@@ -252,26 +249,7 @@ static void setup_eacces(int pos LTP_ATTRIBUTE_UNUSED)
  */
 static void setup_efault(int pos)
 {
-	char *bad_addr = 0;
-
-	bad_addr = mmap(NULL, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, -1, 0);
-
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
-
-	test_cases[pos].pathname = bad_addr;
-}
-
-/*
- * setup_efault() -- setup for a test condition where lchown(2) returns -1 and
- *                   sets errno to EFAULT.
- *
- * Use ltp function get_high_address() to compute high address.
- */
-static void setup_highaddress(int pos)
-{
-	test_cases[pos].pathname = get_high_address();
+	test_cases[pos].pathname = tst_get_bad_addr(cleanup);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c
index 679753f..ac3076c 100644
--- a/testcases/kernel/syscalls/link/link04.c
+++ b/testcases/kernel/syscalls/link/link04.c
@@ -51,12 +51,7 @@
 #include "test.h"
 #include "safe_macros.h"
 
-static char *bad_addr = 0;
-
 static char longpath[PATH_MAX + 2];
-#if !defined(UCLINUX)
-char high_addr[64];
-#endif
 
 struct test_case_t {
 	char *file1;
@@ -73,10 +68,7 @@ struct test_case_t {
 	{"regfile/file", "path contains a regular file", "nefile", "nefile",
 	 ENOTDIR},
 	{longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{high_addr, "address beyond address space", "nefile", "nefile", EFAULT},
-#endif
-	{(char *)-1, "negative address", "nefile", "nefile", EFAULT},
+	{NULL, "negative address", "nefile", "nefile", EFAULT},
 	/* second path is invalid */
 	{"regfile", "regfile", "", "empty string", ENOENT},
 	{"regfile", "regfile", "neefile/file",
@@ -84,11 +76,7 @@ struct test_case_t {
 	{"regfile", "regfile", "file/file",
 		    "path contains a regular file", ENOENT},
 	{"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{"regfile", "regfile", high_addr,
-		    "address beyond address space", EFAULT},
-#endif
-	{"regfile", "regfile", (char *)-1, "negative address", EFAULT},
+	{"regfile", "regfile", NULL, "negative address", EFAULT},
 	/* two existing files */
 	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
 };
@@ -121,13 +109,11 @@ int main(int ac, char **av)
 			fname2 = test_cases[i].file2;
 			desc2 = test_cases[i].desc2;
 
-#if !defined(UCLINUX)
-			if (fname1 == high_addr)
-				fname1 = get_high_address();
+			if (!fname1)
+				fname1 = tst_get_bad_addr(cleanup);
 
-			if (fname2 == high_addr)
-				fname2 = get_high_address();
-#endif
+			if (!fname2)
+				fname2 = tst_get_bad_addr(cleanup);
 
 			TEST(link(fname1, fname2));
 
@@ -166,13 +152,6 @@ static void setup(void)
 
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-	                     MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[6].file1 = bad_addr;
-	test_cases[12].file2 = bad_addr;
-#endif
-
 	memset(longpath, 'a', PATH_MAX+1);
 	SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
 	SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
diff --git a/testcases/kernel/syscalls/lstat/lstat02.c b/testcases/kernel/syscalls/lstat/lstat02.c
index ab46787..15285e7 100644
--- a/testcases/kernel/syscalls/lstat/lstat02.c
+++ b/testcases/kernel/syscalls/lstat/lstat02.c
@@ -59,10 +59,10 @@
 static char longpathname[PATH_MAX + 2];
 static char elooppathname[sizeof(TEST_ELOOP) * 43] = ".";
 
-#if !defined(UCLINUX)
+static void setup(void);
+static void lstat_verify(int);
+static void cleanup(void);
 static void bad_addr_setup(int);
-static void high_address_setup(int);
-#endif
 
 static struct test_case_t {
 	char *pathname;
@@ -71,10 +71,7 @@ static struct test_case_t {
 } test_cases[] = {
 	{TEST_EACCES, EACCES, NULL},
 	{TEST_ENOENT, ENOENT, NULL},
-#if !defined(UCLINUX)
 	{NULL, EFAULT, bad_addr_setup},
-	{NULL, EFAULT, high_address_setup},
-#endif
 	{longpathname, ENAMETOOLONG, NULL},
 	{TEST_ENOTDIR, ENOTDIR, NULL},
 	{elooppathname, ELOOP, NULL},
@@ -83,10 +80,6 @@ static struct test_case_t {
 char *TCID = "lstat02";
 int TST_TOTAL = ARRAY_SIZE(test_cases);
 
-static void setup(void);
-static void lstat_verify(int);
-static void cleanup(void);
-
 int main(int ac, char **av)
 {
 	int lc;
@@ -140,18 +133,10 @@ static void setup(void)
 		strcat(elooppathname, TEST_ELOOP);
 }
 
-#if !defined(UCLINUX)
 static void bad_addr_setup(int i)
 {
-	test_cases[i].pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-					   MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-}
-
-static void high_address_setup(int i)
-{
-	test_cases[i].pathname = (char *)get_high_address();
+	test_cases[i].pathname = tst_get_bad_addr(cleanup);
 }
-#endif
 
 static void lstat_verify(int i)
 {
diff --git a/testcases/kernel/syscalls/mkdir/mkdir01.c b/testcases/kernel/syscalls/mkdir/mkdir01.c
index 9839a09..84012c0 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir01.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir01.c
@@ -116,7 +116,7 @@ void setup();
 void cleanup();
 
 char *TCID = "mkdir01";
-int TST_TOTAL = 2;
+int TST_TOTAL = 1;
 
 char *bad_addr = 0;
 
@@ -161,37 +161,6 @@ int main(int ac, char **av)
 				 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");
 
 		}
-#if !defined(UCLINUX)
-		/*
-		 * TEST CASE: 2
-		 * mkdir() call with pointer above allocated address space.
-		 */
-
-		/* Call mkdir(2) */
-		TEST(mkdir(get_high_address(), 0777));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-		}
-
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT) {
-				tst_resm(TPASS,
-					 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EFAULT);
-			}
-		} else {
-			tst_resm(TFAIL,
-				 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");
-
-		}
-#endif /* if !defined(UCLINUX) */
 
 	}
 
@@ -212,11 +181,7 @@ void setup(void)
 	/* Create a temporary directory and make it current. */
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 /***************************************************************
diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c
index a8ee5ba..a128912 100644
--- a/testcases/kernel/syscalls/mknod/mknod06.c
+++ b/testcases/kernel/syscalls/mknod/mknod06.c
@@ -93,7 +93,6 @@ int setup3();			/* setup function to test mknod for ENOTDIR */
 int longpath_setup();		/* setup function to test mknod for ENAMETOOLONG */
 int no_setup();			/* simply returns 0 to the caller */
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -101,15 +100,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	"tnode_1", "Specified node already exists", EEXIST, setup1},
-#if !defined(UCLINUX)
-	{
-	(char *)-1, "Negative address", EFAULT, no_setup}, {
-	High_address_node, "Address beyond address space", EFAULT,
-		    no_setup},
-#endif
-	{
+	{"tnode_1", "Specified node already exists", EEXIST, setup1}, {
+	NULL, "Negative address", EFAULT, no_setup}, {
 	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
 	"", "Pathname is empty", ENOENT, no_setup}, {
 	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
@@ -119,12 +111,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 
 char *TCID = "mknod06";
 int TST_TOTAL = ARRAY_SIZE(Test_cases);
-#if !defined(UCLINUX)
-extern char *get_high_address();
-#else
-#endif
-
-char *bad_addr = 0;
 
 void setup();			/* setup function for the tests */
 void cleanup();			/* cleanup function for the tests */
@@ -152,11 +138,8 @@ int main(int ac, char **av)
 			node_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (node_name == High_address_node) {
-				node_name = get_high_address();
-			}
-#endif
+			if (!node_name)
+				node_name = tst_get_bad_addr(cleanup);
 
 			/*
 			 * Call mknod(2) to test different test conditions.
@@ -217,14 +200,6 @@ void setup(void)
 	/* Make a temp dir and cd to it */
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
-#endif
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
 		Test_cases[ind].setupfunc();
diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c
index 5cd1a67..a85e986 100644
--- a/testcases/kernel/syscalls/mremap/mremap03.c
+++ b/testcases/kernel/syscalls/mremap/mremap03.c
@@ -92,7 +92,6 @@ int newsize;			/* new size of virtual memory block */
 void setup();			/* Main setup function of test */
 void cleanup();			/* cleanup function for the test */
 
-#if !defined(UCLINUX)
 int main(int ac, char **av)
 {
 	int lc;
@@ -174,7 +173,7 @@ void setup(void)
 	 * Set the old virtual address point to some address
 	 * which is not mapped.
 	 */
-	bad_addr = (char *)get_high_address();
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 /*
@@ -187,13 +186,3 @@ void cleanup(void)
 	/* Exit the program */
 
 }
-
-#else
-
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 2e072ca..f504ed1 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -57,10 +57,7 @@ static int fd;
 static char *addr1;
 static char *addr2;
 static char *addr3;
-
-#if !defined(UCLINUX)
 static char *addr4;
-#endif
 
 static size_t page_sz;
 
@@ -74,9 +71,7 @@ static struct test_case_t {
 	{ &addr1, INV_SYNC, EINVAL },
 	{ &addr2, MS_SYNC, EINVAL },
 	{ &addr3, MS_SYNC, EINVAL },
-#if !defined(UCLINUX)
 	{ &addr4, MS_SYNC, ENOMEM },
-#endif
 };
 
 static void msync_verify(struct test_case_t *tc);
@@ -135,10 +130,8 @@ static void setup(void)
 	SAFE_GETRLIMIT(NULL, RLIMIT_DATA, &rl);
 	addr3 = (char *)rl.rlim_max;
 
-#if !defined(UCLINUX)
 	/* memory pointed to by addr4 was not mapped */
-	addr4 = get_high_address();
-#endif
+	addr4 = sbrk(0) + (4 * page_sz);
 }
 
 static void msync_verify(struct test_case_t *tc)
diff --git a/testcases/kernel/syscalls/rmdir/rmdir05.c b/testcases/kernel/syscalls/rmdir/rmdir05.c
index bef3b47..0eb54f0 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir05.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir05.c
@@ -50,12 +50,7 @@
 static void setup(void);
 static void cleanup(void);
 
-#if !defined(UCLINUX)
-extern char *get_high_address();
-int TST_TOTAL = 6;
-#else
-int TST_TOTAL = 4;
-#endif
+int TST_TOTAL = 5;
 
 char *TCID = "rmdir05";
 
@@ -119,7 +114,6 @@ int main(int argc, char **argv)
 		 * TEST CASE: 4
 		 * path argument points below the minimum allocated address space
 		 */
-#if !defined(UCLINUX)
 		TEST(rmdir(bad_addr));
 
 		if (TEST_RETURN == -1) {
@@ -144,34 +138,6 @@ int main(int argc, char **argv)
 
 		/*
 		 * TEST CASE: 5
-		 * path argument points above the maximum allocated address space
-		 */
-
-		TEST(rmdir(get_high_address()));
-
-		if (TEST_RETURN == -1) {
-		}
-
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT) {
-				tst_resm(TPASS,
-					 "rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EFAULT);
-			}
-		} else {
-			tst_resm(TFAIL,
-				 "rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly.");
-		}
-#endif
-
-		/*
-		 * TEST CASE: 6
 		 * able to remove a directory
 		 */
 
@@ -220,13 +186,7 @@ void setup(void)
 	/* Create a unique directory name. */
 	sprintf(dir_name, "./dir_%d", getpid());
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-#endif
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/stat/stat03.c b/testcases/kernel/syscalls/stat/stat03.c
index ef3d937..b0e4e89 100644
--- a/testcases/kernel/syscalls/stat/stat03.c
+++ b/testcases/kernel/syscalls/stat/stat03.c
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -111,15 +110,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	TEST_FILE1, "No Search permissions to process", EACCES, setup1},
-#if !defined(UCLINUX)
-	{
-	High_address_node, "Address beyond address space", EFAULT, no_setup},
-	{
-	(char *)-1, "Negative address", EFAULT, no_setup},
-#endif
-	{
+	{TEST_FILE1, "No Search permissions to process", EACCES, setup1}, {
+	NULL, "Negative address", EFAULT, no_setup}, {
 	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
 	"", "Pathname is empty", ENOENT, no_setup}, {
 	TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {
@@ -129,8 +121,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 char *TCID = "stat03";
 int TST_TOTAL = ARRAY_SIZE(Test_cases);
 
-char *bad_addr = 0;
-
 void setup();			/* Main setup function for the tests */
 void cleanup();			/* cleanup function for the test */
 
@@ -158,11 +148,8 @@ int main(int ac, char **av)
 			file_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (file_name == High_address_node) {
-				file_name = (char *)get_high_address();
-			}
-#endif
+			if (!file_name)
+				file_name = tst_get_bad_addr(cleanup);
 
 			/*
 			 * Call stat(2) to test different test conditions.
@@ -237,15 +224,6 @@ void setup(void)
 	/* Make a temp dir and cd to it */
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
-#endif
-
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
 		Test_cases[ind].setupfunc();
diff --git a/testcases/kernel/syscalls/symlink/symlink03.c b/testcases/kernel/syscalls/symlink/symlink03.c
index 89f23c9..f1c0d6e 100644
--- a/testcases/kernel/syscalls/symlink/symlink03.c
+++ b/testcases/kernel/syscalls/symlink/symlink03.c
@@ -103,8 +103,6 @@
 char *TCID = "symlink03";
 int TST_TOTAL = 1;
 
-char *bad_addr = 0;
-
 int no_setup();
 int setup1();			/* setup function to test symlink for EACCES */
 int setup2();			/* setup function to test symlink for EEXIST */
@@ -121,18 +119,11 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	TEST_FILE1, SYM_FILE1, "No Search permissions to process",
+	{TEST_FILE1, SYM_FILE1, "No Search permissions to process",
 		    EACCES, setup1}, {
 	TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
-		    EEXIST, setup2},
-#if !defined(UCLINUX)
-	{
-	TESTFILE, High_address_node, "Address beyond address space",
-		    EFAULT, no_setup},
-#endif
-	{
-	TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, {
+		    EEXIST, setup2}, {
+	TESTFILE, NULL, "Negative address", EFAULT, no_setup}, {
 	TESTFILE, Longpathname, "Symlink path too long", ENAMETOOLONG,
 		    longpath_setup}, {
 	TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
@@ -171,11 +162,9 @@ int main(int ac, char **av)
 			test_file = Test_cases[ind].file;
 			sym_file = Test_cases[ind].link;
 			test_desc = Test_cases[ind].desc;
-#if !defined(UCLINUX)
-			if (sym_file == High_address_node) {
-				sym_file = (char *)get_high_address();
-			}
-#endif
+
+			if (!sym_file)
+				sym_file = tst_get_bad_addr(cleanup);
 			/*
 			 * Call symlink(2) to test different test conditions.
 			 * verify that it fails with -1 return value and sets
@@ -241,15 +230,6 @@ void setup(void)
 
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[3].link = bad_addr;
-#endif
-
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
 		Test_cases[ind].setupfunc();
diff --git a/testcases/kernel/syscalls/truncate/truncate03.c b/testcases/kernel/syscalls/truncate/truncate03.c
index 0aa7b3e..041bdfb 100644
--- a/testcases/kernel/syscalls/truncate/truncate03.c
+++ b/testcases/kernel/syscalls/truncate/truncate03.c
@@ -76,10 +76,7 @@ static struct test_case_t {
 } test_cases[] = {
 	{ TEST_FILE1, TRUNC_LEN, EACCES },
 	{ TEST_FILE2, TRUNC_LEN, ENOTDIR },
-#if !defined(UCLINUX)
 	{ NULL, TRUNC_LEN, EFAULT },
-	{ (char *)-1, TRUNC_LEN, EFAULT },
-#endif
 	{ long_pathname, TRUNC_LEN, ENAMETOOLONG },
 	{ "", TRUNC_LEN, ENOENT },
 	{ TEST_DIR1, TRUNC_LEN, EISDIR },
@@ -117,7 +114,6 @@ int main(int ac, char **av)
 void setup(void)
 {
 	struct passwd *ltpuser;
-	char *bad_addr;
 	struct rlimit rlim;
 	sigset_t signalset;
 
@@ -136,14 +132,6 @@ void setup(void)
 
 	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);
 
-#if !defined(UCLINUX)
-	test_cases[2].pathname = (char *)get_high_address();
-
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[3].pathname = bad_addr;
-#endif
-
 	memset(long_pathname, 'a', PATH_MAX + 1);
 
 	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);
@@ -166,6 +154,9 @@ void setup(void)
 
 void truncate_verify(struct test_case_t *tc)
 {
+	if (!tc->pathname)
+		tc->pathname = tst_get_bad_addr(cleanup);
+
 	TEST(truncate(tc->pathname, tc->length));
 
 	if (TEST_RETURN != -1) {
diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 66e4db8..7eb8388 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -123,13 +123,9 @@
 void setup();
 void cleanup();
 
-extern char *get_high_address();
-
 char *TCID = "unlink07";
 int TST_TOTAL = 6;
 
-char *bad_addr = 0;
-
 int longpath_setup();
 int no_setup();
 int filepath_setup();
@@ -146,21 +142,11 @@ struct test_case_t {
 	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
 	"", "path is empty string", ENOENT, no_setup}, {
 	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOENT, no_setup}, {
 	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOTDIR, filepath_setup}, {
 	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	(char *)-1, "negative address", EFAULT, no_setup}, {
+	NULL, "negative address", EFAULT, no_setup}, {
 	NULL, NULL, 0, no_setup}
 };
 
@@ -196,10 +182,9 @@ int main(int ac, char **av)
 			fname = Test_cases[ind].pathname;
 			desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (fname == High_address)
-				fname = get_high_address();
-#endif
+			if (!fname)
+				fname = tst_get_bad_addr(cleanup);
+
 			/*
 			 *  Call unlink(2)
 			 */
@@ -245,12 +230,6 @@ void setup(void)
 
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[7].pathname = bad_addr;
-
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
 		Test_cases[ind].setupfunc();
 	}
-- 
1.8.3.1




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

* [LTP] [PATCH v3 2/4] syscalls/unlink05, 06: Cleanup && Convert to new API
  2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
@ 2018-02-14  6:19           ` Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 3/4] syscalls/unlink07: " Xiao Yang
                             ` (2 subsequent siblings)
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-14  6:19 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Merge unlink06 into unlink05

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/quickhit                            |   2 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/unlink/unlink05.c | 253 +++++++---------------------
 testcases/kernel/syscalls/unlink/unlink06.c | 215 -----------------------
 7 files changed, 62 insertions(+), 412 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 49d2b11..21d31ad 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -964,7 +964,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/quickhit b/runtest/quickhit
index 2a42769..8264b22 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -255,8 +255,6 @@ uname01 uname01
 # Basic test for uname(2)
 unlink05 unlink05
 # Basic test for unlink(2)
-unlink06 unlink06
-# unlink(2) of a FIFO
 unlink07 unlink07
 # unlink(2) negative testcases
 unlink08 unlink08
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 004bbad..261c5f9 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -840,7 +840,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/syscalls b/runtest/syscalls
index ca84c10..7c3cd5b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 684f5e7..e67d726 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1082,7 +1082,6 @@
 /uname/uname02
 /uname/uname03
 /unlink/unlink05
-/unlink/unlink06
 /unlink/unlink07
 /unlink/unlink08
 /unlinkat/unlinkat01
diff --git a/testcases/kernel/syscalls/unlink/unlink05.c b/testcases/kernel/syscalls/unlink/unlink05.c
index aa49316..5305e94 100644
--- a/testcases/kernel/syscalls/unlink/unlink05.c
+++ b/testcases/kernel/syscalls/unlink/unlink05.c
@@ -1,209 +1,80 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
  */
-/* $Id: unlink05.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for unlink(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.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-void create_file();
 
-char *TCID = "unlink05";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
+/*
+ * Description:
+ * The testcase checks the basic functionality of the unlink(2).
+ * 1) unlink() can delete regular file successfully.
+ * 2) unlink() can delete fifo file successfully.
+ */
 
-int main(int ac, char **av)
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+
+static void file_create(char *);
+static void fifo_create(char *);
+
+static struct test_case_t {
+	void (*setupfunc)(char *);
+	char *desc;
+} tcases[] = {
+	{file_create, "file"},
+	{fifo_create, "fifo"},
+};
+
+static void file_create(char *name)
 {
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "unlink(%s) returned %ld",
-				 fname, TEST_RETURN);
-			/* recreate file for next loop */
-			create_file();
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	sprintf(name, "tfile_%d", getpid());
+	SAFE_TOUCH(name, 0777, NULL);
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void fifo_create(char *name)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	create_file();
+	sprintf(name, "tfifo_%d", getpid());
+	SAFE_MKFIFO(name, 0777);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void verify_unlink(unsigned int n)
 {
+	char fname[255];
+	struct test_case_t *tc = &tcases[n];
 
-	tst_rmdir();
-
-}
+	tc->setupfunc(fname);
 
-void create_file(void)
-{
-	sprintf(fname, "tfile_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+	TEST(unlink(fname));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "unlink(%s) failed", tc->desc);
+		return;
 	}
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+
+	if (!access(fname, F_OK)) {
+		tst_res(TFAIL, "unlink(%s) succeeded, but %s still existed",
+			tc->desc, tc->desc);
+		return;
 	}
+
+	tst_res(TPASS, "unlink(%s) succeeded", tc->desc);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
diff --git a/testcases/kernel/syscalls/unlink/unlink06.c b/testcases/kernel/syscalls/unlink/unlink06.c
deleted file mode 100644
index 0e38480..0000000
--- a/testcases/kernel/syscalls/unlink/unlink06.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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/
- *
- */
-/* $Id: unlink06.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink06
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) of a FIFO
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void create_file();
-void cleanup();
-
-char *TCID = "unlink06";
-int TST_TOTAL = 1;
-
-char Fname[255];
-
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		create_file();
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(Fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 Fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			if (access(Fname, F_OK) != -1) {
-				tst_resm(TFAIL,
-					 "unlink(%s) returned %ld, but access says file still exists.",
-					 Fname, TEST_RETURN);
-			} else {
-				tst_resm(TPASS, "unlink(%s) returned %ld",
-					 Fname, TEST_RETURN);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(Fname, "fifo_unlink%d", getpid());
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-void create_file(void)
-{
-	SAFE_MKFIFO(cleanup, Fname, 0777);
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v3 3/4] syscalls/unlink07: Cleanup && Convert to new API
  2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
@ 2018-02-14  6:19           ` Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 4/4] syscalls/unlink08: " Xiao Yang
  2018-02-20 16:08           ` [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-14  6:19 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove duplicate tests for EFAULT

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink07.c | 321 ++++++----------------------
 1 file changed, 60 insertions(+), 261 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 7eb8388..b03b984 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -1,287 +1,86 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns ENOENT if file doesn't exist.
+ * 2) unlink() returns ENOENT if path is empty.
+ * 3) unlink() returns ENOENT if path contains a non-existent file.
+ * 4) unlink() returns EFAULT if address beyond address space.
+ * 5) unlink() returns ENOTDIR if path contains a regular file.
+ * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+ * 7) unlink() returns EFAULT if address is negative.
  */
-/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink07
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-8) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
 #include <errno.h>
 #include <string.h>
-#include <signal.h>
 #include <unistd.h>
-#include <sys/param.h>		/* for PATH_MAX */
-#include "test.h"
+#include <sys/param.h>	/* for PATH_MAX */
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+static char longpathname[PATH_MAX + 2];
 
-char *TCID = "unlink07";
-int TST_TOTAL = 6;
-
-int longpath_setup();
-int no_setup();
-int filepath_setup();
-char Longpathname[PATH_MAX + 2];
-char High_address[64];
-
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{
-	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
-	"", "path is empty string", ENOENT, no_setup}, {
-	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup}, {
-	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup}, {
-	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	NULL, "negative address", EFAULT, no_setup}, {
-	NULL, NULL, 0, no_setup}
+} tcases[] = {
+	{"nonexistfile", "non-existent file", ENOENT},
+	{"", "path is empty string", ENOENT},
+	{"nefile/file", "path contains a non-existent file", ENOENT},
+	{NULL, "negative address", EFAULT},
+	{"file/file", "path contains a regular file", ENOTDIR},
+	{longpathname, "pathname too long", ENAMETOOLONG},
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
+static void verify_unlink(unsigned int n)
 {
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			if (!fname)
-				fname = tst_get_bad_addr(cleanup);
+	struct test_case_t *tc = &tcases[n];
 
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO ==
-				    Test_cases[ind].exp_errno)
-					tst_resm(TPASS,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				else
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-						 desc, TEST_ERRNO,
-						 Test_cases
-						 [ind].exp_errno);
-			} else {
-				tst_resm(TFAIL,
-					 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-					 desc, TEST_RETURN,
-					 Test_cases[ind].exp_errno);
-			}
-		}
+	if (!tc->name)
+		tc->name = tst_get_bad_addr();
 
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int ind;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		Test_cases[ind].setupfunc();
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void setup(void)
 {
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(void)
-{
-	return 0;
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int longpath_setup(void)
-{
-	int ind;
-
-	for (ind = 0; ind <= PATH_MAX + 1; ind++) {
-		Longpathname[ind] = 'a';
-	}
-	return 0;
+	SAFE_TOUCH("file", 0777, NULL);
 
+	memset(longpathname, 'a', PATH_MAX + 2);
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int filepath_setup(void)
-{
-	int fd;
-
-	if ((fd = creat("file", 0777)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s",
-			 errno, strerror(errno));
-	}
-	close(fd);
-	return 0;
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v3 4/4] syscalls/unlink08: Cleanup && Convert to new API
  2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
  2018-02-14  6:19           ` [LTP] [PATCH v3 3/4] syscalls/unlink07: " Xiao Yang
@ 2018-02-14  6:19           ` Xiao Yang
  2018-02-20 16:08           ` [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
  3 siblings, 0 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-14  6:19 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove unused code

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink08.c | 402 ++++++----------------------
 1 file changed, 79 insertions(+), 323 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index 9829a7c..699af2a 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -1,355 +1,111 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
  */
-/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink08
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-3) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
 
-void setup(void);
-void cleanup(void);
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns EACCES when deleting file in unwritable directory
+ *    as an unprivileged user.
+ * 2) unlink() returns EACCES when deleting file in "unsearchable directory
+ *    as an unprivileged user.
+ * 3) unlink() returns EISDIR when deleting directory in linux.
+ * 4) unlink() returns EPERM when deleting directory in non-linux.
+ */
 
-char *TCID = "unlink08";
-int TST_TOTAL = 3;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
 
-int unwrite_dir_setup(int flag);
-int unsearch_dir_setup(int flag);
-int dir_setup(int flag);
-int no_setup(int flag);
+static struct passwd *pw;
 
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
-	int (*setupfunc) (int flag);
-	int exp_ret;		/* -1 means error, 0 means != -1 */
 	int exp_errno;
-} Test_cases[] = {
-	{
-	"unwrite_dir/file", "unwritable directory", unwrite_dir_setup,
-		    -1, EACCES}, {
-	"unsearch_dir/file", "unsearchable directory",
-		    unsearch_dir_setup, -1, EACCES},
-#ifdef linux
-	{
-	"regdir", "directory", dir_setup, -1, EISDIR},
+	int exp_user;
+} tcases[] = {
+	{"unwrite_dir/file", "unwritable directory", EACCES, 1},
+	{"unsearch_dir/file", "unsearchable directory", EACCES, 1},
+#ifdef __linux__
+	{"regdir", "directory", EISDIR, 0},
 #else
-	{
-	"regdir", "directory", dir_setup, -1, EPERM},
+	{"regdir", "directory", EPERM, 0},
 #endif
-	{
-	NULL, NULL, no_setup, -1, 0}
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (Test_cases[ind].exp_ret == -1) {	/* neg test */
-					if (TEST_ERRNO ==
-					    Test_cases[ind].exp_errno)
-						tst_resm(TPASS,
-							 "unlink(<%s>) Failed, errno=%d",
-							 desc,
-							 TEST_ERRNO);
-					else
-						tst_resm(TFAIL,
-							 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-							 desc,
-							 TEST_ERRNO,
-							 Test_cases
-							 [ind].exp_errno);
-				} else {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				}
-			} else {
-				if (Test_cases[ind].exp_ret == -1) {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-						 desc, TEST_RETURN,
-						 Test_cases[ind].exp_errno);
-				} else {
-					tst_resm(TPASS,
-						 "unlink(<%s>) returned %ld",
-						 desc, TEST_RETURN);
-				}
-				Test_cases[ind].setupfunc(1);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void verify_unlink(struct test_case_t *tc)
 {
-	int ind;
-	int postest = 0;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (geteuid() == 0) {
-		postest++;
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (Test_cases[ind].exp_errno == EACCES && postest)
-			Test_cases[ind].exp_ret = 0;	/* set as a pos test */
-		Test_cases[ind].setupfunc(0);
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unwrite_dir_setup(int flag)
+static void do_unlink(unsigned int n)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
+	struct test_case_t *cases = &tcases[n];
+	pid_t pid;
+
+	if (cases->exp_user) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			SAFE_SETUID(pw->pw_uid);
+			verify_unlink(cases);
+			exit(0);
 		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0777);
 
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		verify_unlink(cases);
 	}
-	return 0;
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unsearch_dir_setup(int flag)
+static void setup(void)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unsearch_dir", 0777);
-
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("unwrite_dir", 0777);
+	SAFE_TOUCH("unwrite_dir/file", 0777, NULL);
+	SAFE_CHMOD("unwrite_dir", 0555);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0777);
+	SAFE_MKDIR("unsearch_dir", 0777);
+	SAFE_TOUCH("unsearch_dir/file", 0777, NULL);
+	SAFE_CHMOD("unsearch_dir", 0666);
 
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("regdir", 0777);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	}
-	return 0;
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int dir_setup(int flag)
-{
-	SAFE_MKDIR(cleanup, "regdir", 0777);
-	return 0;
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(int flag)
-{
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = do_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
                             ` (2 preceding siblings ...)
  2018-02-14  6:19           ` [LTP] [PATCH v3 4/4] syscalls/unlink08: " Xiao Yang
@ 2018-02-20 16:08           ` Cyril Hrubis
  2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
  3 siblings, 1 reply; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-20 16:08 UTC (permalink / raw)
  To: ltp

Hi!
> +			if (!fname1)
> +				fname1 = tst_get_bad_addr(cleanup);

Here we should call the function only once in the setup() since this
will allocate two pages of memory for each test iteration and the test
may get out of memory if we pass large enough -i parameter.

I would do something similar in test setup():

	void *bad_add = tst_get_bad_addr(NULL);

	loop over test structure {
		if (!tc->fname)
			tc->fname = bad_addr;
	}

> -			if (fname2 == high_addr)
> -				fname2 = get_high_address();
> -#endif
> +			if (!fname2)
> +				fname2 = tst_get_bad_addr(cleanup);
>  
>  			TEST(link(fname1, fname2));
>  
> @@ -166,13 +152,6 @@ static void setup(void)
>  
>  	tst_tmpdir();
>  
> -#if !defined(UCLINUX)
> -	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
> -	                     MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	test_cases[6].file1 = bad_addr;
> -	test_cases[12].file2 = bad_addr;
> -#endif
> -
>  	memset(longpath, 'a', PATH_MAX+1);
>  	SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
>  	SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
> diff --git a/testcases/kernel/syscalls/lstat/lstat02.c b/testcases/kernel/syscalls/lstat/lstat02.c
> index ab46787..15285e7 100644
> --- a/testcases/kernel/syscalls/lstat/lstat02.c
> +++ b/testcases/kernel/syscalls/lstat/lstat02.c
> @@ -59,10 +59,10 @@
>  static char longpathname[PATH_MAX + 2];
>  static char elooppathname[sizeof(TEST_ELOOP) * 43] = ".";
>  
> -#if !defined(UCLINUX)
> +static void setup(void);
> +static void lstat_verify(int);
> +static void cleanup(void);
>  static void bad_addr_setup(int);
> -static void high_address_setup(int);
> -#endif
>  
>  static struct test_case_t {
>  	char *pathname;
> @@ -71,10 +71,7 @@ static struct test_case_t {
>  } test_cases[] = {
>  	{TEST_EACCES, EACCES, NULL},
>  	{TEST_ENOENT, ENOENT, NULL},
> -#if !defined(UCLINUX)
>  	{NULL, EFAULT, bad_addr_setup},
> -	{NULL, EFAULT, high_address_setup},
> -#endif
>  	{longpathname, ENAMETOOLONG, NULL},
>  	{TEST_ENOTDIR, ENOTDIR, NULL},
>  	{elooppathname, ELOOP, NULL},
> @@ -83,10 +80,6 @@ static struct test_case_t {
>  char *TCID = "lstat02";
>  int TST_TOTAL = ARRAY_SIZE(test_cases);
>  
> -static void setup(void);
> -static void lstat_verify(int);
> -static void cleanup(void);
> -
>  int main(int ac, char **av)
>  {
>  	int lc;
> @@ -140,18 +133,10 @@ static void setup(void)
>  		strcat(elooppathname, TEST_ELOOP);
>  }
>  
> -#if !defined(UCLINUX)
>  static void bad_addr_setup(int i)
>  {
> -	test_cases[i].pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
> -					   MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
> -}
> -
> -static void high_address_setup(int i)
> -{
> -	test_cases[i].pathname = (char *)get_high_address();
> +	test_cases[i].pathname = tst_get_bad_addr(cleanup);
>  }
> -#endif
>  
>  static void lstat_verify(int i)
>  {
> diff --git a/testcases/kernel/syscalls/mkdir/mkdir01.c b/testcases/kernel/syscalls/mkdir/mkdir01.c
> index 9839a09..84012c0 100644
> --- a/testcases/kernel/syscalls/mkdir/mkdir01.c
> +++ b/testcases/kernel/syscalls/mkdir/mkdir01.c
> @@ -116,7 +116,7 @@ void setup();
>  void cleanup();
>  
>  char *TCID = "mkdir01";
> -int TST_TOTAL = 2;
> +int TST_TOTAL = 1;
>  
>  char *bad_addr = 0;
>  
> @@ -161,37 +161,6 @@ int main(int ac, char **av)
>  				 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");
>  
>  		}
> -#if !defined(UCLINUX)
> -		/*
> -		 * TEST CASE: 2
> -		 * mkdir() call with pointer above allocated address space.
> -		 */
> -
> -		/* Call mkdir(2) */
> -		TEST(mkdir(get_high_address(), 0777));
> -
> -		/* check return code */
> -		if (TEST_RETURN == -1) {
> -		}
> -
> -		if (TEST_RETURN == -1) {
> -			if (TEST_ERRNO == EFAULT) {
> -				tst_resm(TPASS,
> -					 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
> -					 TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			} else {
> -				tst_resm(TFAIL,
> -					 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
> -					 TEST_ERRNO,
> -					 strerror(TEST_ERRNO), EFAULT);
> -			}
> -		} else {
> -			tst_resm(TFAIL,
> -				 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");
> -
> -		}
> -#endif /* if !defined(UCLINUX) */
>  
>  	}
>  
> @@ -212,11 +181,7 @@ void setup(void)
>  	/* Create a temporary directory and make it current. */
>  	tst_tmpdir();
>  
> -	bad_addr = mmap(0, 1, PROT_NONE,
> -			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	if (bad_addr == MAP_FAILED) {
> -		tst_brkm(TBROK, cleanup, "mmap failed");
> -	}
> +	bad_addr = tst_get_bad_addr(cleanup);
>  }
>  
>  /***************************************************************
> diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c
> index a8ee5ba..a128912 100644
> --- a/testcases/kernel/syscalls/mknod/mknod06.c
> +++ b/testcases/kernel/syscalls/mknod/mknod06.c
> @@ -93,7 +93,6 @@ int setup3();			/* setup function to test mknod for ENOTDIR */
>  int longpath_setup();		/* setup function to test mknod for ENAMETOOLONG */
>  int no_setup();			/* simply returns 0 to the caller */
>  char Longpathname[PATH_MAX + 2];
> -char High_address_node[64];
>  
>  struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  	char *pathname;
> @@ -101,15 +100,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  	int exp_errno;
>  	int (*setupfunc) ();
>  } Test_cases[] = {
> -	{
> -	"tnode_1", "Specified node already exists", EEXIST, setup1},
> -#if !defined(UCLINUX)
> -	{
> -	(char *)-1, "Negative address", EFAULT, no_setup}, {
> -	High_address_node, "Address beyond address space", EFAULT,
> -		    no_setup},
> -#endif
> -	{
> +	{"tnode_1", "Specified node already exists", EEXIST, setup1}, {
> +	NULL, "Negative address", EFAULT, no_setup}, {
              ^
	      This should say "Invalid address" now.

>  	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
>  	"", "Pathname is empty", ENOENT, no_setup}, {
>  	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
> @@ -119,12 +111,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  
>  char *TCID = "mknod06";
>  int TST_TOTAL = ARRAY_SIZE(Test_cases);
> -#if !defined(UCLINUX)
> -extern char *get_high_address();
> -#else
> -#endif
> -
> -char *bad_addr = 0;
>  
>  void setup();			/* setup function for the tests */
>  void cleanup();			/* cleanup function for the tests */
> @@ -152,11 +138,8 @@ int main(int ac, char **av)
>  			node_name = Test_cases[ind].pathname;
>  			test_desc = Test_cases[ind].desc;
>  
> -#if !defined(UCLINUX)
> -			if (node_name == High_address_node) {
> -				node_name = get_high_address();
> -			}
> -#endif
> +			if (!node_name)
> +				node_name = tst_get_bad_addr(cleanup);

Here as well, the tst_get_bad_addr() should be called only once in the
test setup.

> diff --git a/testcases/kernel/syscalls/stat/stat03.c b/testcases/kernel/syscalls/stat/stat03.c
> index ef3d937..b0e4e89 100644
> --- a/testcases/kernel/syscalls/stat/stat03.c
> +++ b/testcases/kernel/syscalls/stat/stat03.c
> @@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";
>  struct passwd *ltpuser;
>  
>  char Longpathname[PATH_MAX + 2];
> -char High_address_node[64];
>  
>  struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  	char *pathname;
> @@ -111,15 +110,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  	int exp_errno;
>  	int (*setupfunc) ();
>  } Test_cases[] = {
> -	{
> -	TEST_FILE1, "No Search permissions to process", EACCES, setup1},
> -#if !defined(UCLINUX)
> -	{
> -	High_address_node, "Address beyond address space", EFAULT, no_setup},
> -	{
> -	(char *)-1, "Negative address", EFAULT, no_setup},
> -#endif
> -	{
> +	{TEST_FILE1, "No Search permissions to process", EACCES, setup1}, {
> +	NULL, "Negative address", EFAULT, no_setup}, {
                 ^
		 Here as well, should be changed to "Invalid address"

>  	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
>  	"", "Pathname is empty", ENOENT, no_setup}, {
>  	TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {
> @@ -129,8 +121,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  char *TCID = "stat03";
>  int TST_TOTAL = ARRAY_SIZE(Test_cases);
>  
> -char *bad_addr = 0;
> -
>  void setup();			/* Main setup function for the tests */
>  void cleanup();			/* cleanup function for the test */
>  
> @@ -158,11 +148,8 @@ int main(int ac, char **av)
>  			file_name = Test_cases[ind].pathname;
>  			test_desc = Test_cases[ind].desc;
>  
> -#if !defined(UCLINUX)
> -			if (file_name == High_address_node) {
> -				file_name = (char *)get_high_address();
> -			}
> -#endif
> +			if (!file_name)
> +				file_name = tst_get_bad_addr(cleanup);

Here as well the function should be called once in the test setup.

>  			/*
>  			 * Call stat(2) to test different test conditions.
> @@ -237,15 +224,6 @@ void setup(void)
>  	/* Make a temp dir and cd to it */
>  	tst_tmpdir();
>  
> -#if !defined(UCLINUX)
> -	bad_addr = mmap(0, 1, PROT_NONE,
> -			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	if (bad_addr == MAP_FAILED) {
> -		tst_brkm(TBROK, cleanup, "mmap failed");
> -	}
> -	Test_cases[2].pathname = bad_addr;
> -#endif
> -
>  	/* call individual setup functions */
>  	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
>  		Test_cases[ind].setupfunc();
> diff --git a/testcases/kernel/syscalls/symlink/symlink03.c b/testcases/kernel/syscalls/symlink/symlink03.c
> index 89f23c9..f1c0d6e 100644
> --- a/testcases/kernel/syscalls/symlink/symlink03.c
> +++ b/testcases/kernel/syscalls/symlink/symlink03.c
> @@ -103,8 +103,6 @@
>  char *TCID = "symlink03";
>  int TST_TOTAL = 1;
>  
> -char *bad_addr = 0;
> -
>  int no_setup();
>  int setup1();			/* setup function to test symlink for EACCES */
>  int setup2();			/* setup function to test symlink for EEXIST */
> @@ -121,18 +119,11 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
>  	int exp_errno;
>  	int (*setupfunc) ();
>  } Test_cases[] = {
> -	{
> -	TEST_FILE1, SYM_FILE1, "No Search permissions to process",
> +	{TEST_FILE1, SYM_FILE1, "No Search permissions to process",
>  		    EACCES, setup1}, {
>  	TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
> -		    EEXIST, setup2},
> -#if !defined(UCLINUX)
> -	{
> -	TESTFILE, High_address_node, "Address beyond address space",
> -		    EFAULT, no_setup},
> -#endif
> -	{
> -	TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, {
> +		    EEXIST, setup2}, {
> +	TESTFILE, NULL, "Negative address", EFAULT, no_setup}, {
                           ^
			   And here as well.
>  	TESTFILE, Longpathname, "Symlink path too long", ENAMETOOLONG,
>  		    longpath_setup}, {
>  	TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
> @@ -171,11 +162,9 @@ int main(int ac, char **av)
>  			test_file = Test_cases[ind].file;
>  			sym_file = Test_cases[ind].link;
>  			test_desc = Test_cases[ind].desc;
> -#if !defined(UCLINUX)
> -			if (sym_file == High_address_node) {
> -				sym_file = (char *)get_high_address();
> -			}
> -#endif
> +
> +			if (!sym_file)
> +				sym_file = tst_get_bad_addr(cleanup);

And here as well.

>  			/*
>  			 * Call symlink(2) to test different test conditions.
>  			 * verify that it fails with -1 return value and sets
> @@ -241,15 +230,6 @@ void setup(void)
>  
>  	tst_tmpdir();
>  
> -#if !defined(UCLINUX)
> -	bad_addr = mmap(0, 1, PROT_NONE,
> -			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	if (bad_addr == MAP_FAILED) {
> -		tst_brkm(TBROK, cleanup, "mmap failed");
> -	}
> -	Test_cases[3].link = bad_addr;
> -#endif
> -
>  	/* call individual setup functions */
>  	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
>  		Test_cases[ind].setupfunc();
> diff --git a/testcases/kernel/syscalls/truncate/truncate03.c b/testcases/kernel/syscalls/truncate/truncate03.c
> index 0aa7b3e..041bdfb 100644
> --- a/testcases/kernel/syscalls/truncate/truncate03.c
> +++ b/testcases/kernel/syscalls/truncate/truncate03.c
> @@ -76,10 +76,7 @@ static struct test_case_t {
>  } test_cases[] = {
>  	{ TEST_FILE1, TRUNC_LEN, EACCES },
>  	{ TEST_FILE2, TRUNC_LEN, ENOTDIR },
> -#if !defined(UCLINUX)
>  	{ NULL, TRUNC_LEN, EFAULT },
> -	{ (char *)-1, TRUNC_LEN, EFAULT },
> -#endif
>  	{ long_pathname, TRUNC_LEN, ENAMETOOLONG },
>  	{ "", TRUNC_LEN, ENOENT },
>  	{ TEST_DIR1, TRUNC_LEN, EISDIR },
> @@ -117,7 +114,6 @@ int main(int ac, char **av)
>  void setup(void)
>  {
>  	struct passwd *ltpuser;
> -	char *bad_addr;
>  	struct rlimit rlim;
>  	sigset_t signalset;
>  
> @@ -136,14 +132,6 @@ void setup(void)
>  
>  	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);
>  
> -#if !defined(UCLINUX)
> -	test_cases[2].pathname = (char *)get_high_address();
> -
> -	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
> -			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
> -	test_cases[3].pathname = bad_addr;
> -#endif
> -
>  	memset(long_pathname, 'a', PATH_MAX + 1);
>  
>  	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);
> @@ -166,6 +154,9 @@ void setup(void)
>  
>  void truncate_verify(struct test_case_t *tc)
>  {
> +	if (!tc->pathname)
> +		tc->pathname = tst_get_bad_addr(cleanup);

And here as well.

>  	TEST(truncate(tc->pathname, tc->length));
>  
>  	if (TEST_RETURN != -1) {
> diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
> index 66e4db8..7eb8388 100644
> --- a/testcases/kernel/syscalls/unlink/unlink07.c
> +++ b/testcases/kernel/syscalls/unlink/unlink07.c
> @@ -123,13 +123,9 @@
>  void setup();
>  void cleanup();
>  
> -extern char *get_high_address();
> -
>  char *TCID = "unlink07";
>  int TST_TOTAL = 6;
>  
> -char *bad_addr = 0;
> -
>  int longpath_setup();
>  int no_setup();
>  int filepath_setup();
> @@ -146,21 +142,11 @@ struct test_case_t {
>  	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
>  	"", "path is empty string", ENOENT, no_setup}, {
>  	"nefile/file", "path contains a non-existent file",
> -		    ENOENT, no_setup},
> -#if !defined(UCLINUX)
> -	{
> -	High_address, "address beyond address space", EFAULT, no_setup},
> -#endif
> -	{
> +		    ENOENT, no_setup}, {
>  	"file/file", "path contains a regular file",
> -		    ENOTDIR, filepath_setup},
> -#if !defined(UCLINUX)
> -	{
> -	High_address, "address beyond address space", EFAULT, no_setup},
> -#endif
> -	{
> +		    ENOTDIR, filepath_setup}, {
>  	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
> -	(char *)-1, "negative address", EFAULT, no_setup}, {
> +	NULL, "negative address", EFAULT, no_setup}, {
                ^
		And here as well.

>  	NULL, NULL, 0, no_setup}
>  };
>  
> @@ -196,10 +182,9 @@ int main(int ac, char **av)
>  			fname = Test_cases[ind].pathname;
>  			desc = Test_cases[ind].desc;
>  
> -#if !defined(UCLINUX)
> -			if (fname == High_address)
> -				fname = get_high_address();
> -#endif
> +			if (!fname)
> +				fname = tst_get_bad_addr(cleanup);

And here as well.


-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v4 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-20 16:08           ` [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
@ 2018-02-22  5:48             ` Xiao Yang
  2018-02-22  5:48               ` [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
                                 ` (3 more replies)
  0 siblings, 4 replies; 25+ messages in thread
From: Xiao Yang @ 2018-02-22  5:48 UTC (permalink / raw)
  To: ltp

1) Use mmap() with PROT_NONE to get a bad address and rename get_high_address
   as tst_get_bad_addr
2) Make sure tst_get_bad_addr can be used by both new API and old API
3) Apply tst_get_bad_addr and remove duplicate tests for EFAULT
4) Just use sbrk(0) + 4 * PAGE_SIZE to test ENOMEM in msync03
5) Remove UCLINUX

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 include/old/test.h                              |  4 +--
 include/tst_get_bad_addr.h                      | 25 ++++++++++++++
 include/tst_test.h                              |  1 +
 lib/get_high_address.c                          | 40 ----------------------
 lib/tst_get_bad_addr.c                          | 31 +++++++++++++++++
 testcases/kernel/syscalls/lchown/lchown02.c     | 28 ++--------------
 testcases/kernel/syscalls/link/link04.c         | 43 ++++++++----------------
 testcases/kernel/syscalls/lstat/lstat02.c       | 23 +++----------
 testcases/kernel/syscalls/mkdir/mkdir01.c       | 39 ++--------------------
 testcases/kernel/syscalls/mknod/mknod06.c       | 34 +++----------------
 testcases/kernel/syscalls/mremap/mremap03.c     | 13 +-------
 testcases/kernel/syscalls/msync/msync03.c       |  9 +----
 testcases/kernel/syscalls/rmdir/rmdir05.c       | 44 ++-----------------------
 testcases/kernel/syscalls/stat/stat03.c         | 31 +++--------------
 testcases/kernel/syscalls/symlink/symlink03.c   | 32 ++++--------------
 testcases/kernel/syscalls/truncate/truncate03.c | 19 ++++-------
 testcases/kernel/syscalls/unlink/unlink07.c     | 32 +++---------------
 17 files changed, 111 insertions(+), 337 deletions(-)
 create mode 100644 include/tst_get_bad_addr.h
 delete mode 100644 lib/get_high_address.c
 create mode 100644 lib/tst_get_bad_addr.c

diff --git a/include/old/test.h b/include/old/test.h
index 137ebb1..74d11a1 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -63,6 +63,7 @@
 #include "old_device.h"
 #include "old_tmpdir.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Ensure that NUMSIGS is defined.
@@ -203,9 +204,6 @@ extern int tst_count;
 /* lib/tst_sig.c */
 void tst_sig(int fork_flag, void (*handler)(), void (*cleanup)());
 
-/* lib/get_high_address.c */
-char *get_high_address(void);
-
 /* lib/self_exec.c */
 void maybe_run_child(void (*child)(), const char *fmt, ...);
 int self_exec(const char *argv0, const char *fmt, ...);
diff --git a/include/tst_get_bad_addr.h b/include/tst_get_bad_addr.h
new file mode 100644
index 0000000..aed1752
--- /dev/null
+++ b/include/tst_get_bad_addr.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TST_GET_BAD_ADDR_H__
+#define TST_GET_BAD_ADDR_H__
+
+/* Functions from lib/tst_get_bad_addr.c */
+void *tst_get_bad_addr(void (*cleanup_fn) (void));
+
+#endif	/* TST_GET_BAD_ADDR_H__ */
diff --git a/include/tst_test.h b/include/tst_test.h
index eaf7a1f..af97b89 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -40,6 +40,7 @@
 #include "tst_clone.h"
 #include "tst_kernel.h"
 #include "tst_minmax.h"
+#include "tst_get_bad_addr.h"
 
 /*
  * Reports testcase result.
diff --git a/lib/get_high_address.c b/lib/get_high_address.c
deleted file mode 100644
index eed9cf1..0000000
--- a/lib/get_high_address.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* $Header: /cvsroot/ltp/ltp/lib/get_high_address.c,v 1.6 2009/07/20 10:59:32 vapier Exp $ */
-
-/*
- * 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/
- */
-
-#include <unistd.h>
-
-char *get_high_address(void)
-{
-	return (char *)sbrk(0) + (4 * getpagesize());
-}
diff --git a/lib/tst_get_bad_addr.c b/lib/tst_get_bad_addr.c
new file mode 100644
index 0000000..098e72b
--- /dev/null
+++ b/lib/tst_get_bad_addr.c
@@ -0,0 +1,31 @@
+/*
+ * 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 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/mman.h>
+#include "test.h"
+#include "tst_get_bad_addr.h"
+
+void *tst_get_bad_addr(void (*cleanup_fn) (void))
+{
+	void *bad_addr;
+
+	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+	if (bad_addr == MAP_FAILED)
+		tst_brkm(TBROK, cleanup_fn, "mmap() failed to get bad address");
+
+	return bad_addr;
+}
diff --git a/testcases/kernel/syscalls/lchown/lchown02.c b/testcases/kernel/syscalls/lchown/lchown02.c
index 326e584..97966f6 100644
--- a/testcases/kernel/syscalls/lchown/lchown02.c
+++ b/testcases/kernel/syscalls/lchown/lchown02.c
@@ -74,12 +74,13 @@
 TCID_DEFINE(lchown02);
 int TST_TOTAL = 7;
 
+static void setup(void);
+static void cleanup(void);
 static void setup_eperm(int pos);
 static void setup_eacces(int pos);
 static void setup_enotdir(int pos);
 static void setup_longpath(int pos);
 static void setup_efault(int pos);
-static void setup_highaddress(int pos);
 
 static char path[PATH_MAX + 2];
 
@@ -93,7 +94,6 @@ struct test_case_t {
 static struct test_case_t test_cases[] = {
 	{SFILE1, "Process is not owner/root", EPERM, setup_eperm},
 	{SFILE2, "Search permission denied", EACCES, setup_eacces},
-	{NULL, "Address beyond address space", EFAULT, setup_highaddress},
 	{NULL, "Unaccessible address space", EFAULT, setup_efault},
 	{path, "Pathname too long", ENAMETOOLONG, setup_longpath},
 	{SFILE3, "Path contains regular file", ENOTDIR, setup_enotdir},
@@ -103,9 +103,6 @@ static struct test_case_t test_cases[] = {
 
 static struct passwd *ltpuser;
 
-static void setup(void);
-static void cleanup(void);
-
 int main(int argc, char *argv[])
 {
 	int lc;
@@ -252,26 +249,7 @@ static void setup_eacces(int pos LTP_ATTRIBUTE_UNUSED)
  */
 static void setup_efault(int pos)
 {
-	char *bad_addr = 0;
-
-	bad_addr = mmap(NULL, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, -1, 0);
-
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
-
-	test_cases[pos].pathname = bad_addr;
-}
-
-/*
- * setup_efault() -- setup for a test condition where lchown(2) returns -1 and
- *                   sets errno to EFAULT.
- *
- * Use ltp function get_high_address() to compute high address.
- */
-static void setup_highaddress(int pos)
-{
-	test_cases[pos].pathname = get_high_address();
+	test_cases[pos].pathname = tst_get_bad_addr(cleanup);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c
index 679753f..d940884 100644
--- a/testcases/kernel/syscalls/link/link04.c
+++ b/testcases/kernel/syscalls/link/link04.c
@@ -51,12 +51,7 @@
 #include "test.h"
 #include "safe_macros.h"
 
-static char *bad_addr = 0;
-
 static char longpath[PATH_MAX + 2];
-#if !defined(UCLINUX)
-char high_addr[64];
-#endif
 
 struct test_case_t {
 	char *file1;
@@ -73,10 +68,7 @@ struct test_case_t {
 	{"regfile/file", "path contains a regular file", "nefile", "nefile",
 	 ENOTDIR},
 	{longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{high_addr, "address beyond address space", "nefile", "nefile", EFAULT},
-#endif
-	{(char *)-1, "negative address", "nefile", "nefile", EFAULT},
+	{NULL, "invalid address", "nefile", "nefile", EFAULT},
 	/* second path is invalid */
 	{"regfile", "regfile", "", "empty string", ENOENT},
 	{"regfile", "regfile", "neefile/file",
@@ -84,11 +76,7 @@ struct test_case_t {
 	{"regfile", "regfile", "file/file",
 		    "path contains a regular file", ENOENT},
 	{"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG},
-#if !defined(UCLINUX)
-	{"regfile", "regfile", high_addr,
-		    "address beyond address space", EFAULT},
-#endif
-	{"regfile", "regfile", (char *)-1, "negative address", EFAULT},
+	{"regfile", "regfile", NULL, "invalid address", EFAULT},
 	/* two existing files */
 	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
 };
@@ -121,14 +109,6 @@ int main(int ac, char **av)
 			fname2 = test_cases[i].file2;
 			desc2 = test_cases[i].desc2;
 
-#if !defined(UCLINUX)
-			if (fname1 == high_addr)
-				fname1 = get_high_address();
-
-			if (fname2 == high_addr)
-				fname2 = get_high_address();
-#endif
-
 			TEST(link(fname1, fname2));
 
 			if (TEST_RETURN == -1) {
@@ -160,23 +140,28 @@ int main(int ac, char **av)
 
 static void setup(void)
 {
+	int n;
+
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-	                     MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[6].file1 = bad_addr;
-	test_cases[12].file2 = bad_addr;
-#endif
-
 	memset(longpath, 'a', PATH_MAX+1);
 	SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
 	SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
 	SAFE_MKDIR(cleanup, "dir", 0777);
+
+	void *bad_addr = tst_get_bad_addr(cleanup);
+
+	for (n = 0; n < TST_TOTAL; n++) {
+		if (!test_cases[n].file1)
+			test_cases[n].file1 = bad_addr;
+
+		if (!test_cases[n].file2)
+			test_cases[n].file2 = bad_addr;
+	}
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/lstat/lstat02.c b/testcases/kernel/syscalls/lstat/lstat02.c
index ab46787..15285e7 100644
--- a/testcases/kernel/syscalls/lstat/lstat02.c
+++ b/testcases/kernel/syscalls/lstat/lstat02.c
@@ -59,10 +59,10 @@
 static char longpathname[PATH_MAX + 2];
 static char elooppathname[sizeof(TEST_ELOOP) * 43] = ".";
 
-#if !defined(UCLINUX)
+static void setup(void);
+static void lstat_verify(int);
+static void cleanup(void);
 static void bad_addr_setup(int);
-static void high_address_setup(int);
-#endif
 
 static struct test_case_t {
 	char *pathname;
@@ -71,10 +71,7 @@ static struct test_case_t {
 } test_cases[] = {
 	{TEST_EACCES, EACCES, NULL},
 	{TEST_ENOENT, ENOENT, NULL},
-#if !defined(UCLINUX)
 	{NULL, EFAULT, bad_addr_setup},
-	{NULL, EFAULT, high_address_setup},
-#endif
 	{longpathname, ENAMETOOLONG, NULL},
 	{TEST_ENOTDIR, ENOTDIR, NULL},
 	{elooppathname, ELOOP, NULL},
@@ -83,10 +80,6 @@ static struct test_case_t {
 char *TCID = "lstat02";
 int TST_TOTAL = ARRAY_SIZE(test_cases);
 
-static void setup(void);
-static void lstat_verify(int);
-static void cleanup(void);
-
 int main(int ac, char **av)
 {
 	int lc;
@@ -140,18 +133,10 @@ static void setup(void)
 		strcat(elooppathname, TEST_ELOOP);
 }
 
-#if !defined(UCLINUX)
 static void bad_addr_setup(int i)
 {
-	test_cases[i].pathname = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-					   MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-}
-
-static void high_address_setup(int i)
-{
-	test_cases[i].pathname = (char *)get_high_address();
+	test_cases[i].pathname = tst_get_bad_addr(cleanup);
 }
-#endif
 
 static void lstat_verify(int i)
 {
diff --git a/testcases/kernel/syscalls/mkdir/mkdir01.c b/testcases/kernel/syscalls/mkdir/mkdir01.c
index 9839a09..84012c0 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir01.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir01.c
@@ -116,7 +116,7 @@ void setup();
 void cleanup();
 
 char *TCID = "mkdir01";
-int TST_TOTAL = 2;
+int TST_TOTAL = 1;
 
 char *bad_addr = 0;
 
@@ -161,37 +161,6 @@ int main(int ac, char **av)
 				 "mkdir - path argument pointing below allocated address space succeeded unexpectedly.");
 
 		}
-#if !defined(UCLINUX)
-		/*
-		 * TEST CASE: 2
-		 * mkdir() call with pointer above allocated address space.
-		 */
-
-		/* Call mkdir(2) */
-		TEST(mkdir(get_high_address(), 0777));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-		}
-
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT) {
-				tst_resm(TPASS,
-					 "mkdir - path argument pointing above allocated address space failed as expected with errno %d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "mkdir - path argument pointing above allocated address space failed with errno %d : %s but expected %d (EFAULT)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EFAULT);
-			}
-		} else {
-			tst_resm(TFAIL,
-				 "mkdir - path argument pointing above allocated address space succeeded unexpectedly.");
-
-		}
-#endif /* if !defined(UCLINUX) */
 
 	}
 
@@ -212,11 +181,7 @@ void setup(void)
 	/* Create a temporary directory and make it current. */
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 /***************************************************************
diff --git a/testcases/kernel/syscalls/mknod/mknod06.c b/testcases/kernel/syscalls/mknod/mknod06.c
index a8ee5ba..8f70cf0 100644
--- a/testcases/kernel/syscalls/mknod/mknod06.c
+++ b/testcases/kernel/syscalls/mknod/mknod06.c
@@ -93,7 +93,6 @@ int setup3();			/* setup function to test mknod for ENOTDIR */
 int longpath_setup();		/* setup function to test mknod for ENAMETOOLONG */
 int no_setup();			/* simply returns 0 to the caller */
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -101,15 +100,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	"tnode_1", "Specified node already exists", EEXIST, setup1},
-#if !defined(UCLINUX)
-	{
-	(char *)-1, "Negative address", EFAULT, no_setup}, {
-	High_address_node, "Address beyond address space", EFAULT,
-		    no_setup},
-#endif
-	{
+	{"tnode_1", "Specified node already exists", EEXIST, setup1}, {
+	NULL, "Invalid address", EFAULT, no_setup}, {
 	"testdir_2/tnode_2", "Non-existent file", ENOENT, no_setup}, {
 	"", "Pathname is empty", ENOENT, no_setup}, {
 	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
@@ -119,12 +111,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 
 char *TCID = "mknod06";
 int TST_TOTAL = ARRAY_SIZE(Test_cases);
-#if !defined(UCLINUX)
-extern char *get_high_address();
-#else
-#endif
-
-char *bad_addr = 0;
 
 void setup();			/* setup function for the tests */
 void cleanup();			/* cleanup function for the tests */
@@ -152,12 +138,6 @@ int main(int ac, char **av)
 			node_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (node_name == High_address_node) {
-				node_name = get_high_address();
-			}
-#endif
-
 			/*
 			 * Call mknod(2) to test different test conditions.
 			 * verify that it fails with -1 return value and
@@ -217,16 +197,10 @@ void setup(void)
 	/* Make a temp dir and cd to it */
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
-#endif
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
+		if (!Test_cases[ind].pathname)
+			Test_cases[ind].pathname = tst_get_bad_addr(cleanup);
 		Test_cases[ind].setupfunc();
 	}
 }
diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c
index 5cd1a67..a85e986 100644
--- a/testcases/kernel/syscalls/mremap/mremap03.c
+++ b/testcases/kernel/syscalls/mremap/mremap03.c
@@ -92,7 +92,6 @@ int newsize;			/* new size of virtual memory block */
 void setup();			/* Main setup function of test */
 void cleanup();			/* cleanup function for the test */
 
-#if !defined(UCLINUX)
 int main(int ac, char **av)
 {
 	int lc;
@@ -174,7 +173,7 @@ void setup(void)
 	 * Set the old virtual address point to some address
 	 * which is not mapped.
 	 */
-	bad_addr = (char *)get_high_address();
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 /*
@@ -187,13 +186,3 @@ void cleanup(void)
 	/* Exit the program */
 
 }
-
-#else
-
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
diff --git a/testcases/kernel/syscalls/msync/msync03.c b/testcases/kernel/syscalls/msync/msync03.c
index 2e072ca..f504ed1 100644
--- a/testcases/kernel/syscalls/msync/msync03.c
+++ b/testcases/kernel/syscalls/msync/msync03.c
@@ -57,10 +57,7 @@ static int fd;
 static char *addr1;
 static char *addr2;
 static char *addr3;
-
-#if !defined(UCLINUX)
 static char *addr4;
-#endif
 
 static size_t page_sz;
 
@@ -74,9 +71,7 @@ static struct test_case_t {
 	{ &addr1, INV_SYNC, EINVAL },
 	{ &addr2, MS_SYNC, EINVAL },
 	{ &addr3, MS_SYNC, EINVAL },
-#if !defined(UCLINUX)
 	{ &addr4, MS_SYNC, ENOMEM },
-#endif
 };
 
 static void msync_verify(struct test_case_t *tc);
@@ -135,10 +130,8 @@ static void setup(void)
 	SAFE_GETRLIMIT(NULL, RLIMIT_DATA, &rl);
 	addr3 = (char *)rl.rlim_max;
 
-#if !defined(UCLINUX)
 	/* memory pointed to by addr4 was not mapped */
-	addr4 = get_high_address();
-#endif
+	addr4 = sbrk(0) + (4 * page_sz);
 }
 
 static void msync_verify(struct test_case_t *tc)
diff --git a/testcases/kernel/syscalls/rmdir/rmdir05.c b/testcases/kernel/syscalls/rmdir/rmdir05.c
index bef3b47..0eb54f0 100644
--- a/testcases/kernel/syscalls/rmdir/rmdir05.c
+++ b/testcases/kernel/syscalls/rmdir/rmdir05.c
@@ -50,12 +50,7 @@
 static void setup(void);
 static void cleanup(void);
 
-#if !defined(UCLINUX)
-extern char *get_high_address();
-int TST_TOTAL = 6;
-#else
-int TST_TOTAL = 4;
-#endif
+int TST_TOTAL = 5;
 
 char *TCID = "rmdir05";
 
@@ -119,7 +114,6 @@ int main(int argc, char **argv)
 		 * TEST CASE: 4
 		 * path argument points below the minimum allocated address space
 		 */
-#if !defined(UCLINUX)
 		TEST(rmdir(bad_addr));
 
 		if (TEST_RETURN == -1) {
@@ -144,34 +138,6 @@ int main(int argc, char **argv)
 
 		/*
 		 * TEST CASE: 5
-		 * path argument points above the maximum allocated address space
-		 */
-
-		TEST(rmdir(get_high_address()));
-
-		if (TEST_RETURN == -1) {
-		}
-
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT) {
-				tst_resm(TPASS,
-					 "rmdir() - path argument points above the maximum allocated address space failed as expected with errno %d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "rmdir() - path argument points above the maximum allocated address space failed with errno %d : %s but expected %d (EFAULT)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EFAULT);
-			}
-		} else {
-			tst_resm(TFAIL,
-				 "rmdir() - path argument points above the maximum allocated address space succeeded unexpectedly.");
-		}
-#endif
-
-		/*
-		 * TEST CASE: 6
 		 * able to remove a directory
 		 */
 
@@ -220,13 +186,7 @@ void setup(void)
 	/* Create a unique directory name. */
 	sprintf(dir_name, "./dir_%d", getpid());
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-#endif
+	bad_addr = tst_get_bad_addr(cleanup);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/stat/stat03.c b/testcases/kernel/syscalls/stat/stat03.c
index ef3d937..2e4c83a 100644
--- a/testcases/kernel/syscalls/stat/stat03.c
+++ b/testcases/kernel/syscalls/stat/stat03.c
@@ -103,7 +103,6 @@ char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
 char Longpathname[PATH_MAX + 2];
-char High_address_node[64];
 
 struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	char *pathname;
@@ -111,15 +110,8 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	TEST_FILE1, "No Search permissions to process", EACCES, setup1},
-#if !defined(UCLINUX)
-	{
-	High_address_node, "Address beyond address space", EFAULT, no_setup},
-	{
-	(char *)-1, "Negative address", EFAULT, no_setup},
-#endif
-	{
+	{TEST_FILE1, "No Search permissions to process", EACCES, setup1}, {
+	NULL, "Invalid address", EFAULT, no_setup}, {
 	Longpathname, "Pathname too long", ENAMETOOLONG, longpath_setup}, {
 	"", "Pathname is empty", ENOENT, no_setup}, {
 	TEST_FILE2, "Path contains regular file", ENOTDIR, setup2}, {
@@ -129,8 +121,6 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 char *TCID = "stat03";
 int TST_TOTAL = ARRAY_SIZE(Test_cases);
 
-char *bad_addr = 0;
-
 void setup();			/* Main setup function for the tests */
 void cleanup();			/* cleanup function for the test */
 
@@ -158,12 +148,6 @@ int main(int ac, char **av)
 			file_name = Test_cases[ind].pathname;
 			test_desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (file_name == High_address_node) {
-				file_name = (char *)get_high_address();
-			}
-#endif
-
 			/*
 			 * Call stat(2) to test different test conditions.
 			 * verify that it fails with -1 return value and
@@ -237,17 +221,10 @@ void setup(void)
 	/* Make a temp dir and cd to it */
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[2].pathname = bad_addr;
-#endif
-
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
+		if (!Test_cases[ind].pathname)
+			Test_cases[ind].pathname = tst_get_bad_addr(cleanup);
 		Test_cases[ind].setupfunc();
 	}
 }
diff --git a/testcases/kernel/syscalls/symlink/symlink03.c b/testcases/kernel/syscalls/symlink/symlink03.c
index 89f23c9..c89fe5d 100644
--- a/testcases/kernel/syscalls/symlink/symlink03.c
+++ b/testcases/kernel/syscalls/symlink/symlink03.c
@@ -103,8 +103,6 @@
 char *TCID = "symlink03";
 int TST_TOTAL = 1;
 
-char *bad_addr = 0;
-
 int no_setup();
 int setup1();			/* setup function to test symlink for EACCES */
 int setup2();			/* setup function to test symlink for EEXIST */
@@ -121,18 +119,11 @@ struct test_case_t {		/* test case struct. to hold ref. test cond's */
 	int exp_errno;
 	int (*setupfunc) ();
 } Test_cases[] = {
-	{
-	TEST_FILE1, SYM_FILE1, "No Search permissions to process",
+	{TEST_FILE1, SYM_FILE1, "No Search permissions to process",
 		    EACCES, setup1}, {
 	TEST_FILE2, SYM_FILE2, "Specified symlink already exists",
-		    EEXIST, setup2},
-#if !defined(UCLINUX)
-	{
-	TESTFILE, High_address_node, "Address beyond address space",
-		    EFAULT, no_setup},
-#endif
-	{
-	TESTFILE, (char *)-1, "Negative address", EFAULT, no_setup}, {
+		    EEXIST, setup2}, {
+	TESTFILE, NULL, "Invalid address", EFAULT, no_setup}, {
 	TESTFILE, Longpathname, "Symlink path too long", ENAMETOOLONG,
 		    longpath_setup}, {
 	TESTFILE, "", "Symlink Pathname is empty", ENOENT, no_setup}, {
@@ -171,11 +162,7 @@ int main(int ac, char **av)
 			test_file = Test_cases[ind].file;
 			sym_file = Test_cases[ind].link;
 			test_desc = Test_cases[ind].desc;
-#if !defined(UCLINUX)
-			if (sym_file == High_address_node) {
-				sym_file = (char *)get_high_address();
-			}
-#endif
+
 			/*
 			 * Call symlink(2) to test different test conditions.
 			 * verify that it fails with -1 return value and sets
@@ -241,17 +228,10 @@ void setup(void)
 
 	tst_tmpdir();
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[3].link = bad_addr;
-#endif
-
 	/* call individual setup functions */
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
+		if (!Test_cases[ind].link)
+			Test_cases[ind].link = tst_get_bad_addr(cleanup);
 		Test_cases[ind].setupfunc();
 	}
 }
diff --git a/testcases/kernel/syscalls/truncate/truncate03.c b/testcases/kernel/syscalls/truncate/truncate03.c
index 0aa7b3e..401c16a 100644
--- a/testcases/kernel/syscalls/truncate/truncate03.c
+++ b/testcases/kernel/syscalls/truncate/truncate03.c
@@ -76,10 +76,7 @@ static struct test_case_t {
 } test_cases[] = {
 	{ TEST_FILE1, TRUNC_LEN, EACCES },
 	{ TEST_FILE2, TRUNC_LEN, ENOTDIR },
-#if !defined(UCLINUX)
 	{ NULL, TRUNC_LEN, EFAULT },
-	{ (char *)-1, TRUNC_LEN, EFAULT },
-#endif
 	{ long_pathname, TRUNC_LEN, ENAMETOOLONG },
 	{ "", TRUNC_LEN, ENOENT },
 	{ TEST_DIR1, TRUNC_LEN, EISDIR },
@@ -117,9 +114,9 @@ int main(int ac, char **av)
 void setup(void)
 {
 	struct passwd *ltpuser;
-	char *bad_addr;
 	struct rlimit rlim;
 	sigset_t signalset;
+	int n;
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
@@ -136,14 +133,6 @@ void setup(void)
 
 	SAFE_TOUCH(cleanup, "t_file", FILE_MODE, NULL);
 
-#if !defined(UCLINUX)
-	test_cases[2].pathname = (char *)get_high_address();
-
-	bad_addr = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	test_cases[3].pathname = bad_addr;
-#endif
-
 	memset(long_pathname, 'a', PATH_MAX + 1);
 
 	SAFE_MKDIR(cleanup, TEST_DIR1, DIR_MODE);
@@ -162,6 +151,12 @@ void setup(void)
 	TEST(sigprocmask(SIG_BLOCK, &signalset, NULL));
 	if (TEST_RETURN != 0)
 		tst_brkm(TBROK | TTERRNO, cleanup, "sigprocmask");
+
+	for (n = 0; n < TST_TOTAL; n++) {
+		if (!test_cases[n].pathname)
+			test_cases[n].pathname = tst_get_bad_addr(cleanup);
+	}
+
 }
 
 void truncate_verify(struct test_case_t *tc)
diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 66e4db8..dc18ccf 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -123,13 +123,9 @@
 void setup();
 void cleanup();
 
-extern char *get_high_address();
-
 char *TCID = "unlink07";
 int TST_TOTAL = 6;
 
-char *bad_addr = 0;
-
 int longpath_setup();
 int no_setup();
 int filepath_setup();
@@ -146,21 +142,11 @@ struct test_case_t {
 	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
 	"", "path is empty string", ENOENT, no_setup}, {
 	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOENT, no_setup}, {
 	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup},
-#if !defined(UCLINUX)
-	{
-	High_address, "address beyond address space", EFAULT, no_setup},
-#endif
-	{
+		    ENOTDIR, filepath_setup}, {
 	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	(char *)-1, "negative address", EFAULT, no_setup}, {
+	NULL, "invalid address", EFAULT, no_setup}, {
 	NULL, NULL, 0, no_setup}
 };
 
@@ -196,10 +182,6 @@ int main(int ac, char **av)
 			fname = Test_cases[ind].pathname;
 			desc = Test_cases[ind].desc;
 
-#if !defined(UCLINUX)
-			if (fname == High_address)
-				fname = get_high_address();
-#endif
 			/*
 			 *  Call unlink(2)
 			 */
@@ -245,13 +227,9 @@ void setup(void)
 
 	tst_tmpdir();
 
-	bad_addr = mmap(0, 1, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	Test_cases[7].pathname = bad_addr;
-
 	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
+		if (!Test_cases[ind].pathname)
+			Test_cases[ind].pathname = tst_get_bad_addr(cleanup);
 		Test_cases[ind].setupfunc();
 	}
 
-- 
1.8.3.1




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

* [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to new API
  2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
@ 2018-02-22  5:48               ` Xiao Yang
  2018-02-27 10:24                 ` Cyril Hrubis
  2018-02-22  5:48               ` [LTP] [PATCH v4 3/4] syscalls/unlink07: " Xiao Yang
                                 ` (2 subsequent siblings)
  3 siblings, 1 reply; 25+ messages in thread
From: Xiao Yang @ 2018-02-22  5:48 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Merge unlink06 into unlink05

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/quickhit                            |   2 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/unlink/unlink05.c | 253 +++++++---------------------
 testcases/kernel/syscalls/unlink/unlink06.c | 215 -----------------------
 7 files changed, 62 insertions(+), 412 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/unlink/unlink06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 49d2b11..21d31ad 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -964,7 +964,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/quickhit b/runtest/quickhit
index 2a42769..8264b22 100644
--- a/runtest/quickhit
+++ b/runtest/quickhit
@@ -255,8 +255,6 @@ uname01 uname01
 # Basic test for uname(2)
 unlink05 unlink05
 # Basic test for unlink(2)
-unlink06 unlink06
-# unlink(2) of a FIFO
 unlink07 unlink07
 # unlink(2) negative testcases
 unlink08 unlink08
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 004bbad..261c5f9 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -840,7 +840,6 @@ uname03 uname03
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/runtest/syscalls b/runtest/syscalls
index ca84c10..7c3cd5b 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1383,7 +1383,6 @@ cve-2012-0957 cve-2012-0957
 
 unlink01 symlink01 -T unlink01
 unlink05 unlink05
-unlink06 unlink06
 unlink07 unlink07
 unlink08 unlink08
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 684f5e7..e67d726 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -1082,7 +1082,6 @@
 /uname/uname02
 /uname/uname03
 /unlink/unlink05
-/unlink/unlink06
 /unlink/unlink07
 /unlink/unlink08
 /unlinkat/unlinkat01
diff --git a/testcases/kernel/syscalls/unlink/unlink05.c b/testcases/kernel/syscalls/unlink/unlink05.c
index aa49316..5305e94 100644
--- a/testcases/kernel/syscalls/unlink/unlink05.c
+++ b/testcases/kernel/syscalls/unlink/unlink05.c
@@ -1,209 +1,80 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
  */
-/* $Id: unlink05.c,v 1.6 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for unlink(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.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-void create_file();
 
-char *TCID = "unlink05";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
+/*
+ * Description:
+ * The testcase checks the basic functionality of the unlink(2).
+ * 1) unlink() can delete regular file successfully.
+ * 2) unlink() can delete fifo file successfully.
+ */
 
-int main(int ac, char **av)
+#include <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+#include "tst_test.h"
+
+static void file_create(char *);
+static void fifo_create(char *);
+
+static struct test_case_t {
+	void (*setupfunc)(char *);
+	char *desc;
+} tcases[] = {
+	{file_create, "file"},
+	{fifo_create, "fifo"},
+};
+
+static void file_create(char *name)
 {
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "unlink(%s) returned %ld",
-				 fname, TEST_RETURN);
-			/* recreate file for next loop */
-			create_file();
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	sprintf(name, "tfile_%d", getpid());
+	SAFE_TOUCH(name, 0777, NULL);
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void fifo_create(char *name)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	create_file();
+	sprintf(name, "tfifo_%d", getpid());
+	SAFE_MKFIFO(name, 0777);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void verify_unlink(unsigned int n)
 {
+	char fname[255];
+	struct test_case_t *tc = &tcases[n];
 
-	tst_rmdir();
-
-}
+	tc->setupfunc(fname);
 
-void create_file(void)
-{
-	sprintf(fname, "tfile_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+	TEST(unlink(fname));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO, "unlink(%s) failed", tc->desc);
+		return;
 	}
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s",
-			 fname, errno, strerror(errno));
+
+	if (!access(fname, F_OK)) {
+		tst_res(TFAIL, "unlink(%s) succeeded, but %s still existed",
+			tc->desc, tc->desc);
+		return;
 	}
+
+	tst_res(TPASS, "unlink(%s) succeeded", tc->desc);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
diff --git a/testcases/kernel/syscalls/unlink/unlink06.c b/testcases/kernel/syscalls/unlink/unlink06.c
deleted file mode 100644
index 0e38480..0000000
--- a/testcases/kernel/syscalls/unlink/unlink06.c
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * 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/
- *
- */
-/* $Id: unlink06.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink06
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) of a FIFO
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) unlink(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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void create_file();
-void cleanup();
-
-char *TCID = "unlink06";
-int TST_TOTAL = 1;
-
-char Fname[255];
-
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		create_file();
-
-		/*
-		 *  Call unlink(2)
-		 */
-		TEST(unlink(Fname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "unlink(%s) Failed, errno=%d : %s",
-				 Fname, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			if (access(Fname, F_OK) != -1) {
-				tst_resm(TFAIL,
-					 "unlink(%s) returned %ld, but access says file still exists.",
-					 Fname, TEST_RETURN);
-			} else {
-				tst_resm(TPASS, "unlink(%s) returned %ld",
-					 Fname, TEST_RETURN);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(Fname, "fifo_unlink%d", getpid());
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-void create_file(void)
-{
-	SAFE_MKFIFO(cleanup, Fname, 0777);
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v4 3/4] syscalls/unlink07: Cleanup && Convert to new API
  2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
  2018-02-22  5:48               ` [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
@ 2018-02-22  5:48               ` Xiao Yang
  2018-02-27 10:25                 ` Cyril Hrubis
  2018-02-22  5:48               ` [LTP] [PATCH v4 4/4] syscalls/unlink08: " Xiao Yang
  2018-02-27 10:23               ` [LTP] [PATCH v4 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
  3 siblings, 1 reply; 25+ messages in thread
From: Xiao Yang @ 2018-02-22  5:48 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove duplicate tests for EFAULT

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink07.c | 320 ++++++----------------------
 1 file changed, 62 insertions(+), 258 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index dc18ccf..fb59a99 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -1,286 +1,90 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns ENOENT if file doesn't exist.
+ * 2) unlink() returns ENOENT if path is empty.
+ * 3) unlink() returns ENOENT if path contains a non-existent file.
+ * 4) unlink() returns EFAULT if address beyond address space.
+ * 5) unlink() returns ENOTDIR if path contains a regular file.
+ * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+ * 7) unlink() returns EFAULT if address is invalid.
  */
-/* $Id: unlink07.c,v 1.8 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink07
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-8) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
 #include <errno.h>
 #include <string.h>
-#include <signal.h>
 #include <unistd.h>
-#include <sys/param.h>		/* for PATH_MAX */
-#include "test.h"
-
-void setup();
-void cleanup();
+#include <sys/param.h>	/* for PATH_MAX */
+#include "tst_test.h"
 
-char *TCID = "unlink07";
-int TST_TOTAL = 6;
+static char longpathname[PATH_MAX + 2];
 
-int longpath_setup();
-int no_setup();
-int filepath_setup();
-char Longpathname[PATH_MAX + 2];
-char High_address[64];
-
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{
-	"nonexistfile", "non-existent file", ENOENT, no_setup}, {
-	"", "path is empty string", ENOENT, no_setup}, {
-	"nefile/file", "path contains a non-existent file",
-		    ENOENT, no_setup}, {
-	"file/file", "path contains a regular file",
-		    ENOTDIR, filepath_setup}, {
-	Longpathname, "pathname too long", ENAMETOOLONG, longpath_setup}, {
-	NULL, "invalid address", EFAULT, no_setup}, {
-	NULL, NULL, 0, no_setup}
+} tcases[] = {
+	{"nonexistfile", "non-existent file", ENOENT},
+	{"", "path is empty string", ENOENT},
+	{"nefile/file", "path contains a non-existent file", ENOENT},
+	{NULL, "invalid address", EFAULT},
+	{"file/file", "path contains a regular file", ENOTDIR},
+	{longpathname, "pathname too long", ENAMETOOLONG},
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
+static void verify_unlink(unsigned int n)
 {
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO ==
-				    Test_cases[ind].exp_errno)
-					tst_resm(TPASS,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				else
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-						 desc, TEST_ERRNO,
-						 Test_cases
-						 [ind].exp_errno);
-			} else {
-				tst_resm(TFAIL,
-					 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-					 desc, TEST_RETURN,
-					 Test_cases[ind].exp_errno);
-			}
-		}
+	struct test_case_t *tc = &tcases[n];
 
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int ind;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (!Test_cases[ind].pathname)
-			Test_cases[ind].pathname = tst_get_bad_addr(cleanup);
-		Test_cases[ind].setupfunc();
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void setup(void)
 {
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
+	int n;
 
-	tst_rmdir();
-
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(void)
-{
-	return 0;
-}
+	SAFE_TOUCH("file", 0777, NULL);
 
-/******************************************************************
- *
- ******************************************************************/
-int longpath_setup(void)
-{
-	int ind;
+	memset(longpathname, 'a', PATH_MAX + 2);
 
-	for (ind = 0; ind <= PATH_MAX + 1; ind++) {
-		Longpathname[ind] = 'a';
+	for (n = 0; n < ARRAY_SIZE(tcases); n++) {
+		if (!tcases[n].name)
+			tcases[n].name = tst_get_bad_addr(NULL);
 	}
-	return 0;
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int filepath_setup(void)
-{
-	int fd;
-
-	if ((fd = creat("file", 0777)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(file) failed, errno:%d %s",
-			 errno, strerror(errno));
-	}
-	close(fd);
-	return 0;
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v4 4/4] syscalls/unlink08: Cleanup && Convert to new API
  2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
  2018-02-22  5:48               ` [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
  2018-02-22  5:48               ` [LTP] [PATCH v4 3/4] syscalls/unlink07: " Xiao Yang
@ 2018-02-22  5:48               ` Xiao Yang
  2018-02-27 10:26                 ` Cyril Hrubis
  2018-02-27 10:23               ` [LTP] [PATCH v4 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
  3 siblings, 1 reply; 25+ messages in thread
From: Xiao Yang @ 2018-02-22  5:48 UTC (permalink / raw)
  To: ltp

1) Take use of some safe macros
2) Remove unused code

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/unlink/unlink08.c | 402 ++++++----------------------
 1 file changed, 79 insertions(+), 323 deletions(-)

diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index 9829a7c..699af2a 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -1,355 +1,111 @@
 /*
  * 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/
- *
+ * 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, see <http://www.gnu.org/licenses/>.
  */
-/* $Id: unlink08.c,v 1.5 2009/11/02 13:57:19 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: unlink08
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: unlink(2) negative testcases
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 03/30/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1-3) See Testcases structure below.
- *
- *    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 unlink(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
- *	unlink(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 <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
 
-void setup(void);
-void cleanup(void);
+/*
+ * Description:
+ * The testcase checks the various errnos of the unlink(2).
+ * 1) unlink() returns EACCES when deleting file in unwritable directory
+ *    as an unprivileged user.
+ * 2) unlink() returns EACCES when deleting file in "unsearchable directory
+ *    as an unprivileged user.
+ * 3) unlink() returns EISDIR when deleting directory in linux.
+ * 4) unlink() returns EPERM when deleting directory in non-linux.
+ */
 
-char *TCID = "unlink08";
-int TST_TOTAL = 3;
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
 
-int unwrite_dir_setup(int flag);
-int unsearch_dir_setup(int flag);
-int dir_setup(int flag);
-int no_setup(int flag);
+static struct passwd *pw;
 
-struct test_case_t {
-	char *pathname;
+static struct test_case_t {
+	char *name;
 	char *desc;
-	int (*setupfunc) (int flag);
-	int exp_ret;		/* -1 means error, 0 means != -1 */
 	int exp_errno;
-} Test_cases[] = {
-	{
-	"unwrite_dir/file", "unwritable directory", unwrite_dir_setup,
-		    -1, EACCES}, {
-	"unsearch_dir/file", "unsearchable directory",
-		    unsearch_dir_setup, -1, EACCES},
-#ifdef linux
-	{
-	"regdir", "directory", dir_setup, -1, EISDIR},
+	int exp_user;
+} tcases[] = {
+	{"unwrite_dir/file", "unwritable directory", EACCES, 1},
+	{"unsearch_dir/file", "unsearchable directory", EACCES, 1},
+#ifdef __linux__
+	{"regdir", "directory", EISDIR, 0},
 #else
-	{
-	"regdir", "directory", dir_setup, -1, EPERM},
+	{"regdir", "directory", EPERM, 0},
 #endif
-	{
-	NULL, NULL, no_setup, -1, 0}
 };
 
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-	char *fname;
-	char *desc;
-	int ind;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-
-			fname = Test_cases[ind].pathname;
-			desc = Test_cases[ind].desc;
-
-			/*
-			 *  Call unlink(2)
-			 */
-			TEST(unlink(fname));
-
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				if (Test_cases[ind].exp_ret == -1) {	/* neg test */
-					if (TEST_ERRNO ==
-					    Test_cases[ind].exp_errno)
-						tst_resm(TPASS,
-							 "unlink(<%s>) Failed, errno=%d",
-							 desc,
-							 TEST_ERRNO);
-					else
-						tst_resm(TFAIL,
-							 "unlink(<%s>) Failed, errno=%d, expected errno:%d",
-							 desc,
-							 TEST_ERRNO,
-							 Test_cases
-							 [ind].exp_errno);
-				} else {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) Failed, errno=%d",
-						 desc, TEST_ERRNO);
-				}
-			} else {
-				if (Test_cases[ind].exp_ret == -1) {
-					tst_resm(TFAIL,
-						 "unlink(<%s>) returned %ld, expected -1, errno:%d",
-						 desc, TEST_RETURN,
-						 Test_cases[ind].exp_errno);
-				} else {
-					tst_resm(TPASS,
-						 "unlink(<%s>) returned %ld",
-						 desc, TEST_RETURN);
-				}
-				Test_cases[ind].setupfunc(1);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void verify_unlink(struct test_case_t *tc)
 {
-	int ind;
-	int postest = 0;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (geteuid() == 0) {
-		postest++;
+	TEST(unlink(tc->name));
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
+			tc->desc);
+		return;
 	}
 
-	for (ind = 0; Test_cases[ind].desc != NULL; ind++) {
-		if (Test_cases[ind].exp_errno == EACCES && postest)
-			Test_cases[ind].exp_ret = 0;	/* set as a pos test */
-		Test_cases[ind].setupfunc(0);
+	if (TEST_ERRNO == tc->exp_errno) {
+		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
+			tc->desc);
+	} else {
+		tst_res(TFAIL | TTERRNO, "unlink(<%s>) failed, expected errno:%s",
+			tc->desc, tst_strerrno(tc->exp_errno));
 	}
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-	chmod("unwrite_dir", 0777);
-	chmod("unsearch_dir", 0777);
-
-	tst_rmdir();
-
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unwrite_dir_setup(int flag)
+static void do_unlink(unsigned int n)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unwrite_dir", 0777);
-
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
+	struct test_case_t *cases = &tcases[n];
+	pid_t pid;
+
+	if (cases->exp_user) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			SAFE_SETUID(pw->pw_uid);
+			verify_unlink(cases);
+			exit(0);
 		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0777);
 
-		if ((fd = creat("unwrite_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unwrite_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
-
-		SAFE_CHMOD(cleanup, "unwrite_dir", 0555);
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		verify_unlink(cases);
 	}
-	return 0;
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int unsearch_dir_setup(int flag)
+static void setup(void)
 {
-	int fd;
-
-	if (!flag) {		/* initial setup */
-		SAFE_MKDIR(cleanup, "unsearch_dir", 0777);
-
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("unwrite_dir", 0777);
+	SAFE_TOUCH("unwrite_dir/file", 0777, NULL);
+	SAFE_CHMOD("unwrite_dir", 0555);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	} else {		/* resetup */
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0777);
+	SAFE_MKDIR("unsearch_dir", 0777);
+	SAFE_TOUCH("unsearch_dir/file", 0777, NULL);
+	SAFE_CHMOD("unsearch_dir", 0666);
 
-		if ((fd = creat("unsearch_dir/file", 0777)) == -1) {
-			tst_brkm(TBROK, cleanup,
-				 "creat(unsearch_dir/file, 0777) failed, errno:%d %s",
-				 errno, strerror(errno));
-		}
-		close(fd);
+	SAFE_MKDIR("regdir", 0777);
 
-		SAFE_CHMOD(cleanup, "unsearch_dir", 0666);
-	}
-	return 0;
+	pw = SAFE_GETPWNAM("nobody");
 }
 
-/******************************************************************
- *
- ******************************************************************/
-int dir_setup(int flag)
-{
-	SAFE_MKDIR(cleanup, "regdir", 0777);
-	return 0;
-}
-
-/******************************************************************
- *
- ******************************************************************/
-int no_setup(int flag)
-{
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = do_unlink,
+};
-- 
1.8.3.1




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

* [LTP] [PATCH v4 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for new API
  2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
                                 ` (2 preceding siblings ...)
  2018-02-22  5:48               ` [LTP] [PATCH v4 4/4] syscalls/unlink08: " Xiao Yang
@ 2018-02-27 10:23               ` Cyril Hrubis
  3 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-27 10:23 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to new API
  2018-02-22  5:48               ` [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
@ 2018-02-27 10:24                 ` Cyril Hrubis
  0 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-27 10:24 UTC (permalink / raw)
  To: ltp

Hi!
Pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v4 3/4] syscalls/unlink07: Cleanup && Convert to new API
  2018-02-22  5:48               ` [LTP] [PATCH v4 3/4] syscalls/unlink07: " Xiao Yang
@ 2018-02-27 10:25                 ` Cyril Hrubis
  0 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-27 10:25 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor fixes (the description wasn't correct sice we have
only one EFAULT test now), thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v4 4/4] syscalls/unlink08: Cleanup && Convert to new API
  2018-02-22  5:48               ` [LTP] [PATCH v4 4/4] syscalls/unlink08: " Xiao Yang
@ 2018-02-27 10:26                 ` Cyril Hrubis
  0 siblings, 0 replies; 25+ messages in thread
From: Cyril Hrubis @ 2018-02-27 10:26 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes (got rid of the non-linux code), thanks.

This patchset was a nice cleanup :-)

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2018-02-27 10:26 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-09  7:56 [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for new API Xiao Yang
2018-02-09  7:56 ` [LTP] [PATCH 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
2018-02-09  7:56 ` [LTP] [PATCH 3/4] syscalls/unlink07: " Xiao Yang
2018-02-09  7:56 ` [LTP] [PATCH 4/4] syscalls/unlink08: " Xiao Yang
2018-02-12 16:22 ` [LTP] [PATCH 1/4] lib/get_high_address.c: Add tst_get_high_address.h for " Cyril Hrubis
2018-02-13  8:41   ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Xiao Yang
2018-02-13  8:41     ` [LTP] [PATCH v2 2/5] lib/get_high_address.c: Add tst_get_bad_addr.h for new API Xiao Yang
2018-02-13 13:42       ` Cyril Hrubis
2018-02-14  6:19         ` [LTP] [PATCH v3 1/4] " Xiao Yang
2018-02-14  6:19           ` [LTP] [PATCH v3 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
2018-02-14  6:19           ` [LTP] [PATCH v3 3/4] syscalls/unlink07: " Xiao Yang
2018-02-14  6:19           ` [LTP] [PATCH v3 4/4] syscalls/unlink08: " Xiao Yang
2018-02-20 16:08           ` [LTP] [PATCH v3 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
2018-02-22  5:48             ` [LTP] [PATCH v4 " Xiao Yang
2018-02-22  5:48               ` [LTP] [PATCH v4 2/4] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
2018-02-27 10:24                 ` Cyril Hrubis
2018-02-22  5:48               ` [LTP] [PATCH v4 3/4] syscalls/unlink07: " Xiao Yang
2018-02-27 10:25                 ` Cyril Hrubis
2018-02-22  5:48               ` [LTP] [PATCH v4 4/4] syscalls/unlink08: " Xiao Yang
2018-02-27 10:26                 ` Cyril Hrubis
2018-02-27 10:23               ` [LTP] [PATCH v4 1/4] lib/get_high_address.c: Add tst_get_bad_addr.h for " Cyril Hrubis
2018-02-13  8:41     ` [LTP] [PATCH v2 3/5] syscalls/unlink05, 06: Cleanup && Convert to " Xiao Yang
2018-02-13  8:41     ` [LTP] [PATCH v2 4/5] syscalls/unlink07: " Xiao Yang
2018-02-13  8:41     ` [LTP] [PATCH v2 5/5] syscalls/unlink08: " Xiao Yang
2018-02-13 13:04     ` [LTP] [PATCH v2 1/5] syscalls/mremap03: Do not pass MAP_FAILED into mremap() Cyril Hrubis

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.