All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API
@ 2016-07-28  9:38 Guangwen Feng
  2016-07-28  9:38 ` [LTP] [PATCH 2/2] syscalls/access05: " Guangwen Feng
  2016-08-04 16:50 ` [LTP] [PATCH 1/2] syscalls/access04: " Cyril Hrubis
  0 siblings, 2 replies; 10+ messages in thread
From: Guangwen Feng @ 2016-07-28  9:38 UTC (permalink / raw)
  To: ltp

* take use of some SAFE Marcos
* add test as root and nobody respectively

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/access/access04.c | 126 +++++++++++-----------------
 1 file changed, 47 insertions(+), 79 deletions(-)

diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c
index 49e7057..4996e3c 100644
--- a/testcases/kernel/syscalls/access/access04.c
+++ b/testcases/kernel/syscalls/access/access04.c
@@ -20,110 +20,78 @@
 /*
  * Test Description:
  *  Verify that access() succeeds to check the existance of a file if
- *  search access is permitted on the pathname of the specified file.
+ *  search access is permitted on the pathname of the specified file
+ *  as root and nobody respectively.
  *
  *  07/2001 Ported by Wayne Boyer
+ *  07/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
 #include <pwd.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include "tst_test.h"
 
-#include "test.h"
-
-#define TESTDIR		"testdir"
-#define TESTFILE	"testdir/testfile"
-#define DIR_MODE	(S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
-#define FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
-
-char *TCID = "access04";
-int TST_TOTAL = 1;
-
-static const char nobody_uid[] = "nobody";
-static struct passwd *ltpuser;
+#define FNAME "accessfile"
 
-static void setup(void);
-static void cleanup(void);
+static uid_t uid;
 
-int main(int ac, char **av)
+static void access_test(const char *user)
 {
 	struct stat stat_buf;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
 
-	setup();
+	TEST(access(FNAME, F_OK));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(access(TESTFILE, F_OK));
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO,
+			"access(%s, F_OK) as %s failed", FNAME, user);
+		return;
+	}
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "access(%s, F_OK) failed",
-				 TESTFILE);
-			continue;
-		}
+	TEST(stat(FNAME, &stat_buf));
 
-		if (stat(TESTFILE, &stat_buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed",
-				 TESTFILE);
-		} else {
-			tst_resm(TPASS, "functionality of "
-				 "access(%s, F_OK) ok", TESTFILE);
-		}
+	if (TEST_RETURN == -1) {
+		tst_res(TFAIL | TTERRNO,
+			"stat(%s) as %s failed", FNAME, user);
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "access(%s, F_OK) as %s behaviour is correct",
+		FNAME, user);
 }
 
-static void setup(void)
+static void verify_access(void)
 {
-	int fd;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	tst_require_root();
-
-	ltpuser = getpwnam(nobody_uid);
-	if (ltpuser == NULL)
-		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
+	pid_t pid;
 
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TINFO | TERRNO, NULL, "setuid failed");
+	access_test("root");
 
-	TEST_PAUSE;
-	tst_tmpdir();
-
-	if (mkdir(TESTDIR, DIR_MODE) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
-			 TESTDIR, DIR_MODE);
+	pid = SAFE_FORK();
+	if (pid) {
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		SAFE_SETUID(uid);
+		access_test("nobody");
+	}
+}
 
-	if (chmod(TESTDIR, DIR_MODE) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, %#o) failed",
-			 TESTDIR, DIR_MODE);
+static void setup(void)
+{
+	struct passwd *pw;
 
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
-			 TESTFILE, FILE_MODE);
+	pw = SAFE_GETPWNAM("nobody");
 
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", TESTFILE);
+	uid = pw->pw_uid;
 
-	if (chmod(TESTFILE, 0) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "chmod(%s, 0) failed", TESTFILE);
+	SAFE_TOUCH(FNAME, 0644, NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tid = "access04",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.test_all = verify_access
+};
-- 
1.8.4.2




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

* [LTP] [PATCH 2/2] syscalls/access05: reconstruct and convert to new API
  2016-07-28  9:38 [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API Guangwen Feng
@ 2016-07-28  9:38 ` Guangwen Feng
  2016-09-09  7:31   ` Guangwen Feng
  2016-09-22 15:47   ` Cyril Hrubis
  2016-08-04 16:50 ` [LTP] [PATCH 1/2] syscalls/access04: " Cyril Hrubis
  1 sibling, 2 replies; 10+ messages in thread
From: Guangwen Feng @ 2016-07-28  9:38 UTC (permalink / raw)
  To: ltp

* remove duplicate test EACCES and EFAULT
* do UCLINUX check in Makefile instead
* add test as root and nobody respectively

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/access/Makefile   |   2 +-
 testcases/kernel/syscalls/access/access05.c | 219 +++++++++-------------------
 2 files changed, 66 insertions(+), 155 deletions(-)

diff --git a/testcases/kernel/syscalls/access/Makefile b/testcases/kernel/syscalls/access/Makefile
index 06aaf9f..52c1970 100644
--- a/testcases/kernel/syscalls/access/Makefile
+++ b/testcases/kernel/syscalls/access/Makefile
@@ -19,7 +19,7 @@
 top_srcdir		?= ../../../..
 
 ifeq ($(UCLINUX),1)
-FILTER_OUT_MAKE_TARGETS += access02 access03
+FILTER_OUT_MAKE_TARGETS += access02 access03 access05
 endif
 
 include $(top_srcdir)/include/mk/testcases.mk
diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c
index 3b88515..a645397 100644
--- a/testcases/kernel/syscalls/access/access05.c
+++ b/testcases/kernel/syscalls/access/access05.c
@@ -20,197 +20,108 @@
 /*
  * Test Description:
  *  Verify that,
- *   1. access() fails with -1 return value and sets errno to EACCES
- *      if the permission bits of the file mode do not permit the
- *	 requested (Read/Write/Execute) access.
- *   2. access() fails with -1 return value and sets errno to EINVAL
+ *   1. access() fails with -1 return value and sets errno to EINVAL
  *	if the specified access mode argument is invalid.
- *   3. access() fails with -1 return value and sets errno to EFAULT
- *	if the pathname points outside allocate address space for the
- *	process.
- *   4. access() fails with -1 return value and sets errno to ENOENT
+ *   2. access() fails with -1 return value and sets errno to ENOENT
  *	if the specified file doesn't exist (or pathname is NULL).
- *   5. access() fails with -1 return value and sets errno to ENAMETOOLONG
+ *   3. access() fails with -1 return value and sets errno to ENAMETOOLONG
  *      if the pathname size is > PATH_MAX characters.
- *   6. access() fails with -1 return value and sets errno to ENOTDIR
+ *   4. access() fails with -1 return value and sets errno to ENOTDIR
  *      if a component used as a directory in pathname is not a directory.
- *   7. access() fails with -1 return value and sets errno to ELOOP
+ *   5. access() fails with -1 return value and sets errno to ELOOP
  *      if too many symbolic links were encountered in resolving pathname.
  *
  *   07/2001 Ported by Wayne Boyer
+ *   07/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  */
 
