All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API
@ 2017-06-19  5:00 Xiao Yang
  2017-06-19  5:00 ` [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: " Xiao Yang
  2017-06-19 16:51 ` [LTP] [PATCH 1/2] syscalls/lseek01, 06: " Cyril Hrubis
  0 siblings, 2 replies; 8+ messages in thread
From: Xiao Yang @ 2017-06-19  5:00 UTC (permalink / raw)
  To: ltp

1) merge lseek06 into lseek01
2) add tests for SEEK_CUR and SEEK_END

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                           |   1 -
 runtest/stress.part3                      |   1 -
 runtest/syscalls                          |   1 -
 testcases/kernel/syscalls/.gitignore      |   1 -
 testcases/kernel/syscalls/lseek/lseek01.c | 264 ++++++++----------------------
 testcases/kernel/syscalls/lseek/lseek06.c | 202 -----------------------
 6 files changed, 71 insertions(+), 399 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 909bbdb..7904117 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -410,7 +410,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index d5db1c2..42c2b0e 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -336,7 +336,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/syscalls b/runtest/syscalls
index 8754e3e..fcef347 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -552,7 +552,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d8a38c0..5b8e5b4 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -503,7 +503,6 @@
 /lseek/lseek03
 /lseek/lseek04
 /lseek/lseek05
-/lseek/lseek06
 /lseek/lseek07
 /lseek/lseek08
 /lseek/lseek09
diff --git a/testcases/kernel/syscalls/lseek/lseek01.c b/testcases/kernel/syscalls/lseek/lseek01.c
index a5f8524..c553ded 100644
--- a/testcases/kernel/syscalls/lseek/lseek01.c
+++ b/testcases/kernel/syscalls/lseek/lseek01.c
@@ -1,219 +1,97 @@
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 06/2017 modified by 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 free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ * This program is distributed in the hope that it 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:
+ *  lseek() succeeds to set the specified offset according to whence
+ *  and read valid data from this location.
  */
-/* $Id: lseek01.c,v 1.5 2009/11/02 13:57:17 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for lseek(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    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.) lseek(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 lseek(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
- *	lseek(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 <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek01";
-int TST_TOTAL = 3;
-
-char Fname[255];
-int Fd;
-
-int Whence[] = { SEEK_SET, SEEK_CUR, SEEK_END, -1 };
-
-int main(int ac, char **av)
+#include "tst_test.h"
+
+static int fd;
+static struct tcase {
+	off_t off;
+	int whence;
+	off_t exp_off;
+	char *exp_data;
+} tcases[] = {
+	{4, SEEK_SET, 4, "efg"},
+	{-2, SEEK_CUR, 5, "fg"},
+	{-4, SEEK_END, 3, "defg"},
+};
+
+static void verify_lseek(unsigned int n)
 {
-	int lc;
-
-	int ind;
-	int offset;
+	char read_buf[64];
+	struct tcase *tc = &tcases[n];
 
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
+	memset(read_buf, 0, sizeof(read_buf));
 
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		offset = (lc % 100) * 4096;	/* max size is 100 blocks */
-
-		for (ind = 0; Whence[ind] >= 0; ind++) {
+	TEST(lseek(fd, tc->off, tc->whence));
+	if (TEST_RETURN == (off_t) -1) {
+		tst_res(TFAIL | TTERRNO, "lseek(%d, %ld, %d) failed", fd,
+			tc->off, tc->whence);
+		return;
+	}
 
-			/*
-			 *  Call lseek(2)
-			 */
-			TEST(lseek(Fd, (long)offset, Whence[ind]));
+	if (TEST_RETURN != tc->exp_off) {
+		tst_res(TFAIL, "lseek(%d, %ld, %d) returned %ld, expected %ld",
+			fd, tc->off, tc->whence, TEST_RETURN, tc->exp_off);
+		return;
+	}
 
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "lseek(%s, %d, 0) Failed, errno=%d : %s",
-					 Fname, offset, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TPASS,
-					 "lseek(%s, %d, %d) returned %ld",
-					 Fname, offset, Whence[ind],
-					 TEST_RETURN);
-			}
-		}
+	SAFE_READ(0, fd, &read_buf, sizeof(read_buf));
 
