All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/2] removexattr/removexattr01.c: add new testcase
@ 2016-01-29  9:08 Xiao Yang
  2016-01-29  9:08 ` [LTP] [PATCH 2/2] removexattr/removexattr02.c: " Xiao Yang
  2016-02-10 14:26 ` [LTP] [PATCH 1/2] removexattr/removexattr01.c: " Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Xiao Yang @ 2016-01-29  9:08 UTC (permalink / raw)
  To: ltp

The testcase checks the basic functionality of the removexattr(2).
removexattr(2) removes the extended attribute identified by
name and associated with the given path in the filesystem.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                                    |   2 +
 runtest/syscalls                                   |   2 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 testcases/kernel/syscalls/removexattr/Makefile     |  23 ++++
 .../kernel/syscalls/removexattr/removexattr01.c    | 125 +++++++++++++++++++++
 5 files changed, 153 insertions(+)
 create mode 100644 testcases/kernel/syscalls/removexattr/Makefile
 create mode 100644 testcases/kernel/syscalls/removexattr/removexattr01.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 6ca24c5..f1851d6 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -640,6 +640,8 @@ recvfrom01 recvfrom01
 
 recvmsg01 recvmsg01
 
+removexattr01 removexattr01
+
 rename01 rename01
 rename01A symlink01 -T rename01
 rename02 rename02
diff --git a/runtest/syscalls b/runtest/syscalls
index d206831..2c6db8c 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -861,6 +861,8 @@ recvmsg01 recvmsg01
 remap_file_pages01 remap_file_pages01
 remap_file_pages02 remap_file_pages02
 
+removexattr01 removexattr01
+
 rename01 rename01
 rename01A symlink01 -T rename01
 rename02 rename02
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 1e0a85f..69e2298 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -712,6 +712,7 @@
 /recvmsg/recvmsg01
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
+/removexattr/removexattr01
 /rename/rename01
 /rename/rename02
 /rename/rename03
diff --git a/testcases/kernel/syscalls/removexattr/Makefile b/testcases/kernel/syscalls/removexattr/Makefile
new file mode 100644
index 0000000..ed05a48
--- /dev/null
+++ b/testcases/kernel/syscalls/removexattr/Makefile
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) 2016 Fujitsu Ltd.
+#  Author: Xiao Yang <yangx.jy@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
+#  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.
+#
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/removexattr/removexattr01.c b/testcases/kernel/syscalls/removexattr/removexattr01.c
new file mode 100644
index 0000000..23ad250
--- /dev/null
+++ b/testcases/kernel/syscalls/removexattr/removexattr01.c
@@ -0,0 +1,125 @@
+/*
+* Copyright (c) 2016 Fujitsu Ltd.
+* Author: Xiao Yang <yangx.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
+* alone with this program.
+*/
+
+/*
+* Test Name: removexattr01
+*
+* Description:
+* The testcase checks the basic functionality of the removexattr(2).
+* removexattr(2) removes the extended attribute identified by
+* name and associated with the given path in the filesystem.
+*/
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#endif
+
+#include "test.h"
+#include "safe_file_ops.h"
+
+char *TCID = "removexattr01";
+
+#ifdef HAVE_ATTR_XATTR_H
+#define USER_KEY	"user.test"
+#define VALUE	"test"
+#define VALUE_SIZE	4
+
+static void verify_removexattr(void);
+static void setup(void);
+static void cleanup(void);
+
+int TST_TOTAL = 1;
+
+int main(int ac, char **av)
+{
+	int lc;
+
+	tst_parse_opts(ac, av, NULL, NULL);
+
+	setup();
+
+	for (lc = 0; TEST_LOOPING(lc); lc++) {
+		tst_count = 0;
+
+		verify_removexattr();
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void verify_removexattr(void)
+{
+	int n;
+	int size = 64;
+	char buf[size];
+
+	TEST(removexattr("testfile", USER_KEY));
+	if (TEST_RETURN != 0) {
+		tst_resm(TFAIL, "removexattr() failed");
+		return;
+	}
+
+	n = getxattr("testfile", USER_KEY, buf, size);
+	if (n != -1) {
+		tst_resm(TFAIL, "getxattr() succeeded unexpectedly");
+		return;
+	}
+
+	if (errno != ENOATTR)
+		tst_resm(TFAIL, "removexattr() failed");
+	else
+		tst_resm(TPASS, "removexattr() succeeded");
+}
+
+static void setup(void)
+{
+	int n;
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
+
+	n = setxattr("testfile", USER_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
+	if (n == -1) {
+		if (errno == ENOTSUP) {
+			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
+				 "mounted without user_xattr option");
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup, "setxattr() failed");
+		}
+	}
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
+}
+
+#else /* HAVE_ATTR_XATTR_H */
+int main(int ac, char **av)
+{
+	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
+}
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH 2/2] removexattr/removexattr02.c: add new testcase
  2016-01-29  9:08 [LTP] [PATCH 1/2] removexattr/removexattr01.c: add new testcase Xiao Yang
