* [LTP] [PATCH 1/2] syscalls/open01: Cleanup && convert to new library
@ 2017-06-09 10:56 Guangwen Feng
2017-06-09 10:56 ` [LTP] [PATCH 2/2] syscalls/open02: " Guangwen Feng
2017-06-13 11:43 ` [LTP] [PATCH 1/2] syscalls/open01: " Cyril Hrubis
0 siblings, 2 replies; 6+ messages in thread
From: Guangwen Feng @ 2017-06-09 10:56 UTC (permalink / raw)
To: ltp
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/open/open01.c | 153 +++++++++-----------------------
1 file changed, 44 insertions(+), 109 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c
index adb59d4..45af9ca 100644
--- a/testcases/kernel/syscalls/open/open01.c
+++ b/testcases/kernel/syscalls/open/open01.c
@@ -1,6 +1,7 @@
/*
- *
* Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 06/2017 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,139 +19,73 @@
*/
/*
- * NAME
- * open01.c
- *
* DESCRIPTION
* Open a file with oflag = O_CREAT set, does it set the sticky bit off?
- *
* Open "/tmp" with O_DIRECTORY, does it set the S_IFDIR bit on?
*
* ALGORITHM
* 1. open a new file with O_CREAT, fstat.st_mode should not have the
* 01000 bit on. In Linux, the save text bit is *NOT* cleared.
- *
* 2. open "/tmp" with O_DIRECTORY. fstat.st_mode should have the
* 040000 bit on.
- *
- * USAGE: <for command-line>
- * open01 [-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
*/
+
#define _GNU_SOURCE /* for O_DIRECTORY */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
-#include "test.h"
+#include "tst_test.h"
-char *TCID = "open01";
-int TST_TOTAL = 1;
+#define TEST_FILE "testfile"
+#define TEST_DIR "/tmp"
-static char pfilname[40] = "";
+static int fd;
-static void cleanup(void);
-static void setup(void);
+static struct tcase {
+ char *filename;
+ int flag;
+ mode_t mode;
+ unsigned short tst_bit;
+ char *desc;
+} tcases[] = {
+ {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "Sticky bit"},
+ {TEST_DIR, O_DIRECTORY, NULL, S_IFDIR, "Directory bit"}
+};
-int main(int ac, char **av)
+static void verify_open(unsigned int n)
{
- int lc;
-
- struct stat statbuf;
- int fildes;
- unsigned short filmode;
-
- /*
- * parse standard command line options
- */
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- /*
- * check looping state if -i option given on the command line
- */
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0; /* reset tst_count while looping. */
-
- /* test #1 */
- TEST(open(pfilname, O_RDWR | O_CREAT, 01444));
-
- fildes = TEST_RETURN;
- if (fildes == -1) {
- tst_resm(TFAIL, "Cannot open %s", pfilname);
- continue;
- }
-
- fstat(fildes, &statbuf);
- filmode = statbuf.st_mode;
- if (!(filmode & S_ISVTX)) {
- tst_resm(TFAIL, "Save test bit cleared, but "
- "should not have been");
- } else {
- tst_resm(TPASS, "Save text bit not cleared "
- "as expected");
- }
-
- /* test #2 */
- TEST(open("/tmp", O_DIRECTORY));
-
- if (TEST_RETURN == -1) {
- tst_resm(TFAIL, "open of /tmp failed, errno: %d",
- TEST_ERRNO);
- continue;
- }
-
- fstat(TEST_RETURN, &statbuf);
- filmode = statbuf.st_mode;
- if (!(filmode & S_IFDIR)) {
- tst_resm(TFAIL, "directory bit cleared, but "
- "should not have been");
- } else {
- tst_resm(TPASS, "directory bit is set "
- "as expected");
- }
-
- /* clean up things is case we are looping */
- if (close(fildes) == -1)
- tst_brkm(TBROK, cleanup, "close #1 failed");
-
- if (unlink(pfilname) == -1)
- tst_brkm(TBROK, cleanup, "can't remove file");
-
- if (close(TEST_RETURN) == -1)
- tst_brkm(TBROK, cleanup, "close #2 failed");
+ struct tcase *tc = &tcases[n];
+ struct stat buf;
+
+ TEST(open(tc->filename, tc->flag, tc->mode));
+ fd = TEST_RETURN;
+ if (fd == -1) {
+ tst_res(TFAIL, "Cannot open a file");
+ return;
}
- cleanup();
- tst_exit();
-}
-
-static void setup(void)
-{
- umask(0);
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ SAFE_FSTAT(fd, &buf);
+ if (!(buf.st_mode & tc->tst_bit))
+ tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc);
+ else
+ tst_res(TPASS, "%s is set as expected", tc->desc);
- TEST_PAUSE;
-
- tst_tmpdir();
-
- sprintf(pfilname, "open3.%d", getpid());
+ SAFE_CLOSE(fd);
+ if (S_ISREG(buf.st_mode))
+ SAFE_UNLINK(tc->filename);
}
static void cleanup(void)
{
- tst_rmdir();
+ if (fd > 0)
+ SAFE_CLOSE(fd);
}
+
+static struct tst_test test = {
+ .tid = "open01",
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_tmpdir = 1,
+ .cleanup = cleanup,
+ .test = verify_open,
+};
--
1.8.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] syscalls/open02: Cleanup && convert to new library
2017-06-09 10:56 [LTP] [PATCH 1/2] syscalls/open01: Cleanup && convert to new library Guangwen Feng
@ 2017-06-09 10:56 ` Guangwen Feng
2017-06-13 12:25 ` Cyril Hrubis
2017-06-13 11:43 ` [LTP] [PATCH 1/2] syscalls/open01: " Cyril Hrubis
1 sibling, 1 reply; 6+ messages in thread
From: Guangwen Feng @ 2017-06-09 10:56 UTC (permalink / raw)
To: ltp
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/open/open02.c | 92 ++++++++++++---------------------
1 file changed, 33 insertions(+), 59 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open02.c b/testcases/kernel/syscalls/open/open02.c
index 30f8472..518f0f0 100644
--- a/testcases/kernel/syscalls/open/open02.c
+++ b/testcases/kernel/syscalls/open/open02.c
@@ -1,6 +1,7 @@
/*
* Copyright (c) International Business Machines Corp., 2001
* 07/2001 Ported by Wayne Boyer
+ * 06/2017 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -31,91 +32,64 @@
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/fcntl.h"
+#include "tst_test.h"
#define TEST_FILE "test_file"
#define TEST_FILE2 "test_file2"
-char *TCID = "open02";
-
-static void cleanup(void);
-static void setup(void);
-
-static struct test_case_t {
+static struct tcase {
char *filename;
int flag;
int exp_errno;
-} test_cases[] = {
+} tcases[] = {
{TEST_FILE, O_RDWR, ENOENT},
{TEST_FILE2, O_RDONLY | O_NOATIME, EPERM},
};
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-static void open_verify(const struct test_case_t *);
-
-int main(int ac, char **av)
-{
- int lc;
- int i;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
- for (i = 0; i < TST_TOTAL; i++)
- open_verify(&test_cases[i]);
- }
-
- cleanup();
- tst_exit();
-}
-
-static void setup(void)
+void setup(void)
{
struct passwd *ltpuser;
- tst_require_root();
+ SAFE_TOUCH(TEST_FILE2, 0644, NULL);
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
+ ltpuser = SAFE_GETPWNAM("nobody");
- TEST_PAUSE;
-
- tst_tmpdir();
-
- SAFE_TOUCH(cleanup, TEST_FILE2, 0644, NULL);
-
- ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
-
- SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+ SAFE_SETEUID(ltpuser->pw_uid);
}
-static void open_verify(const struct test_case_t *test)
+static void verify_open(unsigned int n)
{
- TEST(open(test->filename, test->flag, 0444));
+ struct tcase *tc = &tcases[n];
+
+ TEST(open(tc->filename, tc->flag, 0444));
if (TEST_RETURN != -1) {
- tst_resm(TFAIL, "open(%s) succeeded unexpectedly",
- test->filename);
+ tst_res(TFAIL, "open(%s) succeeded unexpectedly",
+ tc->filename);
return;
}
- if (TEST_ERRNO != test->exp_errno) {
- tst_resm(TFAIL | TTERRNO,
- "open() failed unexpectedly; expected: %d - %s",
- test->exp_errno, strerror(test->exp_errno));
- } else {
- tst_resm(TPASS | TTERRNO, "open() failed as expected");
+ if (tc->exp_errno != TEST_ERRNO) {
+ tst_res(TFAIL | TTERRNO,
+ "open() should fail with %s",
+ tst_strerrno(tc->exp_errno));
+ return;
}
+
+ tst_res(TPASS | TTERRNO, "open() failed as expected");
}
-static void cleanup(void)
+void cleanup(void)
{
- if (seteuid(0))
- tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
- tst_rmdir();
+ SAFE_SETEUID(0);
}
+
+static struct tst_test test = {
+ .tid = "open02",
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = verify_open,
+};
--
1.8.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH 1/2] syscalls/open01: Cleanup && convert to new library
2017-06-09 10:56 [LTP] [PATCH 1/2] syscalls/open01: Cleanup && convert to new library Guangwen Feng
2017-06-09 10:56 ` [LTP] [PATCH 2/2] syscalls/open02: " Guangwen Feng
@ 2017-06-13 11:43 ` Cyril Hrubis
2017-06-14 3:27 ` [LTP] [PATCH v2] " Guangwen Feng
1 sibling, 1 reply; 6+ messages in thread
From: Cyril Hrubis @ 2017-06-13 11:43 UTC (permalink / raw)
To: ltp
Hi!
> +static struct tcase {
> + char *filename;
> + int flag;
> + mode_t mode;
> + unsigned short tst_bit;
> + char *desc;
> +} tcases[] = {
> + {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "Sticky bit"},
> + {TEST_DIR, O_DIRECTORY, NULL, S_IFDIR, "Directory bit"}
^
This should be just 0 or 00 but not
NULL.
Also it would be a bit safer if we opened a directory created in a the
test temporary directory instead of "/tmp". We just have to do
SAFE_MKDIR() in setup() and use it's name as a relative path.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH 2/2] syscalls/open02: Cleanup && convert to new library
2017-06-09 10:56 ` [LTP] [PATCH 2/2] syscalls/open02: " Guangwen Feng
@ 2017-06-13 12:25 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2017-06-13 12:25 UTC (permalink / raw)
To: ltp
Hi!
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2] syscalls/open01: Cleanup && convert to new library
2017-06-13 11:43 ` [LTP] [PATCH 1/2] syscalls/open01: " Cyril Hrubis
@ 2017-06-14 3:27 ` Guangwen Feng
2017-06-14 13:22 ` Cyril Hrubis
0 siblings, 1 reply; 6+ messages in thread
From: Guangwen Feng @ 2017-06-14 3:27 UTC (permalink / raw)
To: ltp
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
---
testcases/kernel/syscalls/open/open01.c | 157 ++++++++++----------------------
1 file changed, 49 insertions(+), 108 deletions(-)
diff --git a/testcases/kernel/syscalls/open/open01.c b/testcases/kernel/syscalls/open/open01.c
index adb59d4..0d6c371 100644
--- a/testcases/kernel/syscalls/open/open01.c
+++ b/testcases/kernel/syscalls/open/open01.c
@@ -1,6 +1,7 @@
/*
- *
* Copyright (c) International Business Machines Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 06/2017 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,139 +19,79 @@
*/
/*
- * NAME
- * open01.c
- *
* DESCRIPTION
* Open a file with oflag = O_CREAT set, does it set the sticky bit off?
- *
- * Open "/tmp" with O_DIRECTORY, does it set the S_IFDIR bit on?
+ * Open a dir with O_DIRECTORY, does it set the S_IFDIR bit on?
*
* ALGORITHM
* 1. open a new file with O_CREAT, fstat.st_mode should not have the
* 01000 bit on. In Linux, the save text bit is *NOT* cleared.
- *
- * 2. open "/tmp" with O_DIRECTORY. fstat.st_mode should have the
+ * 2. open a new dir with O_DIRECTORY, fstat.st_mode should have the
* 040000 bit on.
- *
- * USAGE: <for command-line>
- * open01 [-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
*/
+
#define _GNU_SOURCE /* for O_DIRECTORY */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
-#include "test.h"
+#include "tst_test.h"
-char *TCID = "open01";
-int TST_TOTAL = 1;
+#define TEST_FILE "testfile"
+#define TEST_DIR "testdir"
-static char pfilname[40] = "";
+static int fd;
-static void cleanup(void);
-static void setup(void);
+static struct tcase {
+ char *filename;
+ int flag;
+ mode_t mode;
+ unsigned short tst_bit;
+ char *desc;
+} tcases[] = {
+ {TEST_FILE, O_RDWR | O_CREAT, 01444, S_ISVTX, "Sticky bit"},
+ {TEST_DIR, O_DIRECTORY, 0, S_IFDIR, "Directory bit"}
+};
-int main(int ac, char **av)
+static void verify_open(unsigned int n)
{
- int lc;
-
- struct stat statbuf;
- int fildes;
- unsigned short filmode;
-
- /*
- * parse standard command line options
- */
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- /*
- * check looping state if -i option given on the command line
- */
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0; /* reset tst_count while looping. */
-
- /* test #1 */
- TEST(open(pfilname, O_RDWR | O_CREAT, 01444));
-
- fildes = TEST_RETURN;
- if (fildes == -1) {
- tst_resm(TFAIL, "Cannot open %s", pfilname);
- continue;
- }
-
- fstat(fildes, &statbuf);
- filmode = statbuf.st_mode;
- if (!(filmode & S_ISVTX)) {
- tst_resm(TFAIL, "Save test bit cleared, but "
- "should not have been");
- } else {
- tst_resm(TPASS, "Save text bit not cleared "
- "as expected");
- }
-
- /* test #2 */
- TEST(open("/tmp", O_DIRECTORY));
-
- if (TEST_RETURN == -1) {
- tst_resm(TFAIL, "open of /tmp failed, errno: %d",
- TEST_ERRNO);
- continue;
- }
-
- fstat(TEST_RETURN, &statbuf);
- filmode = statbuf.st_mode;
- if (!(filmode & S_IFDIR)) {
- tst_resm(TFAIL, "directory bit cleared, but "
- "should not have been");
- } else {
- tst_resm(TPASS, "directory bit is set "
- "as expected");
- }
-
- /* clean up things is case we are looping */
- if (close(fildes) == -1)
- tst_brkm(TBROK, cleanup, "close #1 failed");
-
- if (unlink(pfilname) == -1)
- tst_brkm(TBROK, cleanup, "can't remove file");
-
- if (close(TEST_RETURN) == -1)
- tst_brkm(TBROK, cleanup, "close #2 failed");
+ struct tcase *tc = &tcases[n];
+ struct stat buf;
+
+ TEST(open(tc->filename, tc->flag, tc->mode));
+ fd = TEST_RETURN;
+ if (fd == -1) {
+ tst_res(TFAIL, "Cannot open a file");
+ return;
}
- cleanup();
- tst_exit();
+ SAFE_FSTAT(fd, &buf);
+ if (!(buf.st_mode & tc->tst_bit))
+ tst_res(TFAIL, "%s is cleared unexpectedly", tc->desc);
+ else
+ tst_res(TPASS, "%s is set as expected", tc->desc);
+
+ SAFE_CLOSE(fd);
+ if (S_ISREG(buf.st_mode))
+ SAFE_UNLINK(tc->filename);
}
static void setup(void)
{
- umask(0);
-
- tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
-
- tst_tmpdir();
-
- sprintf(pfilname, "open3.%d", getpid());
+ SAFE_MKDIR(TEST_DIR, 0755);
}
static void cleanup(void)
{
- tst_rmdir();
+ if (fd > 0)
+ SAFE_CLOSE(fd);
}
+
+static struct tst_test test = {
+ .tid = "open01",
+ .tcnt = ARRAY_SIZE(tcases),
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .cleanup = cleanup,
+ .test = verify_open,
+};
--
1.8.4.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [LTP] [PATCH v2] syscalls/open01: Cleanup && convert to new library
2017-06-14 3:27 ` [LTP] [PATCH v2] " Guangwen Feng
@ 2017-06-14 13:22 ` Cyril Hrubis
0 siblings, 0 replies; 6+ messages in thread
From: Cyril Hrubis @ 2017-06-14 13:22 UTC (permalink / raw)
To: ltp
Hi!
Applied, thanks.
--
Cyril Hrubis
chrubis@suse.cz
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-06-14 13:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 10:56 [LTP] [PATCH 1/2] syscalls/open01: Cleanup && convert to new library Guangwen Feng
2017-06-09 10:56 ` [LTP] [PATCH 2/2] syscalls/open02: " Guangwen Feng
2017-06-13 12:25 ` Cyril Hrubis
2017-06-13 11:43 ` [LTP] [PATCH 1/2] syscalls/open01: " Cyril Hrubis
2017-06-14 3:27 ` [LTP] [PATCH v2] " Guangwen Feng
2017-06-14 13:22 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox