All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: rewrote testcases
@ 2019-05-20  5:50 Christian Amann
  2019-05-20  5:50 ` [LTP] [PATCH v1 2/2] syscalls/fstat{03,05}: " Christian Amann
  2019-05-28 14:03 ` [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: " Cyril Hrubis
  0 siblings, 2 replies; 3+ messages in thread
From: Christian Amann @ 2019-05-20  5:50 UTC (permalink / raw)
  To: ltp

Merged the two tests:
	fstat01 is a subset of fstat02 and is therefore not needed
	anymore.
Rewrote testcase:
	Cleaned up, ported to new library and added variants to test
	for libc aswell as the raw syscall.

Signed-off-by: Christian Amann <camann@suse.com>
---
 runtest/syscalls                           |   2 -
 testcases/kernel/syscalls/fstat/.gitignore |   2 -
 testcases/kernel/syscalls/fstat/fstat.h    |  34 ++++++
 testcases/kernel/syscalls/fstat/fstat01.c  | 175 -----------------------------
 testcases/kernel/syscalls/fstat/fstat02.c  | 141 +++++++----------------
 5 files changed, 76 insertions(+), 278 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fstat/fstat.h
 delete mode 100644 testcases/kernel/syscalls/fstat/fstat01.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 2b8ca719b..5c2f4cec6 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -334,8 +334,6 @@ fpathconf01 fpathconf01
 fremovexattr01 fremovexattr01
 fremovexattr02 fremovexattr02
 
-fstat01 fstat01
-fstat01_64 fstat01_64
 fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore
index cf5205d44..1c66bdf10 100644
--- a/testcases/kernel/syscalls/fstat/.gitignore
+++ b/testcases/kernel/syscalls/fstat/.gitignore
@@ -1,5 +1,3 @@
-/fstat01
-/fstat01_64
 /fstat02
 /fstat02_64
 /fstat03
diff --git a/testcases/kernel/syscalls/fstat/fstat.h b/testcases/kernel/syscalls/fstat/fstat.h
new file mode 100644
index 000000000..226428071
--- /dev/null
+++ b/testcases/kernel/syscalls/fstat/fstat.h
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) SUSE LLC, 2019
+ * Author: Christian Amann <camann@suse.com>
+ */
+
+#ifndef __FSTAT_H__
+#define __FSTAT_H__
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "lapi/syscalls.h"
+
+#define TEST_VARIANTS	2
+#define TESTFILE	"test_file"
+
+static void syscall_info(void)
+{
+	if (tst_variant == 0) {
+		tst_res(TINFO, "Testing libc fstat()");
+		return;
+	}
+	tst_res(TINFO, "Testing syscall fstat()");
+}
+
+static int tst_fstat(int fd, struct stat *statbuf)
+{
+	if (tst_variant == 0)
+		return fstat(fd, statbuf);
+	return tst_syscall(__NR_fstat, fd, statbuf);
+}
+
+#endif /* __FSTAT_H__ */
diff --git a/testcases/kernel/syscalls/fstat/fstat01.c b/testcases/kernel/syscalls/fstat/fstat01.c
deleted file mode 100644
index a5940c627..000000000
--- a/testcases/kernel/syscalls/fstat/fstat01.c
+++ /dev/null
@@ -1,175 +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: fstat01.c,v 1.6 2009/08/28 12:51:34 vapier Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: fstat01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for fstat(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- *	1.) fstat(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 fstat(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
- *	fstat(2).
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "fstat01";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
-struct stat statter;
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(fstat(fd, &statter));
-
-		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO, "fstat failed");
-		else
-			tst_resm(TPASS, "fstat returned %ld", TEST_RETURN);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(fname, "tfile_%d", getpid());
-	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
-}
-
-void cleanup(void)
-{
-	if (close(fd) == -1)
-		tst_resm(TWARN | TERRNO, "close(%s) failed", fname);
-
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/fstat/fstat02.c b/testcases/kernel/syscalls/fstat/fstat02.c
index 21ef16617..2b95586a4 100644
--- a/testcases/kernel/syscalls/fstat/fstat02.c
+++ b/testcases/kernel/syscalls/fstat/fstat02.c
@@ -1,152 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  *  07/2001 Ported by Wayne Boyer
- *
- * 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
+ *  05/2019 Ported to new library: Christian Amann <camann@suse.com>
  */
 /*
- * fstat() should return value 0 on success and the stat structure elements
- * should be filled with specified 'file' information.
+ * Tests if fstat() returns correctly and reports correct file information
+ * using the stat structure.
  */
-#include <stdio.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
+
 #include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "fstat.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define FILE_MODE	0644
-#define TESTFILE	"testfile"
 #define FILE_SIZE       1024
-#define BUF_SIZE	256
-#define MASK		0777
+#define FILE_MODE	0644
 
-char *TCID = "fstat02";
-int TST_TOTAL = 1;
 static uid_t user_id;
 static gid_t group_id;
 static int fildes;
 
-static void setup(void);
-static void cleanup(void);
-
-static void verify(void)
+static void run(void)
 {
+	int fail;
 	struct stat stat_buf;
-	int fail = 0;
 
-	TEST(fstat(fildes, &stat_buf));
+	TEST(tst_fstat(fildes, &stat_buf));
 
-	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "fstat(%s) failed", TESTFILE);
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "fstat() failed");
 		return;
 	}
 