-#include <stdio.h>
 #include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
+#include <pwd.h>
 #include <string.h>
-#include <signal.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define INV_OK		-1
-#define TEST_FILE1	"test_file1"
-#define TEST_FILE2	"test_file2"
-#define TEST_FILE3	"test_file3"
-#define TEST_FILE4	"test_file4"
-#define TEST_FILE5	"test_file5/test_file5"
-#define TEST_FILE6	"test_file6"
-
+#include <unistd.h>
+#include "tst_test.h"
 
-#if !defined(UCLINUX)
-static char high_address_node[64];
-#endif
+#define	INV_OK	-1
+#define FNAME1	"accessfile1"
+#define FNAME2	"accessfile2/accessfile2"
+#define DNAME	"accessfile2"
+#define SNAME1	"symlink1"
+#define SNAME2	"symlink2"
 
+static uid_t uid;
 static char longpathname[PATH_MAX + 2];
 
-static struct test_case_t {
-	char *pathname;
-	int a_mode;
+static struct tcase {
+	const char *pathname;
+	int mode;
 	int exp_errno;
-} test_cases[] = {
-	{TEST_FILE1, R_OK, EACCES},
-	{TEST_FILE2, W_OK, EACCES},
-	{TEST_FILE3, X_OK, EACCES},
-	{TEST_FILE4, INV_OK, EINVAL},
-#if !defined(UCLINUX)
-	{(char *)-1, R_OK, EFAULT},
-	{high_address_node, R_OK, EFAULT},
-#endif
+} tcases[] = {
+	{FNAME1, INV_OK, EINVAL},
 	{"", W_OK, ENOENT},
 	{longpathname, R_OK, ENAMETOOLONG},
-	{TEST_FILE5, R_OK, ENOTDIR},
-	{TEST_FILE6, R_OK, ELOOP},
+	{FNAME2, R_OK, ENOTDIR},
+	{SNAME1, R_OK, ELOOP}
 };
 
-char *TCID = "access05";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static const char nobody_uid[] = "nobody";
-static struct passwd *ltpuser;
-
-static void setup(void);
-static void access_verify(int i);
-static void cleanup(void);
-
-static char *bad_addr;
-
-int main(int ac, char **av)
+static void access_test(struct tcase *tc, const char *user)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
+	TEST(access(tc->pathname, tc->mode));
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	if (TEST_RETURN != -1) {
+		tst_res(TFAIL, "access as %s succeeded unexpectedly", user);
+		return;
+	}
 
-		for (i = 0; i < TST_TOTAL; i++)
-			access_verify(i);
+	if (TEST_ERRNO != tc->exp_errno) {
+		tst_res(TFAIL | TTERRNO,
+			"access as %s should fail with %s",
+			user, tst_strerrno(tc->exp_errno));
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS | TTERRNO, "access as %s failed expectedly", user);
 }
 
-static void setup(void)
+static void verify_access(unsigned int n)
 {
-	int fd;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	tst_require_root();
-
-	ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
-	SAFE_SETUID(cleanup, ltpuser->pw_uid);
-	TEST_PAUSE;
-
-#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 | TERRNO, NULL, "mmap failed");
-	test_cases[4].pathname = bad_addr;
-
-	test_cases[5].pathname = get_high_address();
-#endif
-
-	tst_tmpdir();
-
-	/*
-	 * create TEST_FILE1 to test R_OK EACCESS
-	 */
-	fd = SAFE_CREAT(cleanup, TEST_FILE1, 0333);
-	SAFE_CLOSE(cleanup, fd);
-
-	/*
-	 * create TEST_FILE2 to test W_OK EACCESS
-	 */
-	fd = SAFE_CREAT(cleanup, TEST_FILE2, 0555);
-	SAFE_CLOSE(cleanup, fd);
-
-	/*
-	 * create TEST_FILE3 to test X_OK EACCESS
-	 */
-	fd = SAFE_CREAT(cleanup, TEST_FILE3, 0666);
-	SAFE_CLOSE(cleanup, fd);
-
-	/*
-	 * create TEST_FILE4 to test EINVAL
-	 */
-	fd = SAFE_CREAT(cleanup, TEST_FILE4, 0333);
-	SAFE_CLOSE(cleanup, fd);
-
-	/*
-	 *setup to create a node with a name length exceeding
-	 *the MAX length of PATH_MAX.
-	 */
-	memset(longpathname, 'a', sizeof(longpathname) - 1);
+	struct tcase *tc = tcases + n;
+	pid_t pid;
 
-	/* create test_file5 for test ENOTDIR. */
-	SAFE_TOUCH(cleanup, "test_file5", 0644, NULL);
+	access_test(tc, "root");
 
-	/*
-	 * create two symbolic links who point to each other for
-	 * test ELOOP.
-	 */
-	SAFE_SYMLINK(cleanup, "test_file6", "test_file7");
-	SAFE_SYMLINK(cleanup, "test_file7", "test_file6");
+	pid = SAFE_FORK();
+	if (pid) {
+		SAFE_WAITPID(pid, NULL, 0);
+	} else {
+		SAFE_SETUID(uid);
+		access_test(tc, "nobody");
+	}
 }
 
-static void access_verify(int i)
+static void setup(void)
 {
-	char *file_name;
-	int access_mode;
+	struct passwd *pw;
 
-	file_name = test_cases[i].pathname;
-	access_mode = test_cases[i].a_mode;
+	pw = SAFE_GETPWNAM("nobody");
 
-	TEST(access(file_name, access_mode));
+	uid = pw->pw_uid;
 
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "access(%s, %#o) succeeded unexpectedly",
-			 file_name, access_mode);
-		return;
-	}
+	memset(longpathname, 'a', sizeof(longpathname) - 1);
 
-	if (TEST_ERRNO == test_cases[i].exp_errno) {
-		tst_resm(TPASS | TTERRNO, "access failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "access failed unexpectedly; expected: "
-			 "%d - %s", test_cases[i].exp_errno,
-			 strerror(test_cases[i].exp_errno));
-	}
-}
+	SAFE_TOUCH(FNAME1, 0333, NULL);
+	SAFE_TOUCH(DNAME, 0644, NULL);
 
-static void cleanup(void)
-{
-	tst_rmdir();
+	SAFE_SYMLINK(SNAME1, SNAME2);
+	SAFE_SYMLINK(SNAME2, SNAME1);
 }
+
+static struct tst_test test = {
+	.tid = "access05",
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.test = verify_access,
+	.tcnt = ARRAY_SIZE(tcases)
+};
-- 
1.8.4.2




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

