public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] lapi: fcntl.h: Add O_NOATIME
@ 2014-03-09  8:12 Zeng Linggang
  2014-03-09  8:14 ` [LTP] [PATCH 2/2] open/open12.c: add new tests Zeng Linggang
  0 siblings, 1 reply; 6+ messages in thread
From: Zeng Linggang @ 2014-03-09  8:12 UTC (permalink / raw)
  To: ltp-list

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 include/lapi/fcntl.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index fe8b2cc..089f22a 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -47,4 +47,8 @@
 # define AT_SYMLINK_NOFOLLOW 0x100
 #endif
 
+#ifndef O_NOATIME
+# define O_NOATIME 01000000
+#endif
+
 #endif /* __LAPI_FCNTL_H__ */
-- 
1.8.4.2




------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* [LTP] [PATCH 2/2] open/open12.c: add new tests
  2014-03-09  8:12 [LTP] [PATCH 1/2] lapi: fcntl.h: Add O_NOATIME Zeng Linggang
@ 2014-03-09  8:14 ` Zeng Linggang
  2014-03-11 15:43   ` chrubis
  0 siblings, 1 reply; 6+ messages in thread
From: Zeng Linggang @ 2014-03-09  8:14 UTC (permalink / raw)
  To: ltp-list

Add new tests for open(2)
O_APPEND
O_CLOEXEC
O_NOATIME

Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
---
 runtest/ltplite                               |   1 +
 runtest/stress.part3                          |   1 +
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/.gitignore          |   1 +
 testcases/kernel/syscalls/open/open12.c       | 196 ++++++++++++++++++++++++++
 testcases/kernel/syscalls/open/test_cloexec.c |  33 +++++
 6 files changed, 233 insertions(+)
 create mode 100644 testcases/kernel/syscalls/open/open12.c
 create mode 100644 testcases/kernel/syscalls/open/test_cloexec.c

diff --git a/runtest/ltplite b/runtest/ltplite
index f7127fe..6bd72dd 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -543,6 +543,7 @@ open08 open08
 open09 open09
 open10 open10
 open11 open11
+open12 open12 -F $LTPROOT/testcases/bin/test_cloexec
 
 mincore01 mincore01
 #mincore02 mincore02 currently hangs and does not exit correctly
diff --git a/runtest/stress.part3 b/runtest/stress.part3
index 2f31e93..e526ed0 100644
--- a/runtest/stress.part3
+++ b/runtest/stress.part3
@@ -465,6 +465,7 @@ open08 open08
 open09 open09
 open10 open10
 open11 open11
+open12 open12 -F $LTPROOT/testcases/bin/test_cloexec
 
 pathconf01 pathconf01
 
diff --git a/runtest/syscalls b/runtest/syscalls
index 2a408c4..d63911f 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -702,6 +702,7 @@ open08 open08
 open09 open09
 open10 open10
 open11 open11
+open12 open12 -F $LTPROOT/testcases/bin/test_cloexec
 
 #openat test cases
 openat01 openat01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 0138ba9..d336772 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -596,6 +596,7 @@
 /open/open09
 /open/open10
 /open/open11
+/open/open12
 /openat/openat01
 /pathconf/pathconf01
 /pause/pause01
diff --git a/testcases/kernel/syscalls/open/open12.c b/testcases/kernel/syscalls/open/open12.c
new file mode 100644
index 0000000..d2093db
--- /dev/null
+++ b/testcases/kernel/syscalls/open/open12.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.
+ */
+/*
+ * DESCRIPTION
+ *	This test case will verify basic function of open(2) with the flags
+ *	O_APPEND, O_CLOEXEC and O_NOATIME.
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "test.h"
+#include "usctest.h"
+#include "safe_macros.h"
+#include "lapi/fcntl.h"
+
+#define TEST_FILE	"test_file"
+
+char *TCID = "open12";
+
+static int fd;
+static char *test_app;
+static char test_path[MAXPATHLEN];
+static void setup(void);
+static void cleanup(void);
+static void test_append(void);
+static void test_noatime(void);
+static void test_cloexec(void);
+static void help(void);
+option_t options[] = {
+	{"F:", NULL, &test_app},
+	{NULL, NULL, NULL}
+};
+
+static void (*test_func[])(void) = { test_append, test_noatime, test_cloexec };
+
+int TST_TOTAL = ARRAY_SIZE(test_func);
+
+int main(int argc, char **argv)
+{
+	int lc;
+	char *msg;
+	int i;
+
+	msg = parse_opts(argc, argv, options, &help);
+	if (msg != NULL)
+		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
+
+	if (!test_app) {
+		tst_brkm(TBROK, NULL,
+			 "You must specify a test executable with the -F option.");
+	}
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+		for (i = 0; i < TST_TOTAL; i++)
+			(*test_func[i])();
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void setup(void)
+{
+	tst_require_root(NULL);
+
+	TEST_PAUSE;
+
+	tst_sig(FORK, DEF_HANDLER, cleanup);
+
+	if (test_app[0] != '/') {
+		sprintf(test_path, "%s/%s", get_current_dir_name(),
+			basename(test_app));
+		test_app = test_path;
+	}
+
+	tst_tmpdir();
+
+	fd = SAFE_OPEN(cleanup, TEST_FILE, O_WRONLY | O_CREAT, 0777);
+	SAFE_WRITE(cleanup, 1, fd, TEST_FILE, sizeof(TEST_FILE));
+	SAFE_CLOSE(cleanup, fd);
+}
+
+static void test_append(void)
+{
+	unsigned int len;
+
+	fd = SAFE_OPEN(cleanup, TEST_FILE, O_APPEND | O_RDWR);
+
+	SAFE_WRITE(cleanup, 1, fd, TEST_FILE, sizeof(TEST_FILE));
+	len = SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR);
+	SAFE_CLOSE(cleanup, fd);
+
+	if (len > sizeof(TEST_FILE))
+		tst_resm(TPASS, "open(%s, O_APPEND) test success", TEST_FILE);
+	else
+		tst_resm(TFAIL, "open(%s, O_APPEND) test failed", TEST_FILE);
+}
+
+static void test_noatime(void)
+{
+	char read_buf;
+	struct stat orignal, flag, no_flag;
+
+	if ((tst_kvercmp(2, 6, 9)) < 0) {
+		tst_resm(TCONF,
+			 "O_NOATIME flags test for open(2) needs kernel 2.6.9 "
+			 "or higher");
+		return;
+	}
+
+	SAFE_STAT(cleanup, TEST_FILE, &orignal);
+
+	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY | O_NOATIME);
+	sleep(1);
+	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
+	SAFE_CLOSE(cleanup, fd);
+	SAFE_STAT(cleanup, TEST_FILE, &flag);
+
+	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY);
+	sleep(1);
+	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
+	SAFE_CLOSE(cleanup, fd);
+	SAFE_STAT(cleanup, TEST_FILE, &no_flag);
+
+	if (orignal.st_atime == flag.st_atime &&
+	    orignal.st_atime != no_flag.st_atime)
+		tst_resm(TPASS, "open(%s, O_NOATIME) test success", TEST_FILE);
+	else
+		tst_resm(TFAIL, "open(%s, O_NOATIME) test failed", TEST_FILE);
+}
+
+static void test_cloexec(void)
+{
+	int fd2;
+	pid_t pid;
+	int status;
+
+	if ((tst_kvercmp(2, 6, 24)) < 0) {
+		tst_resm(TCONF,
+			 "O_CLOEXEC flags test for open(2) needs kernel 2.6.24 "
+			 "or higher");
+		return;
+	}
+
+	fd2 = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_APPEND | O_CLOEXEC);
+
+	pid = fork();
+	if (pid < 0)
+		tst_brkm(TBROK, cleanup, "fork() failed");
+
+	if (pid == 0) {
+		if (execl(test_app, "test", &fd2, "test O_CLOEXEC\n", NULL)) {
+			printf("execl() error\n");
+			exit(-2);
+		}
+	}
+
+	SAFE_CLOSE(cleanup, fd2);
+
+	if (wait(&status) != pid)
+		tst_resm(TBROK | TERRNO, "wait() error");
+
+	if (WIFEXITED(status) && (char)WEXITSTATUS(status) == -1)
+		tst_resm(TPASS, "open(%s, O_CLOEXEC) test success", TEST_FILE);
+	else
+		tst_resm(TFAIL, "open(%s, O_CLOEXEC) test failed", TEST_FILE);
+}
+static void cleanup(void)
+{
+	TEST_CLEANUP;
+
+	tst_rmdir();
+}
+
+static void help(void)
+{
+	printf("  -F <test file> : for example, 'open12 -F test'\n");
+}
diff --git a/testcases/kernel/syscalls/open/test_cloexec.c b/testcases/kernel/syscalls/open/test_cloexec.c
new file mode 100644
index 0000000..c045cca
--- /dev/null
+++ b/testcases/kernel/syscalls/open/test_cloexec.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2014 Fujitsu Ltd.
+ * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is 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.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+int main(int argc, char **argv)
+{
+	int ret;
+
+	if (argc != 3)
+		printf("Only three arguments: %s fd str", argv[0]);
+
+	ret = write((int)(*argv[1]), argv[2], strlen(argv[2]));
+
+	exit(ret);
+}
-- 
1.8.4.2




------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH 2/2] open/open12.c: add new tests
  2014-03-09  8:14 ` [LTP] [PATCH 2/2] open/open12.c: add new tests Zeng Linggang