+	fail = 0;
 	if (stat_buf.st_uid != user_id) {
-		tst_resm(TINFO, "stat_buf.st_uid = %i expected %i",
-		         stat_buf.st_uid, user_id);
+		tst_res(TFAIL, "stat_buf.st_uid = %i expected %i",
+			stat_buf.st_uid, user_id);
 		fail++;
 	}
 
 	if (stat_buf.st_gid != group_id) {
-		tst_resm(TINFO, "stat_buf.st_gid = %i expected %i",
-		         stat_buf.st_gid, group_id);
+		tst_res(TFAIL, "stat_buf.st_gid = %i expected %i",
+			stat_buf.st_gid, group_id);
 		fail++;
 	}
 
 	if (stat_buf.st_size != FILE_SIZE) {
-		tst_resm(TINFO, "stat_buf.st_size = %li expected %i",
-		         (long)stat_buf.st_size, FILE_SIZE);
+		tst_res(TFAIL, "stat_buf.st_size = %li expected %i",
+			(long)stat_buf.st_size, FILE_SIZE);
 		fail++;
 	}
 
-        if ((stat_buf.st_mode & MASK) != FILE_MODE) {
-		tst_resm(TINFO, "stat_buf.st_mode = %o expected %o",
-		         (stat_buf.st_mode & MASK), FILE_MODE);
+	if ((stat_buf.st_mode & 0777) != FILE_MODE) {
+		tst_res(TFAIL, "stat_buf.st_mode = %o expected %o",
+			(stat_buf.st_mode & 0777), FILE_MODE);
 		fail++;
 	}
 
 	if (fail) {
-		tst_resm(TFAIL, "functionality of fstat incorrect");
+		tst_res(TFAIL, "fstat() reported wrong values.");
 		return;
 	}
 
-	tst_resm(TPASS, "functionality of fstat correct");
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		verify();
-
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "fstat() reported correct values.");
 }
 
 static void setup(void)
 {
-	struct passwd *ltpuser;
-	char tst_buff[BUF_SIZE];
-	int wbytes;
-	int write_len = 0;
+	syscall_info();
 
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	ltpuser = SAFE_GETPWNAM(NULL, "nobody");
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	umask(022);
-
-	fildes = SAFE_OPEN(tst_rmdir, TESTFILE, O_WRONLY | O_CREAT, FILE_MODE);
-
-	/* Fill the test buffer with the known data */
-	memset(tst_buff, 'a', BUF_SIZE - 1);
+	user_id  = getuid();
+	group_id = getgid();
 
-	/* Write to the file 1k data from the buffer */
-	while (write_len < FILE_SIZE) {
-		if ((wbytes = write(fildes, tst_buff, sizeof(tst_buff))) <= 0)
-			tst_brkm(TBROK | TERRNO, cleanup, "write failed");
-		else
-			write_len += wbytes;
-	}
+	fildes = SAFE_OPEN(TESTFILE, O_WRONLY | O_CREAT, FILE_MODE);
 
-	user_id = getuid();
-	group_id = getgid();
+	if (tst_fill_file(TESTFILE, 'a', FILE_SIZE, 1))
+		tst_brk(TBROK, "Could not fill Testfile!");
 }
 
 static void cleanup(void)
 {
-	if (close(fildes) == -1)
-		tst_resm(TWARN | TERRNO, "close failed");
-
-	tst_rmdir();
+	if (fildes > 0)
+		SAFE_CLOSE(fildes);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.test_variants = TEST_VARIANTS,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
-- 
2.16.4


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

* [LTP] [PATCH v1 2/2] syscalls/fstat{03,05}: rewrote testcases
  2019-05-20  5:50 [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: rewrote testcases Christian Amann
@ 2019-05-20  5:50 ` Christian Amann
  2019-05-28 14:03 ` [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: " Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Amann @ 2019-05-20  5:50 UTC (permalink / raw)
  To: ltp

Merged fstat03 and fstat05:
	Both testcases had lots of duplicated code which
	could be removed by creating a single testcase
	for both scenarios.
Rewrote testcase:
	Cleaned up and ported to new library.

Signed-off-by: Christian Amann <camann@suse.com>
---
 runtest/syscalls                           |   2 -
 testcases/kernel/syscalls/fstat/.gitignore |   2 -
 testcases/kernel/syscalls/fstat/fstat03.c  | 198 +++++++----------------
 testcases/kernel/syscalls/fstat/fstat05.c  | 244 -----------------------------
 4 files changed, 59 insertions(+), 387 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/fstat/fstat05.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 5c2f4cec6..3cfb99c63 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -338,8 +338,6 @@ fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
 fstat03_64 fstat03_64
-fstat05 fstat05
-fstat05_64 fstat05_64
 
 #fstatat64/newfstatat test cases
 fstatat01 fstatat01
diff --git a/testcases/kernel/syscalls/fstat/.gitignore b/testcases/kernel/syscalls/fstat/.gitignore
index 1c66bdf10..9b1089438 100644
--- a/testcases/kernel/syscalls/fstat/.gitignore
+++ b/testcases/kernel/syscalls/fstat/.gitignore
@@ -2,5 +2,3 @@
 /fstat02_64
 /fstat03
 /fstat03_64
-/fstat05
-/fstat05_64
diff --git a/testcases/kernel/syscalls/fstat/fstat03.c b/testcases/kernel/syscalls/fstat/fstat03.c
index 0fa62b847..c1ee79bc9 100644
--- a/testcases/kernel/syscalls/fstat/fstat03.c
+++ b/testcases/kernel/syscalls/fstat/fstat03.c
@@ -1,160 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Test Name: fstat03
- *
- * Test Description:
- *   Verify that, fstat(2) returns -1 and sets errno to EBADF if the file
- *   pointed to by file descriptor is not valid.
- *
- * Expected Result:
- *  fstat() should fail with return value -1 and set expected errno.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   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)
- *	if errno set == expected errno
- *		Issue sys call fails with expected return value and errno.
- *	Otherwise,
- *		Issue sys call fails with unexpected errno.
- *   Otherwise,
- *	Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  fstat03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be executed by 'non-super-user' only.
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ *  05/2019 Ported to new library: Christian Amann <camann@suse.com>
+ */
+/*
+ * Tests different error scenarios:
  *
+ * 1) Calls fstat() with closed file descriptor
+ *    -> EBADF
+ * 2) Calls fstat() with an invalid address for stat structure
+ *    -> EFAULT
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "fstat.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TEST_FILE	"testfile"
 
-char *TCID = "fstat03";
-int TST_TOTAL = 1;
-
-int fildes;			/* testfile descriptor */
+static int fd_ok;
+static int fd_ebadf;
+static struct stat stat_buf;
 
-void setup();			/* Main setup function for the tests */
-void cleanup();			/* cleanup function for the test */
+static struct tcase{
+	int *fd;
+	struct stat *stat_buf;
+	int exp_err;
+} tcases[] = {
+	{&fd_ebadf, &stat_buf, EBADF},
+	{&fd_ok, NULL, EFAULT},
+};
 
-int main(int ac, char **av)
+static void run(unsigned int n)
 {
-	struct stat stat_buf;	/* stat structure buffer */
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * Invoke setup function to create a testfile under temporary
-	 * directory.
-	 */
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-		/*
-		 * Call fstat(2) to get the status information
-		 * of a closed testfile pointed to by 'fd'.
-		 * verify that fstat fails with -1 return value and
-		 * sets appropriate errno.
-		 */
-		TEST(fstat(fildes, &stat_buf));
-
-		/* Check return code from fstat(2) */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EBADF) {
-				tst_resm(TPASS,
-					 "fstat() fails with expected error EBADF");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "fstat() did not fail with EBADF");
-			}
+	struct tcase *tc = &tcases[n];
+
+	TEST(tst_fstat(*tc->fd, tc->stat_buf));
+	if (TST_RET == -1) {
+		if (tc->exp_err == TST_ERR) {
+			tst_res(TPASS,
+				 "fstat() fails with expected error %s",
+				 tst_strerrno(tc->exp_err));
 		} else {
-			tst_resm(TFAIL, "fstat() returned %ld, expected -1",
-				 TEST_RETURN);
+			tst_res(TFAIL | TTERRNO,
+				 "fstat() did not fail with %s, but with",
+				 tst_strerrno(tc->exp_err));
 		}
-	}
-
-	/*
-	 * Invoke cleanup() to delete the test directory/file(s) created
-	 * in the setup().
-	 */
-	cleanup();
-
-	tst_exit();
+	} else
+		tst_res(TFAIL, "fstat() returned %ld, expected -1",
+			 TST_RET);
 }
 