+	if (strcmp(read_buf, tc->exp_data)) {
+		tst_res(TFAIL, "lseek(%d, %ld, %d) read incorrect data", fd,
+			tc->off, tc->whence);
+	} else {
+		tst_res(TPASS, "lseek(%d, %ld, %d) read correct data", fd,
+			tc->off, tc->whence);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void setup(void)
 {
+	char write_buf[64];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	strcpy(write_buf, "abcdefg");
 
-	TEST_PAUSE;
+	fd = SAFE_OPEN("tmp_file", O_RDWR | O_CREAT, 0644);
 
-	tst_tmpdir();
-
-	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));
-	}
+	SAFE_WRITE(1, fd, write_buf, strlen(write_buf));
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", Fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_lseek,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/lseek/lseek06.c b/testcases/kernel/syscalls/lseek/lseek06.c
deleted file mode 100644
index 056eb40..0000000
--- a/testcases/kernel/syscalls/lseek/lseek06.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: lseek06
- *
- * Test Description:
- *  Verify that, lseek() call succeeds to set the file pointer position
- *  to less  than  or equal to the file size, when a file is opened for
- *  read or write.
- *
- * Expected Result:
- *  lseek() should return the offset from the beginning of the file measured
- *  in bytes. Also check if able to read valid data from this location.
- * $
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *   Create temporary directory.
- *
- *  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,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  lseek06 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
-
-#include "test.h"
-
-#define OFFSET		4
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-
-char *TCID = "lseek06";
-int TST_TOTAL = 1;
-int fildes;			/* file handle for temp file */
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
-{
-	int lc;
-	char read_buf[1];	/* data read from temp. file */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke lseek(2) to move the read/write file
-		 * pointer/handle by OFFSET bytes.
-		 */
-		TEST(lseek(fildes, OFFSET, SEEK_SET));
-
-		if (TEST_RETURN == (off_t) - 1) {
-			tst_resm(TFAIL, "lseek on (%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
-			continue;
-		}
-		/*
-		 * Check if the return value from lseek(2)
-		 * is equal to the specified OFFSET value.
-		 */
-		if (TEST_RETURN != OFFSET) {
-			tst_resm(TFAIL, "lseek() returned incorrect "
-				 "value %ld, expected %d",
-				 TEST_RETURN, OFFSET);
-			continue;
-		}
-		/*
-		 * The return value is good, now check data.
-		 * Read the data byte from this location.
-		 */
-		if (read(fildes, &read_buf, sizeof(read_buf)) < 0) {
-			tst_brkm(TFAIL, cleanup, "read() failed "
-				 "on %s, error=%d", TEMP_FILE, errno);
-		} else {
-			/*
-			 * Check if read byte is the expected character.
-			 * For pos 4 ---> 'e'
-			 */
-			if (read_buf[0] != 'e') {
-				tst_resm(TFAIL, "Incorrect data read "
-					 "from file %s", TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality "
-					 "of lseek() on %s "
-					 "successful", TEMP_FILE);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- *	     Create a temporary directory and change directory to it.
- *	     Create a test file under temporary directory and write some
- *	     data into it.
- */
-void setup(void)
-{
-	char write_buf[BUFSIZ];	/* buffer to hold data */
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Get the data to be written to temporary file */
-	strcpy(write_buf, "abcdefg");
-
-	/* Creat/open a temporary file under above directory */
-	if ((fildes = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) Failed, errno=%d :%s",
-			 TEMP_FILE, FILE_MODE, errno, strerror(errno));
-	}
-
-	/* Write data into temporary file */
-	if (write(fildes, write_buf, strlen(write_buf)) != strlen(write_buf)) {
-		tst_brkm(TBROK, cleanup, "write(2) on %s Failed, errno=%d : %s",
-			 TEMP_FILE, errno, strerror(errno));
-	}
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	       Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TFAIL, NULL, "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: cleanup && convert to new API
  2017-06-19  5:00 [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API Xiao Yang
@ 2017-06-19  5:00 ` Xiao Yang
  2017-06-19 17:09   ` Cyril Hrubis
  2017-06-19 16:51 ` [LTP] [PATCH 1/2] syscalls/lseek01, 06: " Cyril Hrubis
  1 sibling, 1 reply; 8+ messages in thread
From: Xiao Yang @ 2017-06-19  5:00 UTC (permalink / raw)
  To: ltp

1) merge lseek03,04,05 into lseek02
2) add combinations of invalid parameters

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                           |   3 -
 runtest/stress.part3                      |   3 -
 runtest/syscalls                          |   3 -
 testcases/kernel/syscalls/.gitignore      |   3 -
 testcases/kernel/syscalls/lseek/lseek02.c | 246 ++++++++++--------------------
 testcases/kernel/syscalls/lseek/lseek03.c | 123 ---------------
 testcases/kernel/syscalls/lseek/lseek04.c | 222 ---------------------------
 testcases/kernel/syscalls/lseek/lseek05.c | 219 --------------------------
 8 files changed, 78 insertions(+), 744 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek03.c
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek04.c
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek05.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 7904117..2826514 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -407,9 +407,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 42c2b0e..67548dc 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -333,9 +333,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/syscalls b/runtest/syscalls
index fcef347..169bfcd 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -549,9 +549,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 5b8e5b4..9ea4ed8 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -500,9 +500,6 @@
 /llseek/llseek03
 /lseek/lseek01
 /lseek/lseek02
-/lseek/lseek03
-/lseek/lseek04
-/lseek/lseek05
 /lseek/lseek07
 /lseek/lseek08
 /lseek/lseek09
diff --git a/testcases/kernel/syscalls/lseek/lseek02.c b/testcases/kernel/syscalls/lseek/lseek02.c
index 0efc691..0d6ca1d 100644
--- a/testcases/kernel/syscalls/lseek/lseek02.c
+++ b/testcases/kernel/syscalls/lseek/lseek02.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * 06/2017 modified by 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
@@ -17,189 +18,98 @@
  * 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/
- *
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * DESCRIPTION
+ * 1) lseek(2) fails and sets errno to EBADF when fd is invalid.
+ * 2) lseek(2) fails ans sets errno to EINVAL when whence is invalid.
+ * 3) lseek(2) fails and sets errno to ESPIPE when fd is associated
+ *    with a pipe or FIFO.
  */
-/* $Id: lseek02.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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 <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek02";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
-
-int Whence[] = { SEEK_SET, SEEK_CUR, SEEK_END, -1 };
-
-int main(int ac, char **av)
+#include <stdio.h>
+#include "tst_test.h"
+
+static char fname[255], pname[255];
+static int bad_fd = -1;
+static int fd, pfd;
+static int pfds[2];
+
+static struct tcase {
+	int *fd;
+	int whence;
+	int exp_err;
+} tcases[] = {
+	{&bad_fd, SEEK_SET, EBADF},
+	{&bad_fd, SEEK_CUR, EBADF},
+	{&bad_fd, SEEK_END, EBADF},
+	{&fd, 5, EINVAL},
+	{&fd, -1, EINVAL},
+	{&fd, 7, EINVAL},
+	{&pfd, SEEK_SET, ESPIPE},
+	{&pfd, SEEK_CUR, ESPIPE},
+	{&pfd, SEEK_END, ESPIPE},
+	{&pfds[0], SEEK_SET, ESPIPE},
+	{&pfds[0], SEEK_CUR, ESPIPE},
+	{&pfds[0], SEEK_END, ESPIPE},
+};
+
+static void verify_lseek(unsigned int n)
 {
-	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 lseek(2)
-		 */
-		TEST(lseek(-1, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EBADF)
-
-				tst_resm(TPASS,
-					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s, expected %d(EBADF)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EBADF);
-		} else {
-
-			tst_resm(TFAIL, "lseek(-1, 1, SEEK_SET) returned %ld",
-				 TEST_RETURN);
-		}
+	struct tcase *tc = &tcases[n];
 
+	TEST(lseek(*tc->fd, (off_t) 1, tc->whence));
+	if (TEST_RETURN != (off_t) -1) {
+		tst_res(TFAIL, "lseek(%d, 1, %d) succeeded unexpectedly",
+			*tc->fd, tc->whence);
+			return;
 	}
 
-	cleanup();
-	tst_exit();
+	if (TEST_ERRNO == tc->exp_err) {
+		tst_res(TPASS | TTERRNO, "lseek(%d, 1, %d) failed as expected",
+			*tc->fd, tc->whence);
+	} else {
+		tst_res(TFAIL | TTERRNO, "lseek(%d, 1, %d) failed "
+			"unexpectedly, expected %s", *tc->fd, tc->whence,
+			tst_strerrno(tc->exp_err));
+	}
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void setup(void)
 {
+	sprintf(fname, "tfile_%d", getpid());
+	sprintf(pname, "tpipe_%d", getpid());
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
+	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0777);
+	SAFE_MKFIFO(pname, 0777);
+	pfd = SAFE_OPEN(pname, O_RDWR, 0777);
+	SAFE_PIPE(pfds);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+
+	if (pfd > 0)
+		SAFE_CLOSE(pfd);
 
-	tst_rmdir();
+	if (pfds[0] > 0)
+		SAFE_CLOSE(pfds[0]);
 
+	if (pfds[1] > 0)
+		SAFE_CLOSE(pfds[1]);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_lseek,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/lseek/lseek03.c b/testcases/kernel/syscalls/lseek/lseek03.c
deleted file mode 100644
index 02b94fb..0000000
--- a/testcases/kernel/syscalls/lseek/lseek03.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
- *
- * 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/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-
-static void setup(void);
-static void cleanup(void);
-
-static char fname[255];
-static int fd;
-static int whences[] = { 5, -1, 7 };
-
-char *TCID = "lseek03";
-int TST_TOTAL = ARRAY_SIZE(whences);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i;
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			/* Call lseek(2) */
-			TEST(lseek(fd, (off_t) 1, whences[i]));
-
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO == EINVAL) {
-					tst_resm(TPASS,
-						 "lseek(%s, 1, %d) Failed, errno=%d : %s",
-						 fname, whences[i],
-						 TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-				} else {
-					tst_resm(TFAIL,
-						 "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)",
-						 fname, whences[i],
-						 TEST_ERRNO,
-						 strerror(TEST_ERRNO),
-						 EINVAL);
-				}
-			} else {
-				tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld",
-					 fname, whences[i], TEST_RETURN);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	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));
-	}
-}
-
-void cleanup(void)
-{
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/lseek/lseek04.c b/testcases/kernel/syscalls/lseek/lseek04.c
deleted file mode 100644
index 9d431f0..0000000
--- a/testcases/kernel/syscalls/lseek/lseek04.c
+++ /dev/null
@@ -1,222 +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: lseek04.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek04
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(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	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek04";
-int TST_TOTAL = 1;
-
-char Fname[255];
-int Fd;
-
-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;
-
-		/*
-		 *  Call lseek(2)
-		 */
-		TEST(lseek(Fd, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == ESPIPE)
-				tst_resm(TPASS,
-					 "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EINVAL);
-		} else {
-
-			tst_resm(TFAIL,
-				 "lseek(fifofd, 1, SEEK_SET) returned %ld",
-				 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, "tfile_%d", getpid());
-	if (mkfifo(Fname, 0700) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "mkfifo(%s, 0700) Failed, errno=%d : %s",
-			 Fname, errno, strerror(errno));
-	}
-
-	if ((Fd = open(Fname, O_RDWR, 0777)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR, 0777) Failed, errno=%d : %s",
-			 Fname, errno, strerror(errno));
-	}
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", Fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/lseek/lseek05.c b/testcases/kernel/syscalls/lseek/lseek05.c
deleted file mode 100644
index 1eee03d..0000000
--- a/testcases/kernel/syscalls/lseek/lseek05.c
+++ /dev/null
@@ -1,219 +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: lseek05.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(2) of a pipe
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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 <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek05";
-int TST_TOTAL = 1;
-
-int Fd;
-
-/***********************************************************************
- * 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;
-
-		/*
-		 *  Call lseek(2)
-		 */
-		TEST(lseek(Fd, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == ESPIPE)
-				tst_resm(TPASS,
-					 "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EINVAL);
-		} else {
-
-			tst_resm(TFAIL,
-				 "lseek(pipefd, 1, SEEK_SET) returned %ld",
-				 TEST_RETURN);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int fds[2];
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (pipe(fds) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "pipe(&fds) Failed, errno=%d : %s", errno,
-			 strerror(errno));
-	}
-	Fd = fds[0];
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%d) Failed, errno=%d : %s", Fd, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API
  2017-06-19  5:00 [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API Xiao Yang
  2017-06-19  5:00 ` [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: " Xiao Yang
@ 2017-06-19 16:51 ` Cyril Hrubis
  2017-06-20  2:16   ` Xiao Yang
  2017-06-20  2:30   ` [LTP] [PATCH v2 " Xiao Yang
  1 sibling, 2 replies; 8+ messages in thread
From: Cyril Hrubis @ 2017-06-19 16:51 UTC (permalink / raw)
  To: ltp

Hi!
> +static int fd;
> +static struct tcase {
> +	off_t off;
> +	int whence;
> +	off_t exp_off;
> +	char *exp_data;
> +} tcases[] = {
> +	{4, SEEK_SET, 4, "efg"},
> +	{-2, SEEK_CUR, 5, "fg"},

This part actually depends on the fact that the file has been seeked and
read in the previous test. I wonder if it would be less confusing if we
reset the offset to a defined position (start of the file) before the
the test.

> +	{-4, SEEK_END, 3, "defg"},
> +};
> +
> +static void verify_lseek(unsigned int n)
>  {
> -	int lc;
> -
> -	int ind;
> -	int offset;
> +	char read_buf[64];
> +	struct tcase *tc = &tcases[n];
>  
> -    /***************************************************************
> -     * parse standard options
> -     ***************************************************************/
> -	tst_parse_opts(ac, av, NULL, NULL);
> +	memset(read_buf, 0, sizeof(read_buf));
>  
> -    /***************************************************************
> -     * perform global setup for test
> -     ***************************************************************/
> -	setup();
> -
> -    /***************************************************************
> -     * check looping state if -c option given
> -     ***************************************************************/
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> -
> -		offset = (lc % 100) * 4096;	/* max size is 100 blocks */
> -
> -		for (ind = 0; Whence[ind] >= 0; ind++) {
> +	TEST(lseek(fd, tc->off, tc->whence));
> +	if (TEST_RETURN == (off_t) -1) {
> +		tst_res(TFAIL | TTERRNO, "lseek(%d, %ld, %d) failed", fd,
> +			tc->off, tc->whence);
> +		return;
> +	}
>  
> -			/*
> -			 *  Call lseek(2)
> -			 */
> -			TEST(lseek(Fd, (long)offset, Whence[ind]));
> +	if (TEST_RETURN != tc->exp_off) {
> +		tst_res(TFAIL, "lseek(%d, %ld, %d) returned %ld, expected %ld",
> +			fd, tc->off, tc->whence, TEST_RETURN, tc->exp_off);
> +		return;
> +	}
>  
> -			/* check return code */
> -			if (TEST_RETURN == -1) {
> -				tst_resm(TFAIL,
> -					 "lseek(%s, %d, 0) Failed, errno=%d : %s",
> -					 Fname, offset, TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			} else {
> -				tst_resm(TPASS,
> -					 "lseek(%s, %d, %d) returned %ld",
> -					 Fname, offset, Whence[ind],
> -					 TEST_RETURN);
> -			}
> -		}
> +	SAFE_READ(0, fd, &read_buf, sizeof(read_buf));
>  
> +	if (strcmp(read_buf, tc->exp_data)) {
> +		tst_res(TFAIL, "lseek(%d, %ld, %d) read incorrect data", fd,
> +			tc->off, tc->whence);
> +	} else {
> +		tst_res(TPASS, "lseek(%d, %ld, %d) read correct data", fd,
> +			tc->off, tc->whence);

I guess that the fd here is not that useful and it may be a bit better
to to translate the whence to its name, but that is very minor.

>  	}
> -
> -	cleanup();
> -	tst_exit();
>  }
>  
> -/***************************************************************
> - * setup() - performs all ONE TIME setup for this test.
> - ***************************************************************/
> -void setup(void)
> +static void setup(void)
>  {
> +	char write_buf[64];
>  
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +	strcpy(write_buf, "abcdefg");

There is no need for that. Just define the string and use sizeof instead
of strlen, i.e.

#define WRITE_STR "abcdefg"

...
	SAFE_WRITE(1, fd, WRITE_STR, sizeof(WRITE_STR) - 1);
...

Or use SAFE_FILE_PRINTF(), then open() the fd.

> -	TEST_PAUSE;
> +	fd = SAFE_OPEN("tmp_file", O_RDWR | O_CREAT, 0644);
>  
> -	tst_tmpdir();
> -
> -	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));
> -	}
> +	SAFE_WRITE(1, fd, write_buf, strlen(write_buf));
>  }

Otherwise it looks fine.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: cleanup && convert to new API
  2017-06-19  5:00 ` [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: " Xiao Yang
@ 2017-06-19 17:09   ` Cyril Hrubis
  0 siblings, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2017-06-19 17:09 UTC (permalink / raw)
  To: ltp

Hi!
> +#include <stdio.h>
> +#include "tst_test.h"
> +
> +static char fname[255], pname[255];
> +static int bad_fd = -1;
> +static int fd, pfd;
> +static int pfds[2];
> +
> +static struct tcase {
> +	int *fd;
> +	int whence;
> +	int exp_err;
> +} tcases[] = {
> +	{&bad_fd, SEEK_SET, EBADF},
> +	{&bad_fd, SEEK_CUR, EBADF},
> +	{&bad_fd, SEEK_END, EBADF},
> +	{&fd, 5, EINVAL},
> +	{&fd, -1, EINVAL},
> +	{&fd, 7, EINVAL},
> +	{&pfd, SEEK_SET, ESPIPE},
> +	{&pfd, SEEK_CUR, ESPIPE},
> +	{&pfd, SEEK_END, ESPIPE},
> +	{&pfds[0], SEEK_SET, ESPIPE},
> +	{&pfds[0], SEEK_CUR, ESPIPE},
> +	{&pfds[0], SEEK_END, ESPIPE},
> +};
> +
> +static void verify_lseek(unsigned int n)
>  {
> -	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 lseek(2)
> -		 */
> -		TEST(lseek(-1, (long)1, SEEK_SET));
> -
> -		/* check return code */
> -		if (TEST_RETURN == -1) {
> -			if (TEST_ERRNO == EBADF)
> -
> -				tst_resm(TPASS,
> -					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s",
> -					 TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			else
> -				tst_resm(TFAIL,
> -					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s, expected %d(EBADF)",
> -					 TEST_ERRNO,
> -					 strerror(TEST_ERRNO), EBADF);
> -		} else {
> -
> -			tst_resm(TFAIL, "lseek(-1, 1, SEEK_SET) returned %ld",
> -				 TEST_RETURN);
> -		}
> +	struct tcase *tc = &tcases[n];
>  
> +	TEST(lseek(*tc->fd, (off_t) 1, tc->whence));
> +	if (TEST_RETURN != (off_t) -1) {
> +		tst_res(TFAIL, "lseek(%d, 1, %d) succeeded unexpectedly",
> +			*tc->fd, tc->whence);
> +			return;
>  	}
>  
> -	cleanup();
> -	tst_exit();
> +	if (TEST_ERRNO == tc->exp_err) {
> +		tst_res(TPASS | TTERRNO, "lseek(%d, 1, %d) failed as expected",
> +			*tc->fd, tc->whence);
> +	} else {
> +		tst_res(TFAIL | TTERRNO, "lseek(%d, 1, %d) failed "
> +			"unexpectedly, expected %s", *tc->fd, tc->whence,
> +			tst_strerrno(tc->exp_err));
> +	}
>  }
>  
> -/***************************************************************
> - * setup() - performs all ONE TIME setup for this test.
> - ***************************************************************/
> -void setup(void)
> +static void setup(void)
>  {
> +	sprintf(fname, "tfile_%d", getpid());
> +	sprintf(pname, "tpipe_%d", getpid());

Well there is no need to "randomize" the file names since the test has
it's own temporary directory...

> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> +	fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0777);
> +	SAFE_MKFIFO(pname, 0777);
> +	pfd = SAFE_OPEN(pname, O_RDWR, 0777);
> +	SAFE_PIPE(pfds);
>  }

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API
  2017-06-19 16:51 ` [LTP] [PATCH 1/2] syscalls/lseek01, 06: " Cyril Hrubis
@ 2017-06-20  2:16   ` Xiao Yang
  2017-06-20  2:30   ` [LTP] [PATCH v2 " Xiao Yang
  1 sibling, 0 replies; 8+ messages in thread
From: Xiao Yang @ 2017-06-20  2:16 UTC (permalink / raw)
  To: ltp

On 2017/06/20 0:51, Cyril Hrubis wrote:
> Hi!
>> +static int fd;
>> +static struct tcase {
>> +	off_t off;
>> +	int whence;
>> +	off_t exp_off;
>> +	char *exp_data;
>> +} tcases[] = {
>> +	{4, SEEK_SET, 4, "efg"},
>> +	{-2, SEEK_CUR, 5, "fg"},
> This part actually depends on the fact that the file has been seeked and
> read in the previous test. I wonder if it would be less confusing if we
> reset the offset to a defined position (start of the file) before the
> the test.
>
Hi Cyril,

I want to avoid using lseek(2) directly to reset the offset, so i use 
read(2) to reset it to
end of file before every test.
>> +	{-4, SEEK_END, 3, "defg"},
>> +};
>> +
>> +static void verify_lseek(unsigned int n)
>>   {
>> -	int lc;
>> -
>> -	int ind;
>> -	int offset;
>> +	char read_buf[64];
>> +	struct tcase *tc =&tcases[n];
>>
>> -    /***************************************************************
>> -     * parse standard options
>> -     ***************************************************************/
>> -	tst_parse_opts(ac, av, NULL, NULL);
>> +	memset(read_buf, 0, sizeof(read_buf));
>>
>> -    /***************************************************************
>> -     * perform global setup for test
>> -     ***************************************************************/
>> -	setup();
>> -
>> -    /***************************************************************
>> -     * check looping state if -c option given
>> -     ***************************************************************/
>> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
>> -
>> -		tst_count = 0;
>> -
>> -		offset = (lc % 100) * 4096;	/* max size is 100 blocks */
>> -
>> -		for (ind = 0; Whence[ind]>= 0; ind++) {
>> +	TEST(lseek(fd, tc->off, tc->whence));
>> +	if (TEST_RETURN == (off_t) -1) {
>> +		tst_res(TFAIL | TTERRNO, "lseek(%d, %ld, %d) failed", fd,
>> +			tc->off, tc->whence);
>> +		return;
>> +	}
>>
>> -			/*
>> -			 *  Call lseek(2)
>> -			 */
>> -			TEST(lseek(Fd, (long)offset, Whence[ind]));
>> +	if (TEST_RETURN != tc->exp_off) {
>> +		tst_res(TFAIL, "lseek(%d, %ld, %d) returned %ld, expected %ld",
>> +			fd, tc->off, tc->whence, TEST_RETURN, tc->exp_off);
>> +		return;
>> +	}
>>
>> -			/* check return code */
>> -			if (TEST_RETURN == -1) {
>> -				tst_resm(TFAIL,
>> -					 "lseek(%s, %d, 0) Failed, errno=%d : %s",
>> -					 Fname, offset, TEST_ERRNO,
>> -					 strerror(TEST_ERRNO));
>> -			} else {
>> -				tst_resm(TPASS,
>> -					 "lseek(%s, %d, %d) returned %ld",
>> -					 Fname, offset, Whence[ind],
>> -					 TEST_RETURN);
>> -			}
>> -		}
>> +	SAFE_READ(0, fd,&read_buf, sizeof(read_buf));
>>
>> +	if (strcmp(read_buf, tc->exp_data)) {
>> +		tst_res(TFAIL, "lseek(%d, %ld, %d) read incorrect data", fd,
>> +			tc->off, tc->whence);
>> +	} else {
>> +		tst_res(TPASS, "lseek(%d, %ld, %d) read correct data", fd,
>> +			tc->off, tc->whence);
> I guess that the fd here is not that useful and it may be a bit better
> to to translate the whence to its name, but that is very minor.
>
>>   	}
>> -
>> -	cleanup();
>> -	tst_exit();
>>   }
>>
>> -/***************************************************************
>> - * setup() - performs all ONE TIME setup for this test.
>> - ***************************************************************/
>> -void setup(void)
>> +static void setup(void)
>>   {
>> +	char write_buf[64];
>>
>> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
>> +	strcpy(write_buf, "abcdefg");
> There is no need for that. Just define the string and use sizeof instead
> of strlen, i.e.
>
> #define WRITE_STR "abcdefg"
>
> ...
> 	SAFE_WRITE(1, fd, WRITE_STR, sizeof(WRITE_STR) - 1);
> ...
>
> Or use SAFE_FILE_PRINTF(), then open() the fd.
>
>> -	TEST_PAUSE;
>> +	fd = SAFE_OPEN("tmp_file", O_RDWR | O_CREAT, 0644);
>>
>> -	tst_tmpdir();
>> -
>> -	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));
>> -	}
>> +	SAFE_WRITE(1, fd, write_buf, strlen(write_buf));
>>   }
> Otherwise it looks fine.
Thanks for your comment.
I will send v2 patches soon.

Thanks,
Xiao Yang.




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

* [LTP] [PATCH v2 1/2] syscalls/lseek01, 06: cleanup && convert to new API
  2017-06-19 16:51 ` [LTP] [PATCH 1/2] syscalls/lseek01, 06: " Cyril Hrubis
  2017-06-20  2:16   ` Xiao Yang
@ 2017-06-20  2:30   ` Xiao Yang
  2017-06-20  2:30     ` [LTP] [PATCH v2 2/2] syscalls/lseek0[2-5]: " Xiao Yang
  2017-06-20  8:51     ` [LTP] [PATCH v2 1/2] syscalls/lseek01, 06: " Cyril Hrubis
  1 sibling, 2 replies; 8+ messages in thread
From: Xiao Yang @ 2017-06-20  2:30 UTC (permalink / raw)
  To: ltp

1) merge lseek06 into lseek01
2) add tests for SEEK_CUR and SEEK_END

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                           |   1 -
 runtest/stress.part3                      |   1 -
 runtest/syscalls                          |   1 -
 testcases/kernel/syscalls/.gitignore      |   1 -
 testcases/kernel/syscalls/lseek/lseek01.c | 269 +++++++++---------------------
 testcases/kernel/syscalls/lseek/lseek06.c | 202 ----------------------
 6 files changed, 75 insertions(+), 400 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek06.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 909bbdb..7904117 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -410,7 +410,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index d5db1c2..42c2b0e 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -336,7 +336,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/syscalls b/runtest/syscalls
index 8754e3e..fcef347 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -552,7 +552,6 @@ lseek02 lseek02
 lseek03 lseek03
 lseek04 lseek04
 lseek05 lseek05
-lseek06 lseek06
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index d8a38c0..5b8e5b4 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -503,7 +503,6 @@
 /lseek/lseek03
 /lseek/lseek04
 /lseek/lseek05
-/lseek/lseek06
 /lseek/lseek07
 /lseek/lseek08
 /lseek/lseek09
diff --git a/testcases/kernel/syscalls/lseek/lseek01.c b/testcases/kernel/syscalls/lseek/lseek01.c
index a5f8524..28d8267 100644
--- a/testcases/kernel/syscalls/lseek/lseek01.c
+++ b/testcases/kernel/syscalls/lseek/lseek01.c
@@ -1,219 +1,100 @@
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 06/2017 modified by 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 free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ * This program is distributed in the hope that it 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:
+ *  lseek() succeeds to set the specified offset according to whence
+ *  and read valid data from this location.
  */
-/* $Id: lseek01.c,v 1.5 2009/11/02 13:57:17 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for lseek(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 3
- *
- *    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.) lseek(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 lseek(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
- *	lseek(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 <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek01";
-int TST_TOTAL = 3;
-
-char Fname[255];
-int Fd;
-
-int Whence[] = { SEEK_SET, SEEK_CUR, SEEK_END, -1 };
-
-int main(int ac, char **av)
+#include "tst_test.h"
+
+#define WRITE_STR "abcdefg"
+#define TFILE "tfile"
+
+static int fd;
+static struct tcase {
+	off_t off;
+	int whence;
+	char *wname;
+	off_t exp_off;
+	char *exp_data;
+} tcases[] = {
+	{4, SEEK_SET, "SEEK_SET", 4, "efg"},
+	{-2, SEEK_CUR, "SEEK_CUR", 5, "fg"},
+	{-4, SEEK_END, "SEEK_END", 3, "defg"},
+};
+
+static void verify_lseek(unsigned int n)
 {
-	int lc;
-
-	int ind;
-	int offset;
-
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
+	char read_buf[64];
+	struct tcase *tc = &tcases[n];
 
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	setup();
+	// reset the offset to end of file
+	SAFE_READ(0, fd, &read_buf, sizeof(read_buf));
 
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	memset(read_buf, 0, sizeof(read_buf));
 
-		tst_count = 0;
-
-		offset = (lc % 100) * 4096;	/* max size is 100 blocks */
-
-		for (ind = 0; Whence[ind] >= 0; ind++) {
+	TEST(lseek(fd, tc->off, tc->whence));
+	if (TEST_RETURN == (off_t) -1) {
+		tst_res(TFAIL | TTERRNO, "lseek(%s, %ld, %s) failed", TFILE,
+			tc->off, tc->wname);
+		return;
+	}
 
-			/*
-			 *  Call lseek(2)
-			 */
-			TEST(lseek(Fd, (long)offset, Whence[ind]));
+	if (TEST_RETURN != tc->exp_off) {
+		tst_res(TFAIL, "lseek(%s, %ld, %s) returned %ld, expected %ld",
+			TFILE, tc->off, tc->wname, TEST_RETURN, tc->exp_off);
+		return;
+	}
 
-			/* check return code */
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "lseek(%s, %d, 0) Failed, errno=%d : %s",
-					 Fname, offset, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TPASS,
-					 "lseek(%s, %d, %d) returned %ld",
-					 Fname, offset, Whence[ind],
-					 TEST_RETURN);
-			}
-		}
+	SAFE_READ(0, fd, &read_buf, sizeof(read_buf));
 
+	if (strcmp(read_buf, tc->exp_data)) {
+		tst_res(TFAIL, "lseek(%s, %ld, %s) read incorrect data",
+			TFILE, tc->off, tc->wname);
+	} else {
+		tst_res(TPASS, "lseek(%s, %ld, %s) read correct data",
+			TFILE, tc->off, tc->wname);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void setup(void)
 {
+	fd = SAFE_OPEN(TFILE, O_RDWR | O_CREAT, 0644);
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	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));
-	}
+	SAFE_WRITE(1, fd, WRITE_STR, sizeof(WRITE_STR) - 1);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", Fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_lseek,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/lseek/lseek06.c b/testcases/kernel/syscalls/lseek/lseek06.c
deleted file mode 100644
index 056eb40..0000000
--- a/testcases/kernel/syscalls/lseek/lseek06.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: lseek06
- *
- * Test Description:
- *  Verify that, lseek() call succeeds to set the file pointer position
- *  to less  than  or equal to the file size, when a file is opened for
- *  read or write.
- *
- * Expected Result:
- *  lseek() should return the offset from the beginning of the file measured
- *  in bytes. Also check if able to read valid data from this location.
- * $
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *   Create temporary directory.
- *
- *  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,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  lseek06 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
-
-#include "test.h"
-
-#define OFFSET		4
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-
-char *TCID = "lseek06";
-int TST_TOTAL = 1;
-int fildes;			/* file handle for temp file */
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
-{
-	int lc;
-	char read_buf[1];	/* data read from temp. file */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke lseek(2) to move the read/write file
-		 * pointer/handle by OFFSET bytes.
-		 */
-		TEST(lseek(fildes, OFFSET, SEEK_SET));
-
-		if (TEST_RETURN == (off_t) - 1) {
-			tst_resm(TFAIL, "lseek on (%s) Failed, errno=%d : %s",
-				 TEMP_FILE, TEST_ERRNO, strerror(TEST_ERRNO));
-			continue;
-		}
-		/*
-		 * Check if the return value from lseek(2)
-		 * is equal to the specified OFFSET value.
-		 */
-		if (TEST_RETURN != OFFSET) {
-			tst_resm(TFAIL, "lseek() returned incorrect "
-				 "value %ld, expected %d",
-				 TEST_RETURN, OFFSET);
-			continue;
-		}
-		/*
-		 * The return value is good, now check data.
-		 * Read the data byte from this location.
-		 */
-		if (read(fildes, &read_buf, sizeof(read_buf)) < 0) {
-			tst_brkm(TFAIL, cleanup, "read() failed "
-				 "on %s, error=%d", TEMP_FILE, errno);
-		} else {
-			/*
-			 * Check if read byte is the expected character.
-			 * For pos 4 ---> 'e'
-			 */
-			if (read_buf[0] != 'e') {
-				tst_resm(TFAIL, "Incorrect data read "
-					 "from file %s", TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality "
-					 "of lseek() on %s "
-					 "successful", TEMP_FILE);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- *	     Create a temporary directory and change directory to it.
- *	     Create a test file under temporary directory and write some
- *	     data into it.
- */
-void setup(void)
-{
-	char write_buf[BUFSIZ];	/* buffer to hold data */
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Get the data to be written to temporary file */
-	strcpy(write_buf, "abcdefg");
-
-	/* Creat/open a temporary file under above directory */
-	if ((fildes = open(TEMP_FILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) Failed, errno=%d :%s",
-			 TEMP_FILE, FILE_MODE, errno, strerror(errno));
-	}
-
-	/* Write data into temporary file */
-	if (write(fildes, write_buf, strlen(write_buf)) != strlen(write_buf)) {
-		tst_brkm(TBROK, cleanup, "write(2) on %s Failed, errno=%d : %s",
-			 TEMP_FILE, errno, strerror(errno));
-	}
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	       Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	/* Close the temporary file created */
-	if (close(fildes) < 0) {
-		tst_brkm(TFAIL, NULL, "close(%s) Failed, errno=%d : %s:",
-			 TEMP_FILE, errno, strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v2 2/2] syscalls/lseek0[2-5]: cleanup && convert to new API
  2017-06-20  2:30   ` [LTP] [PATCH v2 " Xiao Yang
@ 2017-06-20  2:30     ` Xiao Yang
  2017-06-20  8:51     ` [LTP] [PATCH v2 1/2] syscalls/lseek01, 06: " Cyril Hrubis
  1 sibling, 0 replies; 8+ messages in thread
From: Xiao Yang @ 2017-06-20  2:30 UTC (permalink / raw)
  To: ltp

1) merge lseek03,04,05 into lseek02
2) add combinations of invalid parameters

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                           |   3 -
 runtest/stress.part3                      |   3 -
 runtest/syscalls                          |   3 -
 testcases/kernel/syscalls/.gitignore      |   3 -
 testcases/kernel/syscalls/lseek/lseek02.c | 247 ++++++++++--------------------
 testcases/kernel/syscalls/lseek/lseek03.c | 123 ---------------
 testcases/kernel/syscalls/lseek/lseek04.c | 222 ---------------------------
 testcases/kernel/syscalls/lseek/lseek05.c | 219 --------------------------
 8 files changed, 78 insertions(+), 745 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek03.c
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek04.c
 delete mode 100644 testcases/kernel/syscalls/lseek/lseek05.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 7904117..2826514 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -407,9 +407,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 42c2b0e..67548dc 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -333,9 +333,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/runtest/syscalls b/runtest/syscalls
index fcef347..169bfcd 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -549,9 +549,6 @@ llseek03 llseek03
 
 lseek01 lseek01
 lseek02 lseek02
-lseek03 lseek03
-lseek04 lseek04
-lseek05 lseek05
 lseek07 lseek07
 lseek08 lseek08
 lseek09 lseek09
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 5b8e5b4..9ea4ed8 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -500,9 +500,6 @@
 /llseek/llseek03
 /lseek/lseek01
 /lseek/lseek02
-/lseek/lseek03
-/lseek/lseek04
-/lseek/lseek05
 /lseek/lseek07
 /lseek/lseek08
 /lseek/lseek09
diff --git a/testcases/kernel/syscalls/lseek/lseek02.c b/testcases/kernel/syscalls/lseek/lseek02.c
index 0efc691..3c09879 100644
--- a/testcases/kernel/syscalls/lseek/lseek02.c
+++ b/testcases/kernel/syscalls/lseek/lseek02.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * 06/2017 modified by 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
@@ -17,189 +18,97 @@
  * 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/
- *
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * DESCRIPTION
+ * 1) lseek(2) fails and sets errno to EBADF when fd is invalid.
+ * 2) lseek(2) fails ans sets errno to EINVAL when whence is invalid.
+ * 3) lseek(2) fails and sets errno to ESPIPE when fd is associated
+ *    with a pipe or FIFO.
  */
-/* $Id: lseek02.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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 <sys/types.h>
 #include <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek02";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
-
-int Whence[] = { SEEK_SET, SEEK_CUR, SEEK_END, -1 };
-
-int main(int ac, char **av)
+#include <stdio.h>
+#include "tst_test.h"
+
+#define TFILE "tfile"
+#define TFIFO "tfifo"
+
+static int bad_fd = -1;
+static int fd, pfd;
+static int pfds[2];
+
+static struct tcase {
+	int *fd;
+	int whence;
+	int exp_err;
+} tcases[] = {
+	{&bad_fd, SEEK_SET, EBADF},
+	{&bad_fd, SEEK_CUR, EBADF},
+	{&bad_fd, SEEK_END, EBADF},
+	{&fd, 5, EINVAL},
+	{&fd, -1, EINVAL},
+	{&fd, 7, EINVAL},
+	{&pfd, SEEK_SET, ESPIPE},
+	{&pfd, SEEK_CUR, ESPIPE},
+	{&pfd, SEEK_END, ESPIPE},
+	{&pfds[0], SEEK_SET, ESPIPE},
+	{&pfds[0], SEEK_CUR, ESPIPE},
+	{&pfds[0], SEEK_END, ESPIPE},
+};
+
+static void verify_lseek(unsigned int n)
 {
-	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 lseek(2)
-		 */
-		TEST(lseek(-1, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EBADF)
-
-				tst_resm(TPASS,
-					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(-1, 1, SEEK_SET) Failed, errno=%d : %s, expected %d(EBADF)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EBADF);
-		} else {
-
-			tst_resm(TFAIL, "lseek(-1, 1, SEEK_SET) returned %ld",
-				 TEST_RETURN);
-		}
+	struct tcase *tc = &tcases[n];
 
+	TEST(lseek(*tc->fd, (off_t) 1, tc->whence));
+	if (TEST_RETURN != (off_t) -1) {
+		tst_res(TFAIL, "lseek(%d, 1, %d) succeeded unexpectedly",
+			*tc->fd, tc->whence);
+			return;
 	}
 
-	cleanup();
-	tst_exit();
+	if (TEST_ERRNO == tc->exp_err) {
+		tst_res(TPASS | TTERRNO, "lseek(%d, 1, %d) failed as expected",
+			*tc->fd, tc->whence);
+	} else {
+		tst_res(TFAIL | TTERRNO, "lseek(%d, 1, %d) failed "
+			"unexpectedly, expected %s", *tc->fd, tc->whence,
+			tst_strerrno(tc->exp_err));
+	}
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void setup(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
+	fd = SAFE_OPEN(TFILE, O_RDWR | O_CREAT, 0777);
+	SAFE_MKFIFO(TFIFO, 0777);
+	pfd = SAFE_OPEN(TFIFO, O_RDWR, 0777);
+	SAFE_PIPE(pfds);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+
+	if (pfd > 0)
+		SAFE_CLOSE(pfd);
 
-	tst_rmdir();
+	if (pfds[0] > 0)
+		SAFE_CLOSE(pfds[0]);
 
+	if (pfds[1] > 0)
+		SAFE_CLOSE(pfds[1]);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_lseek,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/lseek/lseek03.c b/testcases/kernel/syscalls/lseek/lseek03.c
deleted file mode 100644
index 02b94fb..0000000
--- a/testcases/kernel/syscalls/lseek/lseek03.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
- *
- * 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/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-
-static void setup(void);
-static void cleanup(void);
-
-static char fname[255];
-static int fd;
-static int whences[] = { 5, -1, 7 };
-
-char *TCID = "lseek03";
-int TST_TOTAL = ARRAY_SIZE(whences);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i;
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			/* Call lseek(2) */
-			TEST(lseek(fd, (off_t) 1, whences[i]));
-
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO == EINVAL) {
-					tst_resm(TPASS,
-						 "lseek(%s, 1, %d) Failed, errno=%d : %s",
-						 fname, whences[i],
-						 TEST_ERRNO,
-						 strerror(TEST_ERRNO));
-				} else {
-					tst_resm(TFAIL,
-						 "lseek(%s, 1, %d) Failed, errno=%d %s, expected %d(EINVAL)",
-						 fname, whences[i],
-						 TEST_ERRNO,
-						 strerror(TEST_ERRNO),
-						 EINVAL);
-				}
-			} else {
-				tst_resm(TFAIL, "lseek(%s, 1, %d) returned %ld",
-					 fname, whences[i], TEST_RETURN);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	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));
-	}
-}
-
-void cleanup(void)
-{
-	if (close(fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/lseek/lseek04.c b/testcases/kernel/syscalls/lseek/lseek04.c
deleted file mode 100644
index 9d431f0..0000000
--- a/testcases/kernel/syscalls/lseek/lseek04.c
+++ /dev/null
@@ -1,222 +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: lseek04.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek04
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(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	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek04";
-int TST_TOTAL = 1;
-
-char Fname[255];
-int Fd;
-
-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;
-
-		/*
-		 *  Call lseek(2)
-		 */
-		TEST(lseek(Fd, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == ESPIPE)
-				tst_resm(TPASS,
-					 "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(fifofd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EINVAL);
-		} else {
-
-			tst_resm(TFAIL,
-				 "lseek(fifofd, 1, SEEK_SET) returned %ld",
-				 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, "tfile_%d", getpid());
-	if (mkfifo(Fname, 0700) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "mkfifo(%s, 0700) Failed, errno=%d : %s",
-			 Fname, errno, strerror(errno));
-	}
-
-	if ((Fd = open(Fname, O_RDWR, 0777)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDWR, 0777) Failed, errno=%d : %s",
-			 Fname, errno, strerror(errno));
-	}
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%s) Failed, errno=%d : %s", Fname, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/lseek/lseek05.c b/testcases/kernel/syscalls/lseek/lseek05.c
deleted file mode 100644
index 1eee03d..0000000
--- a/testcases/kernel/syscalls/lseek/lseek05.c
+++ /dev/null
@@ -1,219 +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: lseek05.c,v 1.5 2009/10/26 14:55:48 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: lseek05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Negative test for lseek(2) of a pipe
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 04/25/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) lseek(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 lseek(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
- *	lseek(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 <unistd.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "lseek05";
-int TST_TOTAL = 1;
-
-int Fd;
-
-/***********************************************************************
- * 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;
-
-		/*
-		 *  Call lseek(2)
-		 */
-		TEST(lseek(Fd, (long)1, SEEK_SET));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == ESPIPE)
-				tst_resm(TPASS,
-					 "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d : %s",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			else
-				tst_resm(TFAIL,
-					 "lseek(pipefd, 1, SEEK_SET) Failed, errno=%d %s, expected %d(ESPIPE)",
-					 TEST_ERRNO,
-					 strerror(TEST_ERRNO), EINVAL);
-		} else {
-
-			tst_resm(TFAIL,
-				 "lseek(pipefd, 1, SEEK_SET) returned %ld",
-				 TEST_RETURN);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-	int fds[2];
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	if (pipe(fds) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "pipe(&fds) Failed, errno=%d : %s", errno,
-			 strerror(errno));
-	}
-	Fd = fds[0];
-
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	/* close the file we have open */
-	if (close(Fd) == -1) {
-		tst_resm(TWARN, "close(%d) Failed, errno=%d : %s", Fd, errno,
-			 strerror(errno));
-	}
-
-	tst_rmdir();
-
-}
-- 
1.8.3.1




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

* [LTP] [PATCH v2 1/2] syscalls/lseek01, 06: cleanup && convert to new API
  2017-06-20  2:30   ` [LTP] [PATCH v2 " Xiao Yang
  2017-06-20  2:30     ` [LTP] [PATCH v2 2/2] syscalls/lseek0[2-5]: " Xiao Yang
@ 2017-06-20  8:51     ` Cyril Hrubis
  1 sibling, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2017-06-20  8:51 UTC (permalink / raw)
  To: ltp

Hi!
Both pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2017-06-20  8:51 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19  5:00 [LTP] [PATCH 1/2] syscalls/lseek01, 06: cleanup && convert to new API Xiao Yang
2017-06-19  5:00 ` [LTP] [PATCH 2/2] syscalls/lseek0[2-5]: " Xiao Yang
2017-06-19 17:09   ` Cyril Hrubis
2017-06-19 16:51 ` [LTP] [PATCH 1/2] syscalls/lseek01, 06: " Cyril Hrubis
2017-06-20  2:16   ` Xiao Yang
2017-06-20  2:30   ` [LTP] [PATCH v2 " Xiao Yang
2017-06-20  2:30     ` [LTP] [PATCH v2 2/2] syscalls/lseek0[2-5]: " Xiao Yang
2017-06-20  8:51     ` [LTP] [PATCH v2 1/2] syscalls/lseek01, 06: " 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.