@ 2014-03-11 15:43   ` chrubis
       [not found]     ` <1394716096.2087.10.camel@G08JYZSD130126>
  0 siblings, 1 reply; 6+ messages in thread
From: chrubis @ 2014-03-11 15:43 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
> Add new tests for open(2)
> O_APPEND
> O_CLOEXEC
> O_NOATIME
> 
> Signed-off-by: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> ---
>  runtest/ltplite                               |   1 +
>  runtest/stress.part3                          |   1 +
>  runtest/syscalls                              |   1 +
>  testcases/kernel/syscalls/.gitignore          |   1 +
>  testcases/kernel/syscalls/open/open12.c       | 196 ++++++++++++++++++++++++++
>  testcases/kernel/syscalls/open/test_cloexec.c |  33 +++++
>  6 files changed, 233 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/open/open12.c
>  create mode 100644 testcases/kernel/syscalls/open/test_cloexec.c
> 
> diff --git a/runtest/ltplite b/runtest/ltplite
> index f7127fe..6bd72dd 100644
> --- a/runtest/ltplite
> +++ b/runtest/ltplite
> @@ -543,6 +543,7 @@ open08 open08
>  open09 open09
>  open10 open10
>  open11 open11
> +open12 open12 -F $LTPROOT/testcases/bin/test_cloexec