-/*
- * void
- * setup(void) - performs all ONE TIME setup for this test.
- *	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory and change directory to it.
- *      Create a testfile under temporary directory.
- *      Close the testfile.
- */
-void setup(void)
+static void setup(void)
 {
-	/* Capture unexpected signals */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	syscall_info();
 
-	/* Make a temp dir and cd to it */
-	tst_tmpdir();
-
-	/* Create a testfile under temporary directory */
-	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
-
-	SAFE_CLOSE(cleanup, fildes);
+	fd_ebadf = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0644);
+	SAFE_CLOSE(fd_ebadf);
+	fd_ok = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, 0644);
 }
 
-/*
- * void
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Close the testfile if still opened.
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-
-	tst_rmdir();
-
+	if (fd_ebadf > 0)
+		SAFE_CLOSE(fd_ebadf);
+	if (fd_ok > 0)
+		SAFE_CLOSE(fd_ok);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test_variants = TEST_VARIANTS,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/fstat/fstat05.c b/testcases/kernel/syscalls/fstat/fstat05.c
deleted file mode 100644
index 200de4130..000000000
--- a/testcases/kernel/syscalls/fstat/fstat05.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- *
- *   Copyright (C) Bull S.A. 2001
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is 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: fstat05
- *
- * Test Description:
- *   Verify that,
- *   if buffer points outside user's accessible address space fstat(2)
- *	either returns -1 and sets errno to EFAULT
- *	or SIGSEGV is returned instead of EFAULT
- *
- * Expected Result:
- *   fstat() should fail with return value -1 and set expected errno.
- *    or
- *   fstat() should fail with SIGSEGV returned.
- *   Both results are considered as acceptable.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling SIGSEGV included.
- *   Switch to nobody user.
- *   Pause for SIGUSR1 if option specified.
- *   Create temporary directory.
- *   Create a testfile under temporary directory.
- *
- *  Test:
- *   Buffer points outside user's accessible address space.
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	if errno set == expected errno
- *		Issue sys call fails with expected return value and errno.
- *	Otherwise,
- *		Issue sys call fails with unexpected errno.
- *   Otherwise,
- *	Issue sys call returns unexpected value.
- *
- *  Sighandler:
- *	if signal == SIGSEGV
- *		Issue sys call fails with expected signal
- *      Otherwise,
- *              Issue sys call fails with unexpected signal.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Close the test file
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  fstat05 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	05/2002 Jacky Malcles
- *		-Ported
- *
- * Restrictions:
- *      This test must be run as root.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define TEST_FILE       "testfile"
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-char *TCID = "fstat05";
-int TST_TOTAL = 1;
-
-int fildes;			/* testfile descriptor */
-
-void setup();			/* Main setup function for the tests */
-void cleanup();			/* cleanup function for the test */
-void sighandler(int sig);	/* signals handler function for the test */
-
-int siglist[] = { SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT,
-	SIGBUS, SIGFPE, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM,
-	SIGTERM,
-#ifdef SIGSTKFLT
-	SIGSTKFLT,
-#endif
-	SIGCHLD, SIGCONT, SIGTSTP, SIGTTIN,
-	SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF,
-	SIGWINCH, SIGIO, SIGPWR, SIGSYS,
-#ifdef SIGUNUSED
-	SIGUNUSED
-#endif
-};
-
-int SIG_SEEN = sizeof(siglist) / sizeof(int);
-
-#if !defined(UCLINUX)
-
-int main(int ac, char **av)
-{
-	struct stat *ptr_str = tst_get_bad_addr(NULL);
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * Invoke setup function
-	 */
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call fstat(2).
-		 * verify that it fails with -1 return value and
-		 * sets appropriate errno.
-		 */
-		TEST(fstat(fildes, ptr_str));
-
-		/* Check return code from fstat(2) */
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == EFAULT)
-				tst_resm(TPASS,
-					 "fstat failed with EFAULT as expected");
-			else
-				tst_resm(TFAIL | TTERRNO,
-					 "fstat failed unexpectedly");
-		} else
-			tst_resm(TFAIL, "fstat() returned %ld but we wanted -1",
-				 TEST_RETURN);
-
-	}
-
-	/*
-	 * Invoke cleanup() to delete the test directory/file(s) created
-	 * in the setup().
-	 */
-	cleanup();
-	tst_exit();
-}
-
-#else
-
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "test is not available on uClinux");
-}
-
-#endif /* if !defined(UCLINUX) */
-
-/*
- * void
- * setup(void) - performs all ONE TIME setup for this test.
- *	Exit the test program on receipt of unexpected signals.
- *	Create a temporary directory and change directory to it.
- */
-void setup(void)
-{
-	int i;
-
-	tst_require_root();
-
-	/*
-	 * Capture unexpected signals SIGSEGV included
-	 * SIGSEGV being considered as acceptable as returned value
-	 */
-	for (i = 0; i < SIG_SEEN; i++)
-		signal(siglist[i], &sighandler);
-
-	ltpuser = getpwnam(nobody_uid);
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	tst_tmpdir();
-
-	/* Create a testfile under temporary directory */
-	fildes = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0666);
-
-	TEST_PAUSE;
-}
-
-/*
- * void
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *	Print test timing stats and errno log if test executed with options.
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
-{
-
-	SAFE_CLOSE(cleanup, fildes);
-
-	tst_rmdir();
-
-}
-
-/*
- * sighandler() - handle the signals
- */
-
-void sighandler(int sig)
-{
-	if (sig == SIGSEGV)
-		tst_resm(TPASS, "fstat failed as expected with SIGSEGV");
-	else
-		tst_brkm(TBROK, NULL, "Unexpected signal %d received.", sig);
-	cleanup();
-	tst_exit();
-}
-- 
2.16.4


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