* [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API
  2016-07-28  9:38 [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API Guangwen Feng
  2016-07-28  9:38 ` [LTP] [PATCH 2/2] syscalls/access05: " Guangwen Feng
@ 2016-08-04 16:50 ` Cyril Hrubis
  2016-08-05 10:08   ` Guangwen Feng
  2016-08-19  9:19   ` [LTP] [PATCH 1/2] syscalls/access01: add testcases with files in subdirectory Guangwen Feng
  1 sibling, 2 replies; 10+ messages in thread
From: Cyril Hrubis @ 2016-08-04 16:50 UTC (permalink / raw)
  To: ltp

Hi!
Once we remote the directory the accessfile is in this is just the same
as access01.c.

Looks like the whole point of the test was to put the file into a
directory and pass the path to the syscall.

What about we remote this test and add a few more cases with a file in
subdirectory to the access01 test instead?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API
  2016-08-04 16:50 ` [LTP] [PATCH 1/2] syscalls/access04: " Cyril Hrubis
@ 2016-08-05 10:08   ` Guangwen Feng
  2016-08-09 13:14     ` Cyril Hrubis
  2016-08-19  9:19   ` [LTP] [PATCH 1/2] syscalls/access01: add testcases with files in subdirectory Guangwen Feng
  1 sibling, 1 reply; 10+ messages in thread
From: Guangwen Feng @ 2016-08-05 10:08 UTC (permalink / raw)
  To: ltp

Hi!

Thanks for your comments!

On 08/05/2016 12:50 AM, Cyril Hrubis wrote:
> Hi!
> Once we remote the directory the accessfile is in this is just the same
> as access01.c.
> 

Sorry, do you mean once we "remote" the directory? or "remove" the directory?
And I think access04 does a little more: checks if the file exists actually
via stat(), maybe I should add this part(check existence) to access02?

> Looks like the whole point of the test was to put the file into a
> directory and pass the path to the syscall.
> 
> What about we remote this test and add a few more cases with a file in
> subdirectory to the access01 test instead?
> 

OK, I will put this part into access01 and add a few more cases instead, thanks.

Regards,
Guangwen Feng



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

* [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API
  2016-08-05 10:08   ` Guangwen Feng
@ 2016-08-09 13:14     ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2016-08-09 13:14 UTC (permalink / raw)
  To: ltp

Hi!
> > Once we remote the directory the accessfile is in this is just the same
> > as access01.c.
> > 
> 
> Sorry, do you mean once we "remote" the directory? or "remove" the directory?
> And I think access04 does a little more: checks if the file exists actually
> via stat(), maybe I should add this part(check existence) to access02?

Yep, I typed remote instead of remove instead of remove twice in this
email.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 1/2] syscalls/access01: add testcases with files in subdirectory
  2016-08-04 16:50 ` [LTP] [PATCH 1/2] syscalls/access04: " Cyril Hrubis
  2016-08-05 10:08   ` Guangwen Feng
@ 2016-08-19  9:19   ` Guangwen Feng
  2016-08-19  9:19     ` [LTP] [PATCH 2/2] syscalls/access02: add behaviour check for F_OK Guangwen Feng
  1 sibling, 1 reply; 10+ messages in thread
From: Guangwen Feng @ 2016-08-19  9:19 UTC (permalink / raw)
  To: ltp

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 testcases/kernel/syscalls/access/access01.c | 196 +++++++++++++++++++++++++++-
 1 file changed, 192 insertions(+), 4 deletions(-)

diff --git a/testcases/kernel/syscalls/access/access01.c b/testcases/kernel/syscalls/access/access01.c
index a445edd..25e13b7 100644
--- a/testcases/kernel/syscalls/access/access01.c
+++ b/testcases/kernel/syscalls/access/access01.c
@@ -32,9 +32,16 @@
 #include "tst_test.h"
 
 #define FNAME_RWX "accessfile_rwx"
-#define FNAME_R   "accesfile_r"
-#define FNAME_W   "accesfile_w"
-#define FNAME_X   "accesfile_x"
+#define FNAME_R   "accessfile_r"
+#define FNAME_W   "accessfile_w"
+#define FNAME_X   "accessfile_x"
+
+#define DNAME_R   "accessdir_r"
+#define DNAME_W   "accessdir_w"
+#define DNAME_X   "accessdir_x"
+#define DNAME_RW  "accessdir_rw"
+#define DNAME_RX  "accessdir_rx"
+#define DNAME_WX  "accessdir_wx"
 
 static uid_t uid;
 
@@ -90,7 +97,157 @@ static struct tcase {
 
 	{FNAME_X, R_OK, "R_OK", 0, 2},
 	{FNAME_X, W_OK, "W_OK", 0, 2},
-	{FNAME_X, R_OK|W_OK, "R_OK|W_OK", 0, 2}
+	{FNAME_X, R_OK|W_OK, "R_OK|W_OK", 0, 2},
+
+	{DNAME_R"/"FNAME_R, F_OK, "F_OK", 0, 2},
+	{DNAME_R"/"FNAME_R, R_OK, "R_OK", 0, 2},
+	{DNAME_R"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_R"/"FNAME_W, F_OK, "F_OK", 0, 2},
+	{DNAME_R"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_R"/"FNAME_W, W_OK, "W_OK", 0, 2},
+
+	{DNAME_R"/"FNAME_X, F_OK, "F_OK", 0, 2},
+	{DNAME_R"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_R"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_R"/"FNAME_X, X_OK, "X_OK", 0, 2},
+
+	{DNAME_W"/"FNAME_R, F_OK, "F_OK", 0, 2},
+	{DNAME_W"/"FNAME_R, R_OK, "R_OK", 0, 2},
+	{DNAME_W"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_W"/"FNAME_W, F_OK, "F_OK", 0, 2},
+	{DNAME_W"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_W"/"FNAME_W, W_OK, "W_OK", 0, 2},
+
+	{DNAME_W"/"FNAME_X, F_OK, "F_OK", 0, 2},
+	{DNAME_W"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_W"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_W"/"FNAME_X, X_OK, "X_OK", 0, 2},
+
+	{DNAME_X"/"FNAME_R, F_OK, "F_OK", 0, 3},
+	{DNAME_X"/"FNAME_R, R_OK, "R_OK", 0, 3},
+	{DNAME_X"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_X"/"FNAME_W, F_OK, "F_OK", 0, 3},
+	{DNAME_X"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_X"/"FNAME_W, W_OK, "W_OK", 0, 3},
+
+	{DNAME_X"/"FNAME_X, F_OK, "F_OK", 0, 3},
+	{DNAME_X"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_X"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_X"/"FNAME_X, X_OK, "X_OK", 0, 3},
+
+	{DNAME_RW"/"FNAME_R, F_OK, "F_OK", 0, 2},
+	{DNAME_RW"/"FNAME_R, R_OK, "R_OK", 0, 2},
+	{DNAME_RW"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_RW"/"FNAME_W, F_OK, "F_OK", 0, 2},
+	{DNAME_RW"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_RW"/"FNAME_W, W_OK, "W_OK", 0, 2},
+
+	{DNAME_RW"/"FNAME_X, F_OK, "F_OK", 0, 2},
+	{DNAME_RW"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_RW"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_RW"/"FNAME_X, X_OK, "X_OK", 0, 2},
+
+	{DNAME_RX"/"FNAME_R, F_OK, "F_OK", 0, 3},
+	{DNAME_RX"/"FNAME_R, R_OK, "R_OK", 0, 3},
+	{DNAME_RX"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_RX"/"FNAME_W, F_OK, "F_OK", 0, 3},
+	{DNAME_RX"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_RX"/"FNAME_W, W_OK, "W_OK", 0, 3},
+
+	{DNAME_RX"/"FNAME_X, F_OK, "F_OK", 0, 3},
+	{DNAME_RX"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_RX"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_RX"/"FNAME_X, X_OK, "X_OK", 0, 3},
+
+	{DNAME_WX"/"FNAME_R, F_OK, "F_OK", 0, 3},
+	{DNAME_WX"/"FNAME_R, R_OK, "R_OK", 0, 3},
+	{DNAME_WX"/"FNAME_R, W_OK, "W_OK", 0, 2},
+
+	{DNAME_WX"/"FNAME_W, F_OK, "F_OK", 0, 3},
+	{DNAME_WX"/"FNAME_W, R_OK, "R_OK", 0, 2},
+	{DNAME_WX"/"FNAME_W, W_OK, "W_OK", 0, 3},
+
+	{DNAME_WX"/"FNAME_X, F_OK, "F_OK", 0, 3},
+	{DNAME_WX"/"FNAME_X, R_OK, "R_OK", 0, 2},
+	{DNAME_WX"/"FNAME_X, W_OK, "W_OK", 0, 2},
+	{DNAME_WX"/"FNAME_X, X_OK, "X_OK", 0, 3},
+
+	{DNAME_R"/"FNAME_R, F_OK, "F_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_R, R_OK, "R_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_R"/"FNAME_W, F_OK, "F_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_W, W_OK, "W_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_R"/"FNAME_X, F_OK, "F_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_X, W_OK, "W_OK", EACCES, 1},
+	{DNAME_R"/"FNAME_X, X_OK, "X_OK", EACCES, 1},
+
+	{DNAME_W"/"FNAME_R, F_OK, "F_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_R, R_OK, "R_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_W"/"FNAME_W, F_OK, "F_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_W, W_OK, "W_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_W"/"FNAME_X, F_OK, "F_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_X, W_OK, "W_OK", EACCES, 1},
+	{DNAME_W"/"FNAME_X, X_OK, "X_OK", EACCES, 1},
+
+	{DNAME_X"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_X"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_X"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_X"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_X"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_X"/"FNAME_X, W_OK, "W_OK", EACCES, 1},
+
+	{DNAME_RW"/"FNAME_R, F_OK, "F_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_R, R_OK, "R_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_RW"/"FNAME_W, F_OK, "F_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_W, W_OK, "W_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_RW"/"FNAME_X, F_OK, "F_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_X, W_OK, "W_OK", EACCES, 1},
+	{DNAME_RW"/"FNAME_X, X_OK, "X_OK", EACCES, 1},
+
+	{DNAME_RX"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_RX"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_RX"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_RX"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_RX"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_RX"/"FNAME_X, W_OK, "W_OK", EACCES, 1},
+
+	{DNAME_WX"/"FNAME_R, W_OK, "W_OK", EACCES, 1},
+	{DNAME_WX"/"FNAME_R, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_WX"/"FNAME_W, R_OK, "R_OK", EACCES, 1},
+	{DNAME_WX"/"FNAME_W, X_OK, "X_OK", EACCES, 3},
+
+	{DNAME_WX"/"FNAME_X, R_OK, "R_OK", EACCES, 1},
+	{DNAME_WX"/"FNAME_X, W_OK, "W_OK", EACCES, 1}
 };
 
 static void verify_success(struct tcase *tc, const char *user)
@@ -166,6 +323,37 @@ static void setup(void)
 	SAFE_TOUCH(FNAME_R, 0444, NULL);
 	SAFE_TOUCH(FNAME_W, 0222, NULL);
 	SAFE_TOUCH(FNAME_X, 0111, NULL);
+
+	SAFE_MKDIR(DNAME_R, 0444);
+	SAFE_MKDIR(DNAME_W, 0222);
+	SAFE_MKDIR(DNAME_X, 0111);
+	SAFE_MKDIR(DNAME_RW, 0666);
+	SAFE_MKDIR(DNAME_RX, 0555);
+	SAFE_MKDIR(DNAME_WX, 0333);
+
+	SAFE_TOUCH(DNAME_R"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_R"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_R"/"FNAME_X, 0111, NULL);
+
+	SAFE_TOUCH(DNAME_W"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_W"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_W"/"FNAME_X, 0111, NULL);
+
+	SAFE_TOUCH(DNAME_X"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_X"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_X"/"FNAME_X, 0111, NULL);
+
+	SAFE_TOUCH(DNAME_RW"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_RW"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_RW"/"FNAME_X, 0111, NULL);
+
+	SAFE_TOUCH(DNAME_RX"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_RX"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_RX"/"FNAME_X, 0111, NULL);
+
+	SAFE_TOUCH(DNAME_WX"/"FNAME_R, 0444, NULL);
+	SAFE_TOUCH(DNAME_WX"/"FNAME_W, 0222, NULL);
+	SAFE_TOUCH(DNAME_WX"/"FNAME_X, 0111, NULL);
 }
 
 static struct tst_test test = {
-- 
1.8.4.2




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

* [LTP] [PATCH 2/2] syscalls/access02: add behaviour check for F_OK
  2016-08-19  9:19   ` [LTP] [PATCH 1/2] syscalls/access01: add testcases with files in subdirectory Guangwen Feng
@ 2016-08-19  9:19     ` Guangwen Feng
  2016-08-24 14:44       ` Cyril Hrubis
  0 siblings, 1 reply; 10+ messages in thread
From: Guangwen Feng @ 2016-08-19  9:19 UTC (permalink / raw)
  To: ltp

Add F_OK check of access04 to access02, and remove access04.

Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
 runtest/ltplite                             |   1 -
 runtest/stress.part3                        |   1 -
 runtest/syscalls                            |   1 -
 testcases/kernel/syscalls/.gitignore        |   1 -
 testcases/kernel/syscalls/access/access02.c |  32 +++++--
 testcases/kernel/syscalls/access/access04.c | 129 ----------------------------
 6 files changed, 27 insertions(+), 138 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/access/access04.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 00898f2..2f8fbaf 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -64,7 +64,6 @@ accept01 accept01
 access01 access01
 access02 access02
 access03 access03
-access04 access04
 access05 access05
 access06 access06
 
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 7c74ea0..537e450 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -6,7 +6,6 @@ accept01 accept01
 access01 access01
 access02 access02
 access03 access03
-access04 access04
 access05 access05
 access06 access06
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 9ccf851..53d6f32 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -7,7 +7,6 @@ accept4_01 accept4_01
 access01 access01
 access02 access02
 access03 access03
-access04 access04
 access05 access05
 access06 access06
 
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 10bd62a..a13dbb3 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -4,7 +4,6 @@
 /access/access01
 /access/access02
 /access/access03
-/access/access04
 /access/access05
 /access/access06
 /acct/acct01
diff --git a/testcases/kernel/syscalls/access/access02.c b/testcases/kernel/syscalls/access/access02.c
index 7161a05..e327a91 100644
--- a/testcases/kernel/syscalls/access/access02.c
+++ b/testcases/kernel/syscalls/access/access02.c
@@ -19,17 +19,17 @@
 
 /*
  * Test Description:
- *  Verify that access() succeeds to check the read/write/execute permissions
- *  on a file if the mode argument passed was R_OK/W_OK/X_OK.
+ *  Verify that access() succeeds to check the existence or read/write/execute
+ *  permissions on a file if the mode argument passed was F_OK/R_OK/W_OK/X_OK.
  *
  *  Also verify that, access() succeeds to test the accessibility of the file
  *  referred to by symbolic link if the pathname points to a symbolic link.
  *
- *  As well as verify that, these test files can be read/written/executed
- *  indeed as root and nobody respectively.
+ *  As well as verify that, these test files can be got status or
+ *  read/written/executed indeed as root and nobody respectively.
  *
  *	07/2001 Ported by Wayne Boyera
- *	06/2016 modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ *	06/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  */
 
 #include <sys/types.h>
@@ -40,9 +40,11 @@
 #include <stdlib.h>
 #include "tst_test.h"
 
+#define FNAME_F	"file_f"
 #define FNAME_R	"file_r"
 #define FNAME_W	"file_w"
 #define FNAME_X	"file_x"
+#define SNAME_F	"symlink_f"
 #define SNAME_R	"symlink_r"
 #define SNAME_W	"symlink_w"
 #define SNAME_X	"symlink_x"
@@ -55,9 +57,11 @@ static struct tcase {
 	char *name;
 	const char *targetname;
 } tcases[] = {
+	{FNAME_F, F_OK, "F_OK", FNAME_F},
 	{FNAME_R, R_OK, "R_OK", FNAME_R},
 	{FNAME_W, W_OK, "W_OK", FNAME_W},
 	{FNAME_X, X_OK, "X_OK", FNAME_X},
+	{SNAME_F, F_OK, "F_OK", FNAME_F},
 	{SNAME_R, R_OK, "R_OK", FNAME_R},
 	{SNAME_W, W_OK, "W_OK", FNAME_W},
 	{SNAME_X, X_OK, "X_OK", FNAME_X}
@@ -65,6 +69,7 @@ static struct tcase {
 
 static void access_test(struct tcase *tc, const char *user)
 {
+	struct stat stat_buf;
 	char command[64];
 
 	TEST(access(tc->pathname, tc->mode));
@@ -76,6 +81,21 @@ static void access_test(struct tcase *tc, const char *user)
 	}
 
 	switch (tc->mode) {
+	case F_OK:
+		/*
+		 * The specified file(or pointed to by symbolic link)
+		 * exists, attempt to get its status, if successful,
+		 * access() behaviour is correct.
+		 */
+		TEST(stat(tc->targetname, &stat_buf));
+
+		if (TEST_RETURN == -1) {
+			tst_res(TFAIL | TTERRNO, "stat(%s) as %s failed",
+				tc->targetname, user);
+			return;
+		}
+
+		break;
 	case R_OK:
 		/*
 		 * The specified file(or pointed to by symbolic link)
@@ -163,10 +183,12 @@ static void setup(void)
 
 	uid = pw->pw_uid;
 
+	SAFE_TOUCH(FNAME_F, 0000, NULL);
 	SAFE_TOUCH(FNAME_R, 0444, NULL);
 	SAFE_TOUCH(FNAME_W, 0222, NULL);
 	SAFE_TOUCH(FNAME_X, 0555, NULL);
 
+	SAFE_SYMLINK(FNAME_F, SNAME_F);
 	SAFE_SYMLINK(FNAME_R, SNAME_R);
 	SAFE_SYMLINK(FNAME_W, SNAME_W);
 	SAFE_SYMLINK(FNAME_X, SNAME_X);
diff --git a/testcases/kernel/syscalls/access/access04.c b/testcases/kernel/syscalls/access/access04.c
deleted file mode 100644
index 49e7057..0000000
--- a/testcases/kernel/syscalls/access/access04.c
+++ /dev/null
@@ -1,129 +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 Description:
- *  Verify that access() succeeds to check the existance of a file if
- *  search access is permitted on the pathname of the specified file.
- *
- *  07/2001 Ported by Wayne Boyer
- */
-
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/stat.h>
-#include <pwd.h>
-
-#include "test.h"
-
-#define TESTDIR		"testdir"
-#define TESTFILE	"testdir/testfile"
-#define DIR_MODE	(S_IRWXU | S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP)
-#define FILE_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
-
-char *TCID = "access04";
-int TST_TOTAL = 1;
-
-static const char nobody_uid[] = "nobody";
-static struct passwd *ltpuser;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	struct stat stat_buf;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(access(TESTFILE, F_OK));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "access(%s, F_OK) failed",
-				 TESTFILE);
-			continue;
-		}
-
-		if (stat(TESTFILE, &stat_buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed",
-				 TESTFILE);
-		} else {
-			tst_resm(TPASS, "functionality of "
-				 "access(%s, F_OK) ok", TESTFILE);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	int fd;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	tst_require_root();
-
-	ltpuser = getpwnam(nobody_uid);
-	if (ltpuser == NULL)
-		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_brkm(TINFO | TERRNO, NULL, "setuid failed");
-
-	TEST_PAUSE;
-	tst_tmpdir();
-
-	if (mkdir(TESTDIR, DIR_MODE) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "mkdir(%s, %#o) failed",
-			 TESTDIR, DIR_MODE);
-
-	if (chmod(TESTDIR, DIR_MODE) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "chmod(%s, %#o) failed",
-			 TESTDIR, DIR_MODE);
-
-	fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	if (fd == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
-			 TESTFILE, FILE_MODE);
-
-	if (close(fd) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(%s) failed", TESTFILE);
-
-	if (chmod(TESTFILE, 0) < 0)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "chmod(%s, 0) failed", TESTFILE);
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-- 
1.8.4.2




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

* [LTP] [PATCH 2/2] syscalls/access02: add behaviour check for F_OK
  2016-08-19  9:19     ` [LTP] [PATCH 2/2] syscalls/access02: add behaviour check for F_OK Guangwen Feng
@ 2016-08-24 14:44       ` Cyril Hrubis
  0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2016-08-24 14:44 UTC (permalink / raw)
  To: ltp

Hi!
> - *  As well as verify that, these test files can be read/written/executed
> - *  indeed as root and nobody respectively.
> + *  As well as verify that, these test files can be got status or
> + *  read/written/executed indeed as root and nobody respectively.

I've changed this sentence to be more clear on what we do for the check
and pushed both patches. Thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/2] syscalls/access05: reconstruct and convert to new API
  2016-07-28  9:38 ` [LTP] [PATCH 2/2] syscalls/access05: " Guangwen Feng
@ 2016-09-09  7:31   ` Guangwen Feng
  2016-09-22 15:47   ` Cyril Hrubis
  1 sibling, 0 replies; 10+ messages in thread
From: Guangwen Feng @ 2016-09-09  7:31 UTC (permalink / raw)
  To: ltp

Hi!

Ping, thanks!


Regards,
Guangwen Feng

On 07/28/2016 05:38 PM, Guangwen Feng wrote:
> * remove duplicate test EACCES and EFAULT
> * do UCLINUX check in Makefile instead
> * add test as root and nobody respectively
> 
> Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
> ---
>  testcases/kernel/syscalls/access/Makefile   |   2 +-
>  testcases/kernel/syscalls/access/access05.c | 219 +++++++++-------------------
>  2 files changed, 66 insertions(+), 155 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/access/Makefile b/testcases/kernel/syscalls/access/Makefile
> index 06aaf9f..52c1970 100644
> --- a/testcases/kernel/syscalls/access/Makefile
> +++ b/testcases/kernel/syscalls/access/Makefile
> @@ -19,7 +19,7 @@
>  top_srcdir		?= ../../../..
>  
>  ifeq ($(UCLINUX),1)
> -FILTER_OUT_MAKE_TARGETS += access02 access03
> +FILTER_OUT_MAKE_TARGETS += access02 access03 access05
>  endif
>  
>  include $(top_srcdir)/include/mk/testcases.mk
> diff --git a/testcases/kernel/syscalls/access/access05.c b/testcases/kernel/syscalls/access/access05.c
> index 3b88515..a645397 100644
> --- a/testcases/kernel/syscalls/access/access05.c
> +++ b/testcases/kernel/syscalls/access/access05.c
> @@ -20,197 +20,108 @@
>  /*
>   * Test Description:
>   *  Verify that,
> - *   1. access() fails with -1 return value and sets errno to EACCES
> - *      if the permission bits of the file mode do not permit the
> - *	 requested (Read/Write/Execute) access.
> - *   2. access() fails with -1 return value and sets errno to EINVAL
> + *   1. access() fails with -1 return value and sets errno to EINVAL
>   *	if the specified access mode argument is invalid.
> - *   3. access() fails with -1 return value and sets errno to EFAULT
> - *	if the pathname points outside allocate address space for the
> - *	process.
> - *   4. access() fails with -1 return value and sets errno to ENOENT
> + *   2. access() fails with -1 return value and sets errno to ENOENT
>   *	if the specified file doesn't exist (or pathname is NULL).
> - *   5. access() fails with -1 return value and sets errno to ENAMETOOLONG
> + *   3. access() fails with -1 return value and sets errno to ENAMETOOLONG
>   *      if the pathname size is > PATH_MAX characters.
> - *   6. access() fails with -1 return value and sets errno to ENOTDIR
> + *   4. access() fails with -1 return value and sets errno to ENOTDIR
>   *      if a component used as a directory in pathname is not a directory.
> - *   7. access() fails with -1 return value and sets errno to ELOOP
> + *   5. access() fails with -1 return value and sets errno to ELOOP
>   *      if too many symbolic links were encountered in resolving pathname.
>   *
>   *   07/2001 Ported by Wayne Boyer
> + *   07/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
>   */
>  
> -#include <stdio.h>
>  #include <errno.h>
> -#include <unistd.h>
> -#include <fcntl.h>
> +#include <pwd.h>
>  #include <string.h>
> -#include <signal.h>
>  #include <sys/types.h>
> -#include <sys/stat.h>
> -#include <sys/mman.h>
> -#include <pwd.h>
> -
> -#include "test.h"
> -#include "safe_macros.h"
> -
> -#define INV_OK		-1
> -#define TEST_FILE1	"test_file1"
> -#define TEST_FILE2	"test_file2"
> -#define TEST_FILE3	"test_file3"
> -#define TEST_FILE4	"test_file4"
> -#define TEST_FILE5	"test_file5/test_file5"
> -#define TEST_FILE6	"test_file6"
> -
> +#include <unistd.h>
> +#include "tst_test.h"
>  
> -#if !defined(UCLINUX)
> -static char high_address_node[64];
> -#endif
> +#define	INV_OK	-1
> +#define FNAME1	"accessfile1"
> +#define FNAME2	"accessfile2/accessfile2"
> +#define DNAME	"accessfile2"
> +#define SNAME1	"symlink1"
> +#define SNAME2	"symlink2"
>  
> +static uid_t uid;
>  static char longpathname[PATH_MAX + 2];
>  
> -static struct test_case_t {
> -	char *pathname;
> -	int a_mode;
> +static struct tcase {
> +	const char *pathname;
> +	int mode;
>  	int exp_errno;
> -} test_cases[] = {
> -	{TEST_FILE1, R_OK, EACCES},
> -	{TEST_FILE2, W_OK, EACCES},
> -	{TEST_FILE3, X_OK, EACCES},
> -	{TEST_FILE4, INV_OK, EINVAL},
> -#if !defined(UCLINUX)
> -	{(char *)-1, R_OK, EFAULT},
> -	{high_address_node, R_OK, EFAULT},
> -#endif
> +} tcases[] = {
> +	{FNAME1, INV_OK, EINVAL},
>  	{"", W_OK, ENOENT},
>  	{longpathname, R_OK, ENAMETOOLONG},
> -	{TEST_FILE5, R_OK, ENOTDIR},
> -	{TEST_FILE6, R_OK, ELOOP},
> +	{FNAME2, R_OK, ENOTDIR},
> +	{SNAME1, R_OK, ELOOP}
>  };
>  
> -char *TCID = "access05";
> -int TST_TOTAL = ARRAY_SIZE(test_cases);
> -
> -static const char nobody_uid[] = "nobody";
> -static struct passwd *ltpuser;
> -
> -static void setup(void);
> -static void access_verify(int i);
> -static void cleanup(void);
> -
> -static char *bad_addr;
> -
> -int main(int ac, char **av)
> +static void access_test(struct tcase *tc, const char *user)
>  {
> -	int lc;
> -	int i;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> +	TEST(access(tc->pathname, tc->mode));
>  
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -		tst_count = 0;
> +	if (TEST_RETURN != -1) {
> +		tst_res(TFAIL, "access as %s succeeded unexpectedly", user);
> +		return;
> +	}
>  
> -		for (i = 0; i < TST_TOTAL; i++)
> -			access_verify(i);
> +	if (TEST_ERRNO != tc->exp_errno) {
> +		tst_res(TFAIL | TTERRNO,
> +			"access as %s should fail with %s",
> +			user, tst_strerrno(tc->exp_errno));
> +		return;
>  	}
>  
> -	cleanup();
> -	tst_exit();
> +	tst_res(TPASS | TTERRNO, "access as %s failed expectedly", user);
>  }
>  
> -static void setup(void)
> +static void verify_access(unsigned int n)
>  {
> -	int fd;
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -	tst_require_root();
> -
> -	ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
> -	SAFE_SETUID(cleanup, ltpuser->pw_uid);
> -	TEST_PAUSE;
> -
> -#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 | TERRNO, NULL, "mmap failed");
> -	test_cases[4].pathname = bad_addr;
> -
> -	test_cases[5].pathname = get_high_address();
> -#endif
> -
> -	tst_tmpdir();
> -
> -	/*
> -	 * create TEST_FILE1 to test R_OK EACCESS
> -	 */
> -	fd = SAFE_CREAT(cleanup, TEST_FILE1, 0333);
> -	SAFE_CLOSE(cleanup, fd);
> -
> -	/*
> -	 * create TEST_FILE2 to test W_OK EACCESS
> -	 */
> -	fd = SAFE_CREAT(cleanup, TEST_FILE2, 0555);
> -	SAFE_CLOSE(cleanup, fd);
> -
> -	/*
> -	 * create TEST_FILE3 to test X_OK EACCESS
> -	 */
> -	fd = SAFE_CREAT(cleanup, TEST_FILE3, 0666);
> -	SAFE_CLOSE(cleanup, fd);
> -
> -	/*
> -	 * create TEST_FILE4 to test EINVAL
> -	 */
> -	fd = SAFE_CREAT(cleanup, TEST_FILE4, 0333);
> -	SAFE_CLOSE(cleanup, fd);
> -
> -	/*
> -	 *setup to create a node with a name length exceeding
> -	 *the MAX length of PATH_MAX.
> -	 */
> -	memset(longpathname, 'a', sizeof(longpathname) - 1);
> +	struct tcase *tc = tcases + n;
> +	pid_t pid;
>  
> -	/* create test_file5 for test ENOTDIR. */
> -	SAFE_TOUCH(cleanup, "test_file5", 0644, NULL);
> +	access_test(tc, "root");
>  
> -	/*
> -	 * create two symbolic links who point to each other for
> -	 * test ELOOP.
> -	 */
> -	SAFE_SYMLINK(cleanup, "test_file6", "test_file7");
> -	SAFE_SYMLINK(cleanup, "test_file7", "test_file6");
> +	pid = SAFE_FORK();
> +	if (pid) {
> +		SAFE_WAITPID(pid, NULL, 0);
> +	} else {
> +		SAFE_SETUID(uid);
> +		access_test(tc, "nobody");
> +	}
>  }
>  
> -static void access_verify(int i)
> +static void setup(void)
>  {
> -	char *file_name;
> -	int access_mode;
> +	struct passwd *pw;
>  
> -	file_name = test_cases[i].pathname;
> -	access_mode = test_cases[i].a_mode;
> +	pw = SAFE_GETPWNAM("nobody");
>  
> -	TEST(access(file_name, access_mode));
> +	uid = pw->pw_uid;
>  
> -	if (TEST_RETURN != -1) {
> -		tst_resm(TFAIL, "access(%s, %#o) succeeded unexpectedly",
> -			 file_name, access_mode);
> -		return;
> -	}
> +	memset(longpathname, 'a', sizeof(longpathname) - 1);
>  
> -	if (TEST_ERRNO == test_cases[i].exp_errno) {
> -		tst_resm(TPASS | TTERRNO, "access failed as expected");
> -	} else {
> -		tst_resm(TFAIL | TTERRNO,
> -			 "access failed unexpectedly; expected: "
> -			 "%d - %s", test_cases[i].exp_errno,
> -			 strerror(test_cases[i].exp_errno));
> -	}
> -}
> +	SAFE_TOUCH(FNAME1, 0333, NULL);
> +	SAFE_TOUCH(DNAME, 0644, NULL);
>  
> -static void cleanup(void)
> -{
> -	tst_rmdir();
> +	SAFE_SYMLINK(SNAME1, SNAME2);
> +	SAFE_SYMLINK(SNAME2, SNAME1);
>  }
> +
> +static struct tst_test test = {
> +	.tid = "access05",
> +	.needs_tmpdir = 1,
> +	.needs_root = 1,
> +	.forks_child = 1,
> +	.setup = setup,
> +	.test = verify_access,
> +	.tcnt = ARRAY_SIZE(tcases)
> +};
> 



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

* [LTP] [PATCH 2/2] syscalls/access05: reconstruct and convert to new API
  2016-07-28  9:38 ` [LTP] [PATCH 2/2] syscalls/access05: " Guangwen Feng
  2016-09-09  7:31   ` Guangwen Feng
@ 2016-09-22 15:47   ` Cyril Hrubis
  1 sibling, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2016-09-22 15:47 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with minor changes, thanks.

* There is no need to disable the test on uClinux once the EFAULT
  testcases were removed

* Got rid of the confusing INV_OK constant and used -1 directly

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2016-09-22 15:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-28  9:38 [LTP] [PATCH 1/2] syscalls/access04: reconstruct and convert to new API Guangwen Feng
2016-07-28  9:38 ` [LTP] [PATCH 2/2] syscalls/access05: " Guangwen Feng
2016-09-09  7:31   ` Guangwen Feng
2016-09-22 15:47   ` Cyril Hrubis
2016-08-04 16:50 ` [LTP] [PATCH 1/2] syscalls/access04: " Cyril Hrubis
2016-08-05 10:08   ` Guangwen Feng
2016-08-09 13:14     ` Cyril Hrubis
2016-08-19  9:19   ` [LTP] [PATCH 1/2] syscalls/access01: add testcases with files in subdirectory Guangwen Feng
2016-08-19  9:19     ` [LTP] [PATCH 2/2] syscalls/access02: add behaviour check for F_OK Guangwen Feng
2016-08-24 14:44       ` 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.