This is not the way we treat subexecutables. See paragraph 2.1.3 in
Test-Writing-Guidelines.

https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines

>  mincore01 mincore01
>  #mincore02 mincore02 currently hangs and does not exit correctly
> diff --git a/runtest/stress.part3 b/runtest/stress.part3
> index 2f31e93..e526ed0 100644
> --- a/runtest/stress.part3
> +++ b/runtest/stress.part3
> @@ -465,6 +465,7 @@ open08 open08
>  open09 open09
>  open10 open10
>  open11 open11
> +open12 open12 -F $LTPROOT/testcases/bin/test_cloexec
>  
>  pathconf01 pathconf01
>  
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 2a408c4..d63911f 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -702,6 +702,7 @@ open08 open08
>  open09 open09
>  open10 open10
>  open11 open11
> +open12 open12 -F $LTPROOT/testcases/bin/test_cloexec
>  
>  #openat test cases
>  openat01 openat01
> diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
> index 0138ba9..d336772 100644
> --- a/testcases/kernel/syscalls/.gitignore
> +++ b/testcases/kernel/syscalls/.gitignore
> @@ -596,6 +596,7 @@
>  /open/open09
>  /open/open10
>  /open/open11
> +/open/open12
>  /openat/openat01
>  /pathconf/pathconf01
>  /pause/pause01
> diff --git a/testcases/kernel/syscalls/open/open12.c b/testcases/kernel/syscalls/open/open12.c
> new file mode 100644
> index 0000000..d2093db
> --- /dev/null
> +++ b/testcases/kernel/syscalls/open/open12.c
> @@ -0,0 +1,196 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is 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.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program.
> + */
> +/*
> + * DESCRIPTION
> + *	This test case will verify basic function of open(2) with the flags
> + *	O_APPEND, O_CLOEXEC and O_NOATIME.
> + */
> +
> +#include <stdio.h>
> +#include <sys/types.h>
> +#include <sys/wait.h>
> +#include <unistd.h>
> +#include "test.h"
> +#include "usctest.h"
> +#include "safe_macros.h"
> +#include "lapi/fcntl.h"
> +
> +#define TEST_FILE	"test_file"
> +
> +char *TCID = "open12";
> +
> +static int fd;
> +static char *test_app;
> +static char test_path[MAXPATHLEN];
> +static void setup(void);
> +static void cleanup(void);
> +static void test_append(void);
> +static void test_noatime(void);
> +static void test_cloexec(void);
> +static void help(void);
> +option_t options[] = {
> +	{"F:", NULL, &test_app},
> +	{NULL, NULL, NULL}
> +};
> +
> +static void (*test_func[])(void) = { test_append, test_noatime, test_cloexec };
> +
> +int TST_TOTAL = ARRAY_SIZE(test_func);
> +
> +int main(int argc, char **argv)
> +{
> +	int lc;
> +	char *msg;
> +	int i;
> +
> +	msg = parse_opts(argc, argv, options, &help);
> +	if (msg != NULL)
> +		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
> +
> +	if (!test_app) {
> +		tst_brkm(TBROK, NULL,
> +			 "You must specify a test executable with the -F option.");
> +	}
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		tst_count = 0;
> +		for (i = 0; i < TST_TOTAL; i++)
> +			(*test_func[i])();
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void setup(void)
> +{
> +	tst_require_root(NULL);
> +
> +	TEST_PAUSE;
> +
> +	tst_sig(FORK, DEF_HANDLER, cleanup);
> +
> +	if (test_app[0] != '/') {
> +		sprintf(test_path, "%s/%s", get_current_dir_name(),
> +			basename(test_app));
> +		test_app = test_path;
> +	}
> +
> +	tst_tmpdir();
> +
> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_WRONLY | O_CREAT, 0777);
> +	SAFE_WRITE(cleanup, 1, fd, TEST_FILE, sizeof(TEST_FILE));
> +	SAFE_CLOSE(cleanup, fd);

What about SAFE_FILE_PRINTF(cleanup, TEST_FILE, TEST_FILE); ?

> +}
> +
> +static void test_append(void)
> +{
> +	unsigned int len;
> +
> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_APPEND | O_RDWR);
> +
> +	SAFE_WRITE(cleanup, 1, fd, TEST_FILE, sizeof(TEST_FILE));
> +	len = SAFE_LSEEK(cleanup, fd, 0, SEEK_CUR);
> +	SAFE_CLOSE(cleanup, fd);
> +
> +	if (len > sizeof(TEST_FILE))
> +		tst_resm(TPASS, "open(%s, O_APPEND) test success", TEST_FILE);
> +	else
> +		tst_resm(TFAIL, "open(%s, O_APPEND) test failed", TEST_FILE);
> +}
> +
> +static void test_noatime(void)
> +{
> +	char read_buf;
> +	struct stat orignal, flag, no_flag;
> +
> +	if ((tst_kvercmp(2, 6, 9)) < 0) {
> +		tst_resm(TCONF,
> +			 "O_NOATIME flags test for open(2) needs kernel 2.6.9 "
> +			 "or higher");
> +		return;
> +	}

We should check here that test temp dir is mounted noatime, which would
invalidate this test because all files are opened noatime.

I've looked at a few systems and it seems that filesystems are mounted
relatime these days, which sometimes updates the access time. Which
makes this a bit more complicated.

> +	SAFE_STAT(cleanup, TEST_FILE, &orignal);
> +
> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY | O_NOATIME);
> +	sleep(1);
> +	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
> +	SAFE_CLOSE(cleanup, fd);
> +	SAFE_STAT(cleanup, TEST_FILE, &flag);

