public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] statfs/statfs02.c: cleanup
@ 2014-05-09 11:24 Zeng Linggang
  2014-05-09 11:39 ` [LTP] [PATCH 2/2] statfs/statfs02.c: Add ELOOP errno test Zeng Linggang
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng Linggang @ 2014-05-09 11:24 UTC (permalink / raw)
  To: ltp-list

From 841dc67dad71b7cdabc4d7d6804467e2cd7a6950 Mon Sep 17 00:00:00 2001
From: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
Date: Fri, 9 May 2014 17:06:54 +0800
Subject: [PATCH] statfs/statfs02.c: cleanup

* Delete some useless commtents.
* Use static.
* Move the test body from main() to statfs_verify().
* Some cleanup.

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/statfs/statfs02.c | 191 ++++++++++------------------
 1 file changed, 67 insertions(+), 124 deletions(-)

diff --git a/testcases/kernel/syscalls/statfs/statfs02.c b/testcases/kernel/syscalls/statfs/statfs02.c
index af839d0..98d9111 100644
--- a/testcases/kernel/syscalls/statfs/statfs02.c
+++ b/testcases/kernel/syscalls/statfs/statfs02.c
@@ -1,30 +1,24 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 Ported by Wayne Boyer
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it 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.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
- * NAME
- *	statfs02.c
- *
  * DESCRIPTION
- *	Testcase to check that statfs(2) sets errno correctly.
- *
- * ALGORITHM
  *	1.	Use a component of the pathname, which is not a directory
  *		in the "path" parameter to statfs(). Expect ENOTDIR
  *	2.	Pass a filename which doesn't exist, and expect ENOENT.
@@ -34,23 +28,8 @@
  *		the process, and expect EFAULT.
  *	5.	Pass a pointer to the buf paramter outside the address space
  *		of the process, and expect EFAULT.
- *
- * USAGE:  <for command-line>
- *  statfs02 [-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
- *	NONE
- *
  */
+
 #include <sys/types.h>
 #include <sys/statfs.h>
 #include <sys/stat.h>
@@ -60,55 +39,45 @@
 #include <errno.h>
 #include "test.h"
 #include "usctest.h"
+#include "safe_macros.h"
 
 char *TCID = "statfs02";
-int fileHandle = 0;
 
-int exp_enos[] = {
+static int exp_enos[] = {
 	ENOTDIR, ENOENT, ENAMETOOLONG,
 #if !defined(UCLINUX)
-	EFAULT, 0
+	EFAULT,
 #endif
+	0
 };
 
-char *bad_addr = 0;
+static int fd;
+
+#define TEST_FILE		"statfs_file"
+#define TEST_FILE1		TEST_FILE"/statfs_file1"
+#define TEST_NOEXIST		"statfs_noexist"
 
-char bad_file[] =
-    "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
-char good_dir[100] = "testdir";
-char fname[30] = "testfile";
-struct statfs fsbuf;
-char fname1[30];
+static char test_toolong[PATH_MAX+2];
+static struct statfs buf;
 
-struct test_case_t {
+static struct test_case_t {
 	char *path;
 	struct statfs *buf;
-	int error;
+	int exp_error;
 } TC[] = {
-	/* path has a component which is not a directory - ENOTDIR */
-	{
-	fname1, &fsbuf, ENOTDIR},
-	    /* path does not exist - ENOENT */
-	{
-	good_dir, &fsbuf, ENOENT},
-	    /* path is too long - ENAMETOOLONG */
-	{
-	bad_file, &fsbuf, ENAMETOOLONG},
+	{TEST_FILE1, &buf, ENOTDIR},
+	{TEST_NOEXIST, &buf, ENOENT},
+	{test_toolong, &buf, ENAMETOOLONG},
 #ifndef UCLINUX
-	    /* Skip since uClinux does not implement memory protection */
-	    /* path is an invalid address - EFAULT */
-	{
-	(char *)-1, &fsbuf, EFAULT},
-	    /* buf is an invalid address - EFAULT */
-	{
-	fname, (struct statfs *)-1, EFAULT}
+	{(char *)-1, &buf, EFAULT},
+	{TEST_FILE, (struct statfs *)-1, EFAULT},
 #endif
 };
 
-int TST_TOTAL = sizeof(TC) / sizeof(*TC);
-
-void setup(void);
-void cleanup(void);
+int TST_TOTAL = ARRAY_SIZE(TC);
+static void setup(void);
+static void cleanup(void);
+static void statfs_verify(const struct test_case_t *);
 
 int main(int ac, char **av)
 {
@@ -116,93 +85,67 @@ int main(int ac, char **av)
 	char *msg;
 	int i;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
+	msg = parse_opts(ac, av, NULL, NULL);
+	if (msg != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
 	setup();
 
-	/* set up the expected errnos */
 	TEST_EXP_ENOS(exp_enos);
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
 		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(statfs(TC[i].path, TC[i].buf));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			TEST_ERROR_LOG(TEST_ERRNO);
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
+		for (i = 0; i < TST_TOTAL; i++)
+			statfs_verify(&TC[i]);
 	}
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 
-	/* make a temporary directory and cd to it */
 	tst_tmpdir();
 
-	sprintf(fname, "%s.%d", fname, getpid());
-	if ((fileHandle = creat(fname, 0444)) == -1) {
-		tst_resm(TFAIL, "creat(2) FAILED to creat temp file");
-	}
-	sprintf(fname1, "%s/%s", fname, fname);
+	fd = SAFE_CREAT(cleanup, TEST_FILE, 0444);
 
-	sprintf(good_dir, "%s.statfs.%d", good_dir, getpid());
+	memset(test_toolong, 'a', PATH_MAX+1);
 
 #if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	TC[3].path = bad_addr;
+	TC[3].path = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
+			       MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 #endif
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void statfs_verify(const struct test_case_t *test)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	close(fileHandle);
+	TEST(statfs(test->path, test->buf));
+
+	if (TEST_RETURN != -1) {
+		tst_resm(TFAIL, "call succeeded unexpectedly");
+		return;
+	}
+
+	TEST_ERROR_LOG(TEST_ERRNO);
+
+	if (TEST_ERRNO == test->exp_error) {
+		tst_resm(TPASS | TTERRNO, "expected failure");
+	} else {
+		tst_resm(TFAIL | TTERRNO, "unexpected error, expected %d",
+			 TEST_ERRNO);
+	}
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		close(fd);
 
 	TEST_CLEANUP;
 
 	tst_rmdir();
-
 }
-- 
1.8.4.2




------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 2/2] statfs/statfs02.c: Add ELOOP errno test
  2014-05-09 11:24 [LTP] [PATCH 1/2] statfs/statfs02.c: cleanup Zeng Linggang
@ 2014-05-09 11:39 ` Zeng Linggang
  2014-05-15 13:03   ` chrubis
  0 siblings, 1 reply; 3+ messages in thread
From: Zeng Linggang @ 2014-05-09 11:39 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 testcases/kernel/syscalls/statfs/statfs02.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/testcases/kernel/syscalls/statfs/statfs02.c b/testcases/kernel/syscalls/statfs/statfs02.c
index 98d9111..6208ec7 100644
--- a/testcases/kernel/syscalls/statfs/statfs02.c
+++ b/testcases/kernel/syscalls/statfs/statfs02.c
@@ -28,6 +28,8 @@
  *		the process, and expect EFAULT.
  *	5.	Pass a pointer to the buf paramter outside the address space
  *		of the process, and expect EFAULT.
+ *	6.	Pass a filename which has too many symbolic links, and expect
+ *		ELOOP.
  */
 
 #include <sys/types.h>
@@ -48,6 +50,7 @@ static int exp_enos[] = {
 #if !defined(UCLINUX)
 	EFAULT,
 #endif
+	ELOOP,
 	0
 };
 
@@ -56,6 +59,7 @@ static int fd;
 #define TEST_FILE		"statfs_file"
 #define TEST_FILE1		TEST_FILE"/statfs_file1"
 #define TEST_NOEXIST		"statfs_noexist"
+#define TEST_SYMLINK		"statfs_symlink"
 
 static char test_toolong[PATH_MAX+2];
 static struct statfs buf;
@@ -72,6 +76,7 @@ static struct test_case_t {
 	{(char *)-1, &buf, EFAULT},
 	{TEST_FILE, (struct statfs *)-1, EFAULT},
 #endif
+	{TEST_SYMLINK, &buf, ELOOP},
 };
 
 int TST_TOTAL = ARRAY_SIZE(TC);
@@ -119,6 +124,9 @@ static void setup(void)
 	TC[3].path = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
 			       MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 #endif
+
+	SAFE_SYMLINK(cleanup, TEST_SYMLINK, "statfs_symlink_2");
+	SAFE_SYMLINK(cleanup, "statfs_symlink_2", TEST_SYMLINK);
 }
 
 static void statfs_verify(const struct test_case_t *test)
-- 
1.8.4.2




------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 2/2] statfs/statfs02.c: Add ELOOP errno test
  2014-05-09 11:39 ` [LTP] [PATCH 2/2] statfs/statfs02.c: Add ELOOP errno test Zeng Linggang
@ 2014-05-15 13:03   ` chrubis
  0 siblings, 0 replies; 3+ messages in thread
From: chrubis @ 2014-05-15 13:03 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
Both pushed, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

end of thread, other threads:[~2014-05-15 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-09 11:24 [LTP] [PATCH 1/2] statfs/statfs02.c: cleanup Zeng Linggang
2014-05-09 11:39 ` [LTP] [PATCH 2/2] statfs/statfs02.c: Add ELOOP errno test Zeng Linggang
2014-05-15 13:03   ` chrubis

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