@ 2016-01-29  9:08 ` Xiao Yang
  2016-02-10 14:37   ` Cyril Hrubis
  2016-02-10 14:26 ` [LTP] [PATCH 1/2] removexattr/removexattr01.c: " Cyril Hrubis
  1 sibling, 1 reply; 4+ messages in thread
From: Xiao Yang @ 2016-01-29  9:08 UTC (permalink / raw)
  To: ltp

1) removexattr(2) fails if the named attribute does not exist set
   errno to ENOATTR.
2) removexattr(2) fails if path is an empty string set errno to ENOENT.
3) removexattr(2) fails when attempted to read from a invalid address
   and set errno to EFAULT.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 runtest/ltplite                                    |   1 +
 runtest/syscalls                                   |   1 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 .../kernel/syscalls/removexattr/removexattr02.c    | 138 +++++++++++++++++++++
 4 files changed, 141 insertions(+)
 create mode 100644 testcases/kernel/syscalls/removexattr/removexattr02.c

diff --git a/runtest/ltplite b/runtest/ltplite
index f1851d6..9e5fbbb 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -641,6 +641,7 @@ recvfrom01 recvfrom01
 recvmsg01 recvmsg01
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
diff --git a/runtest/syscalls b/runtest/syscalls
index 2c6db8c..fb4fde5 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -862,6 +862,7 @@ remap_file_pages01 remap_file_pages01
 remap_file_pages02 remap_file_pages02
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 69e2298..d9350ef 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -713,6 +713,7 @@
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
 /removexattr/removexattr01
+/removexattr/removexattr02
 /rename/rename01
 /rename/rename02
 /rename/rename03
diff --git a/testcases/kernel/syscalls/removexattr/removexattr02.c b/testcases/kernel/syscalls/removexattr/removexattr02.c
new file mode 100644
index 0000000..b9ca791
--- /dev/null
+++ b/testcases/kernel/syscalls/removexattr/removexattr02.c
@@ -0,0 +1,138 @@
+/*
+* Copyright (c) 2016 Fujitsu Ltd.
+* Author: Xiao Yang <yangx.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
+* alone with this program.
+*/
+
+/*
+* Test Name: removexattr02
+*
+* Description:
+* 1) removexattr(2) fails if the named attribute does not exist.
+* 2) removexattr(2) fails if path is an empty string.
+* 3) removexattr(2) fails when attempted to read from a invalid address.
+*
+* Expected Result:
+* 1) removexattr(2) should return -1 and set errno to ENOATTR.
+* 2) removcxattr(2) should return -1 and set errno to ENOENT.
+* 3) removexattr(2) should return -1 and set errno to EFAULT.
+*/
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#endif
+
+#include "test.h"
+#include "safe_file_ops.h"
+
+char *TCID = "removexattr02";
+
+#ifdef HAVE_ATTR_XATTR_H
+#define USER_KEY	"user.test"
+#define VALUE	"test"
+#define VALUE_SIZE	4
+
+static struct test_case {
+	const char *path;
+	char *name;
+	int exp_err;
+} tc[] = {
+	/* test1 */
+	{"testfile", "user.test1", ENOATTR},
+	/* test2 */
+	{"", USER_KEY, ENOENT},
+	/* test3 */
+	{NULL, USER_KEY, EFAULT}
+};
+
+static void verify_removexattr(struct test_case *tc);
+static void setup(void);
+static void cleanup(void);
+
+int TST_TOTAL = ARRAY_SIZE(tc);
+
+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++)
+			verify_removexattr(&tc[i]);
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void verify_removexattr(struct test_case *tc)
+{
+
+	TEST(removexattr(tc->path, tc->name));
+	if (TEST_RETURN != -1) {
+		tst_resm(TFAIL, "removexattr() succeeded unexpectedly");
+	} else {
+		if (TEST_ERRNO != tc->exp_err) {
+			tst_resm(TFAIL | TTERRNO, "removexattr() failed "
+				 "unexpectedly, expected errno is %s",
+				 tst_strerrno(tc->exp_err));
+		} else {
+			tst_resm(TPASS | TTERRNO,
+				 "removexattr() failed as expected");
+		}
+	}
+}
+
+static void setup(void)
+{
+	int n;
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
+
+	n = setxattr("testfile", USER_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
+	if (n == -1) {
+		if (errno == ENOTSUP) {
+			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
+				 "mounted without user_xattr option");
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup, "setxattr() failed");
+		}
+	}
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
+}
+
+#else /* HAVE_ATTR_XATTR_H */
+int main(int ac, char **av)
+{
+	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
+}
+#endif
-- 
1.8.3.1




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

* [LTP] [PATCH 1/2] removexattr/removexattr01.c: add new testcase
  2016-01-29  9:08 [LTP] [PATCH 1/2] removexattr/removexattr01.c: add new testcase Xiao Yang
  2016-01-29  9:08 ` [LTP] [PATCH 2/2] removexattr/removexattr02.c: " Xiao Yang
@ 2016-02-10 14:26 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2016-02-10 14:26 UTC (permalink / raw)
  To: ltp

Hi!
> +int main(int ac, char **av)
> +{
> +	int lc;
> +
> +	tst_parse_opts(ac, av, NULL, NULL);
> +
> +	setup();
> +
> +	for (lc = 0; TEST_LOOPING(lc); lc++) {
> +		tst_count = 0;
> +
> +		verify_removexattr();
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void verify_removexattr(void)
> +{
> +	int n;
> +	int size = 64;
> +	char buf[size];
> +
> +	TEST(removexattr("testfile", USER_KEY));
> +	if (TEST_RETURN != 0) {
> +		tst_resm(TFAIL, "removexattr() failed");
> +		return;
> +	}
> +
> +	n = getxattr("testfile", USER_KEY, buf, size);
> +	if (n != -1) {
> +		tst_resm(TFAIL, "getxattr() succeeded unexpectedly");
> +		return;
> +	}
> +
> +	if (errno != ENOATTR)
> +		tst_resm(TFAIL, "removexattr() failed");
                          ^
			  TFAIL | TERRNO
> +	else
> +		tst_resm(TPASS, "removexattr() succeeded");


You should add the attribute here otherwise the test would break on
second iteration with -i N parameter.

> +}
> +
> +static void setup(void)
> +{
> +	int n;
> +
> +	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +	TEST_PAUSE;
> +
> +	tst_tmpdir();
> +
> +	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
> +
> +	n = setxattr("testfile", USER_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
> +	if (n == -1) {
> +		if (errno == ENOTSUP) {
> +			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
> +				 "mounted without user_xattr option");
> +		} else {
> +			tst_brkm(TFAIL | TERRNO, cleanup, "setxattr() failed");
> +		}
> +	}
> +}
> +
> +static void cleanup(void)
> +{
> +	tst_rmdir();
> +}
> +
> +#else /* HAVE_ATTR_XATTR_H */
> +int main(int ac, char **av)
> +{
> +	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
> +}
> +#endif
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: http://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH 2/2] removexattr/removexattr02.c: add new testcase
  2016-01-29  9:08 ` [LTP] [PATCH 2/2] removexattr/removexattr02.c: " Xiao Yang
@ 2016-02-10 14:37   ` Cyril Hrubis
  0 siblings, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2016-02-10 14:37 UTC (permalink / raw)
  To: ltp

Hi!
> +#include "config.h"
> +#include <errno.h>
> +#include <sys/types.h>
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#include <attr/xattr.h>
> +#endif
> +
> +#include "test.h"
> +#include "safe_file_ops.h"
> +
> +char *TCID = "removexattr02";
> +
> +#ifdef HAVE_ATTR_XATTR_H
> +#define USER_KEY	"user.test"
> +#define VALUE	"test"
> +#define VALUE_SIZE	4
> +
> +static struct test_case {
> +	const char *path;
> +	char *name;
> +	int exp_err;
> +} tc[] = {
> +	/* test1 */
> +	{"testfile", "user.test1", ENOATTR},
> +	/* test2 */
> +	{"", USER_KEY, ENOENT},
> +	/* test3 */
> +	{NULL, USER_KEY, EFAULT}

Here as well use (char*)-1 instead of the NULL.

> +};
> +
> +static void verify_removexattr(struct test_case *tc);
> +static void setup(void);
> +static void cleanup(void);
> +
> +int TST_TOTAL = ARRAY_SIZE(tc);
> +
> +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++)
> +			verify_removexattr(&tc[i]);
> +	}
> +
> +	cleanup();
> +	tst_exit();
> +}
> +
> +static void verify_removexattr(struct test_case *tc)
> +{
> +
> +	TEST(removexattr(tc->path, tc->name));
> +	if (TEST_RETURN != -1) {
> +		tst_resm(TFAIL, "removexattr() succeeded unexpectedly");
> +	} else {
> +		if (TEST_ERRNO != tc->exp_err) {
> +			tst_resm(TFAIL | TTERRNO, "removexattr() failed "
> +				 "unexpectedly, expected errno is %s",
                                                  ^
						  this may be just:
						  "expected %s"

						  to keep the messages
						  short and to the point

> +				 tst_strerrno(tc->exp_err));
> +		} else {
> +			tst_resm(TPASS | TTERRNO,
> +				 "removexattr() failed as expected");
> +		}
> +	}
> +}
> +
> +static void setup(void)
> +{
> +	int n;
> +
> +	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> +
> +	TEST_PAUSE;
> +
> +	tst_tmpdir();
> +
> +	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
> +
> +	n = setxattr("testfile", USER_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
> +	if (n == -1) {
> +		if (errno == ENOTSUP) {
> +			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
> +				 "mounted without user_xattr option");
> +		} else {
> +			tst_brkm(TFAIL | TERRNO, cleanup, "setxattr() failed");
> +		}
> +	}
> +}
> +
> +static void cleanup(void)
> +{
> +	tst_rmdir();
> +}
> +
> +#else /* HAVE_ATTR_XATTR_H */
> +int main(int ac, char **av)
> +{
> +	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
> +}
> +#endif
> -- 
> 1.8.3.1
> 
> 
> 
> 
> -- 
> Mailing list info: http://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2016-02-10 14:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-29  9:08 [LTP] [PATCH 1/2] removexattr/removexattr01.c: add new testcase Xiao Yang
2016-01-29  9:08 ` [LTP] [PATCH 2/2] removexattr/removexattr02.c: " Xiao Yang
2016-02-10 14:37   ` Cyril Hrubis
2016-02-10 14:26 ` [LTP] [PATCH 1/2] removexattr/removexattr01.c: " 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.