This order is a bit confusing. I would add the sleep() right after the
first stat so that it's clear that we do stat() then wait, then read()
then stat() again and that we expect these two values to be the same.

> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY);
> +	sleep(1);
> +	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
> +	SAFE_CLOSE(cleanup, fd);
> +	SAFE_STAT(cleanup, TEST_FILE, &no_flag);
> +
> +	if (orignal.st_atime == flag.st_atime &&
> +	    orignal.st_atime != no_flag.st_atime)
> +		tst_resm(TPASS, "open(%s, O_NOATIME) test success", TEST_FILE);
> +	else
> +		tst_resm(TFAIL, "open(%s, O_NOATIME) test failed", TEST_FILE);
> +}
> +
> +static void test_cloexec(void)
> +{
> +	int fd2;
> +	pid_t pid;
> +	int status;
> +
> +	if ((tst_kvercmp(2, 6, 24)) < 0) {
> +		tst_resm(TCONF,
> +			 "O_CLOEXEC flags test for open(2) needs kernel 2.6.24 "
> +			 "or higher");
> +		return;
> +	}
> +
> +	fd2 = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_APPEND | O_CLOEXEC);
> +
> +	pid = fork();

Use tst_fork() please.

> +	if (pid < 0)
> +		tst_brkm(TBROK, cleanup, "fork() failed");
> +
> +	if (pid == 0) {
> +		if (execl(test_app, "test", &fd2, "test O_CLOEXEC\n", NULL)) {
                                            ^
					    This is completly wrong, you
					    are passing pointer to fd2
					    as a string to the execl()
					    function


What you should do instead is to snprintf() the value into a string
buffer and pass that, then convert the value back to integer in the
process atoi(argv[1]) should suffice.

Also please pass something more usefull as the first arg. The whole name
of the binary would be better.

> +			printf("execl() error\n");
> +			exit(-2);
> +		}
> +	}
> +
> +	SAFE_CLOSE(cleanup, fd2);
> +
> +	if (wait(&status) != pid)
> +		tst_resm(TBROK | TERRNO, "wait() error");
> +
> +	if (WIFEXITED(status) && (char)WEXITSTATUS(status) == -1)
> +		tst_resm(TPASS, "open(%s, O_CLOEXEC) test success", TEST_FILE);
> +	else
> +		tst_resm(TFAIL, "open(%s, O_CLOEXEC) test failed", TEST_FILE);
> +}
> +static void cleanup(void)
> +{
> +	TEST_CLEANUP;
> +
> +	tst_rmdir();
> +}
> +
> +static void help(void)
> +{
> +	printf("  -F <test file> : for example, 'open12 -F test'\n");
> +}
> diff --git a/testcases/kernel/syscalls/open/test_cloexec.c b/testcases/kernel/syscalls/open/test_cloexec.c
> new file mode 100644
> index 0000000..c045cca
> --- /dev/null
> +++ b/testcases/kernel/syscalls/open/test_cloexec.c
> @@ -0,0 +1,33 @@
> +/*
> + * Copyright (c) 2014 Fujitsu Ltd.
> + * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This program is 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.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <errno.h>
> +#include <unistd.h>
> +
> +int main(int argc, char **argv)
> +{
> +	int ret;
> +
> +	if (argc != 3)
> +		printf("Only three arguments: %s fd str", argv[0]);
                             ^
                             This should be two arguments
> +	ret = write((int)(*argv[1]), argv[2], strlen(argv[2]));
> +
> +	exit(ret);
> +}
> -- 
> 1.8.4.2
> 
> 
> 
> 
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works. 
> Faster operations. Version large binaries.  Built-in WAN optimization and the
> freedom to use Git, Perforce or both. Make the move to Perforce.
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> Ltp-list mailing list
> Ltp-list@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ltp-list

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2 4/4] open/open12.c: add new tests
       [not found]       ` <1394716306.2087.14.camel@G08JYZSD130126>
@ 2014-04-01 16:14         ` chrubis
       [not found]           ` <1396589471.2098.6.camel@G08JYZSD130126>
  0 siblings, 1 reply; 6+ messages in thread
From: chrubis @ 2014-04-01 16:14 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
> +static void setup(void)
> +{
> +       tst_require_root(NULL);
> +
> +       TEST_PAUSE;
> +        
> +       tst_sig(FORK, DEF_HANDLER, cleanup);
> +
> +       if (test_subexe[0] != '/') {
> +               sprintf(test_path, "%s/%s", get_current_dir_name(),
> +                       basename(test_subexe));
> +               test_subexe = test_path;
> +       }

This is plain wrong. The path to the test helpers MUST be in $PATH so
the test can do just:

	if (execl("open12_cloexec", "open12_cloexec", buf, NULL)) {
		...
	}

If you wan't to run the test from git checkout do:

PATH="$PATH:$PWD" ./test

(It's all written in the Test-Writing-Guidelines)

> +       if (device != NULL && device[0] != '/') {
> +               sprintf(test_path2, "%s/%s", get_current_dir_name(),
> +                       basename(device));
> +               device = test_path2;
> +       }

This is wrong too. If you need a big device you should utilize path
stored in LTP_BIG_DEV env variable. And ideally skip particular testcase
if it's not set.

> +static void test_noatime(void)
> +{
> +	FILE *mtab_f;
> +	struct mntent *entry;
> +	char read_buf;
> +	struct stat orignal, flag, no_flag;
> +
> +	if ((tst_kvercmp(2, 6, 9)) < 0) {
> +		tst_resm(TCONF,
> +			 "O_NOATIME flags test for open(2) needs kernel 2.6.9 "
> +			 "or higher");
> +		return;
> +	}
> +
> +	mtab_f = setmntent("/etc/mtab", "r");
> +	entry = getmntent(mtab_f);
> +	if (hasmntopt(entry, "noatime") != NULL ||
> +	    hasmntopt(entry, "relatime") != NULL) {
> +		tst_resm(TCONF,
> +			 "O_NOATIME flags test for open(2) needs filesystems "
> +			 "which are mounted without noatime and relatime");
> +		return;
> +	}
> +	endmntent(mtab_f);

This part should use the library function I've proposed for the openat()
testcase.

Also note that this snippet is not corret because it check first entry
in mtab which may not be mountpoint the LTP tmp is mounted to. You have
to find the right one first.

> +	SAFE_STAT(cleanup, TEST_FILE, &orignal);
> +
> +	sleep(1);
> +
> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY | O_NOATIME);
> +	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
> +	SAFE_CLOSE(cleanup, fd);
> +	SAFE_STAT(cleanup, TEST_FILE, &flag);
> +
> +	fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDONLY);
> +	SAFE_READ(cleanup, 1, fd, &read_buf, 1);
> +	SAFE_CLOSE(cleanup, fd);
> +	SAFE_STAT(cleanup, TEST_FILE, &no_flag);
> +
> +	if (orignal.st_atime == flag.st_atime &&
> +	    orignal.st_atime != no_flag.st_atime)
> +		tst_resm(TPASS, "open(%s, O_NOATIME) test success", TEST_FILE);
> +	else
> +		tst_resm(TFAIL, "open(%s, O_NOATIME) test failed", TEST_FILE);
> +}
> +
> +static void test_cloexec(void)
> +{
> +	int fd2;
> +	pid_t pid;
> +	int status;
> +	char buf[20];
> +
> +	if ((tst_kvercmp(2, 6, 24)) < 0) {
> +		tst_resm(TCONF,
> +			 "O_CLOEXEC flags test for open(2) needs kernel 2.6.24 "
> +			 "or higher");
> +		return;
> +	}
> +
> +	fd2 = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_APPEND | O_CLOEXEC);
> +
> +	sprintf(buf, "%d", fd2);
> +	pid = tst_fork();
> +	if (pid < 0)
> +		tst_brkm(TBROK, cleanup, "fork() failed");
> +
> +	if (pid == 0) {
> +		if (execl(test_subexe, "open12_cloexec", buf, NULL)) {
> +			printf("execl error\n");
> +			exit(-2);
> +		}
> +	}
> +
> +	SAFE_CLOSE(cleanup, fd2);
> +
> +	if (wait(&status) != pid)
> +		printf("wait error\n");
> +
> +	if (WIFEXITED(status) && (char)WEXITSTATUS(status) == -1)

The cast to char is suspicious, did you get warnings without it?

Note that char may or may not be signed (accordingly to C standard), for
unsigned char the value, after the case, could not be negative.

> +		tst_resm(TPASS, "open(%s, O_CLOEXEC) test success", TEST_FILE);
> +	else
> +		tst_resm(TFAIL, "open(%s, O_CLOEXEC) test failed", TEST_FILE);
> +}
> +
> +static void test_largefile(void)
> +{
> +	struct stat buf;
> +
> +	if (!device) {
> +		tst_resm(TCONF,
> +			 "O_LARGEFILE flags test for open(2) needs specify the "
> +			 "-D option.");
> +		return;
> +	}
> +
> +	SAFE_STAT(cleanup, device, &buf);
> +	if (buf.st_size < 4L * 1024 * 1024 * 1024) {
> +		tst_resm(TCONF,
> +			 "O_LARGEFILE flags test for open(2) needs the file "
> +			 "which size is more than 4G.");
> +		return;
> +	}
> +
> +	TEST(open(device, O_RDONLY | O_LARGEFILE));
> +	SAFE_CLOSE(cleanup, TEST_RETURN);
> +
> +	if (TEST_RETURN != -1) {
> +		tst_resm(TPASS, "open(%s, O_LARGEFILE) test success", device);
> +	} else {
> +		tst_resm(TFAIL | TTERRNO,
> +			 "open(%s, O_LARGEFILE) failed unexpectedly", device);
> +	}
> +}

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2 3/4] open/open02.c: add EPERM errno test
       [not found]       ` <1394716248.2087.13.camel@G08JYZSD130126>
@ 2014-04-01 16:14         ` chrubis
  0 siblings, 0 replies; 6+ messages in thread
From: chrubis @ 2014-04-01 16:14 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
I've pushed first three patches from this series, thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

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

* Re: [LTP] [PATCH v2] open/open12.c: add new tests
       [not found]           ` <1396589471.2098.6.camel@G08JYZSD130126>
@ 2014-05-14 15:07             ` chrubis
  0 siblings, 0 replies; 6+ messages in thread
From: chrubis @ 2014-05-14 15:07 UTC (permalink / raw)
  To: Zeng Linggang; +Cc: ltp-list

Hi!
Pushed with following changes, thanks.

diff --git a/testcases/kernel/syscalls/open/open12.c b/testcases/kernel/syscalls/open/open12.c
index 8b78b83..5b7576b 100644
--- a/testcases/kernel/syscalls/open/open12.c
+++ b/testcases/kernel/syscalls/open/open12.c
@@ -86,7 +86,7 @@ static void setup(void)
 
 static void test_append(void)
 {
-	off_t len;
+	off_t len1, len2;
 
 	TEST(open(TEST_FILE, O_RDWR | O_APPEND, 0777));
 
@@ -95,11 +95,12 @@ static void test_append(void)
 		return;
 	}
 
+	len1 = SAFE_LSEEK(cleanup, TEST_RETURN, 0, SEEK_CUR);
 	SAFE_WRITE(cleanup, 1, TEST_RETURN, TEST_FILE, sizeof(TEST_FILE));
-	len = SAFE_LSEEK(cleanup, TEST_RETURN, 0, SEEK_CUR);
+	len2 = SAFE_LSEEK(cleanup, TEST_RETURN, 0, SEEK_CUR);
 	SAFE_CLOSE(cleanup, TEST_RETURN);
 
-	if (len > (off_t)sizeof(TEST_FILE))
+	if (len2 > len1)
 		tst_resm(TPASS, "test O_APPEND for open success");
 	else
 		tst_resm(TFAIL, "test O_APPEND for open failed");

This makes the test better on -i N (because the len would be greater
than the initial lenght after the first append write no matter what).


@@ -118,10 +119,10 @@ static void test_noatime(void)
 		return;
 	}
 
-	if (tst_path_has_mnt_flags(TEST_FILE, flags)) {
+	if (tst_path_has_mnt_flags(cleanup, NULL, flags)) {
 		tst_resm(TCONF,
 			 "test O_NOATIME flag for open needs filesystems which "
-			 "are mounted without noatime and relatime");
+			 "is mounted without noatime and relatime");
 		return;
 	}

This fixes the tst_path_has_mnt_flags() usage. The path to this function
must be full path (not just filename). I've changed the library to use
tst_tmpdir path if NULL is passed as a path (which simplifies the
usage).

@@ -173,7 +174,7 @@ static void test_cloexec(void)
 
 	if (pid == 0) {
 		if (execlp("open12_cloexec", "open12_cloexec", buf, NULL))
-			exit(1);
+			exit(2);
 	}
 
 	SAFE_CLOSE(cleanup, TEST_RETURN);
@@ -183,13 +184,14 @@ static void test_cloexec(void)
 
 	if (WIFEXITED(status)) {
 		switch ((int8_t)WEXITSTATUS(status)) {
-		case -1:
+		case 0:
 			tst_resm(TPASS, "test O_CLOEXEC for open success");
-			break;
+		break;
 		case 1:
-			tst_brkm(TBROK, cleanup, "execlp() failed");
-		default:
 			tst_resm(TFAIL, "test O_CLOEXEC for open failed");
+		break;
+		default:
+			tst_brkm(TBROK, cleanup, "execlp() failed");
 		}
 	} else {
 		tst_brkm(TBROK, cleanup,
diff --git a/testcases/kernel/syscalls/open/open12_cloexec.c b/testcases/kernel/syscalls/open/open12_cloexec.c
index 5b55a05..a6dabd5 100644
--- a/testcases/kernel/syscalls/open/open12_cloexec.c
+++ b/testcases/kernel/syscalls/open/open12_cloexec.c
@@ -26,12 +26,12 @@ int main(int argc, char **argv)
 	int fd;
 
 	if (argc != 2) {
-		fprintf(stderr, "Only two arguments: %s <fd>", argv[0]);
+		fprintf(stderr, "Only two arguments: %s <fd>\n", argv[0]);
 		exit(1);
 	}
 
 	fd = atoi(argv[1]);
 	ret = write(fd, argv[1], strlen(argv[1]));
 
-	exit(ret);
+	return ret != -1;
 }

This fixes the return values, because as it was return value 1 was
assigned to both failed execlp() and failed testcase (write() succeded
and returned size of the written data which was 1).

Now execlp failure maps to 2, testcase failure to 1 and success to 0 (in
accordance with shell 0 == succes).

-- 
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 related	[flat|nested] 6+ messages in thread

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-09  8:12 [LTP] [PATCH 1/2] lapi: fcntl.h: Add O_NOATIME Zeng Linggang
2014-03-09  8:14 ` [LTP] [PATCH 2/2] open/open12.c: add new tests Zeng Linggang
2014-03-11 15:43   ` chrubis
     [not found]     ` <1394716096.2087.10.camel@G08JYZSD130126>
     [not found]       ` <1394716306.2087.14.camel@G08JYZSD130126>
2014-04-01 16:14         ` [LTP] [PATCH v2 4/4] " chrubis
     [not found]           ` <1396589471.2098.6.camel@G08JYZSD130126>
2014-05-14 15:07             ` [LTP] [PATCH v2] " chrubis
     [not found]       ` <1394716248.2087.13.camel@G08JYZSD130126>
2014-04-01 16:14         ` [LTP] [PATCH v2 3/4] open/open02.c: add EPERM errno test chrubis

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