* [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: rewrote testcases
  2019-05-20  5:50 [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: rewrote testcases Christian Amann
  2019-05-20  5:50 ` [LTP] [PATCH v1 2/2] syscalls/fstat{03,05}: " Christian Amann
@ 2019-05-28 14:03 ` Cyril Hrubis
  1 sibling, 0 replies; 3+ messages in thread
From: Cyril Hrubis @ 2019-05-28 14:03 UTC (permalink / raw)
  To: ltp

Hi!
> +++ b/testcases/kernel/syscalls/fstat/fstat.h
> @@ -0,0 +1,34 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) SUSE LLC, 2019
> + * Author: Christian Amann <camann@suse.com>
> + */
> +
> +#ifndef __FSTAT_H__
> +#define __FSTAT_H__
> +
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +#include "lapi/syscalls.h"
> +
> +#define TEST_VARIANTS	2
> +#define TESTFILE	"test_file"
> +
> +static void syscall_info(void)
> +{
> +	if (tst_variant == 0) {
> +		tst_res(TINFO, "Testing libc fstat()");
> +		return;
> +	}
> +	tst_res(TINFO, "Testing syscall fstat()");
> +}
> +
> +static int tst_fstat(int fd, struct stat *statbuf)
> +{
> +	if (tst_variant == 0)
> +		return fstat(fd, statbuf);
> +	return tst_syscall(__NR_fstat, fd, statbuf);
> +}

Have you tested this wrapper with 32bit binary?

Because on x86 (among others) we do have fstat and fstat64 that differ
in the statbuf structure size (see man fstat NOTES). If I add a printf()
to print sizeof(struct stat) to the fstat01.c test on x86 I get 96 bytes
with _FILE_OFFSET_BITS=64 and 88 without, so I guess that this uses
wrong syscall with the _FILE_OFFSET_BITS=64 defined.

And actually there are three fstat variants there, the old_fstat, fstat
and fstat64, we could probably test all three variants but I guess that
old_fstat is actually not worth of the effort...

HINT: You can compile 32bit LTP on 64bit distribution with:
      ./configure CFLAGS=-m32 LDFLAGS=-m32.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2019-05-28 14:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-20  5:50 [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: rewrote testcases Christian Amann
2019-05-20  5:50 ` [LTP] [PATCH v1 2/2] syscalls/fstat{03,05}: " Christian Amann
2019-05-28 14:03 ` [LTP] [PATCH v1 1/2] syscalls/fstat{01,02}: " 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.