Skip to contentSkip to conversation

removexattr/removexattr01.c: add new testcase

PATCH Superseded Xiao Yang 2 participants 7 messages Feb 17, 2016 – Mar 7, 2016

lore
Share & tools
lore

Xiao Yang

author
#0 lore raw

PATCH v2 1/2 removexattr/removexattr01.c: add new testcase

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.

---
 runtest/ltplite                                    |   2 +
 runtest/syscalls                                   |   2 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 testcases/kernel/syscalls/removexattr/Makefile     |  23 ++++
 .../kernel/syscalls/removexattr/removexattr01.c    | 123 +++++++++++++++++++++
 5 files changed, 151 insertions(+)
 create mode 100644 testcases/kernel/syscalls/removexattr/Makefile
 create mode 100644 testcases/kernel/syscalls/removexattr/removexattr01.c
runtest/ltplite +2 -0
index 89accc4..3928263 100644
@@ -639,6 +639,8 @@ recvfrom01 recvfrom01
 
 recvmsg01 recvmsg01
 
+removexattr01 removexattr01
+
 rename01 rename01
 rename01A symlink01 -T rename01
 rename02 rename02
runtest/syscalls +2 -0
index 5f169a3..166f908 100644
@@ -862,6 +862,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
testcases/kernel/syscalls/.gitignore +1 -0
index de403e4..4cf74fb 100644
@@ -713,6 +713,7 @@
 /recvmsg/recvmsg01
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
+/removexattr/removexattr01
 /rename/rename01
 /rename/rename02
 /rename/rename03
testcases/kernel/syscalls/removexattr/Makefile new file +23 -0
new file mode 100644
index 0000000..ed05a48
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) 2016 Fujitsu Ltd.
+#  Author: Xiao Yang <[email protected]>
+#
+#  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
testcases/kernel/syscalls/removexattr/removexattr01.c new file +123 -0

123 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH v2 2/2 removexattr/removexattr02.c: add new testcase

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.

---
 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
runtest/ltplite +1 -0
index 3928263..6e7506c 100644
@@ -640,6 +640,7 @@ recvfrom01 recvfrom01
 recvmsg01 recvmsg01
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
runtest/syscalls +1 -0
index 166f908..9f0b818 100644
@@ -863,6 +863,7 @@ remap_file_pages01 remap_file_pages01
 remap_file_pages02 remap_file_pages02
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
testcases/kernel/syscalls/.gitignore +1 -0
index 4cf74fb..47412a4 100644
@@ -714,6 +714,7 @@
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
 /removexattr/removexattr01
+/removexattr/removexattr02
 /rename/rename01
 /rename/rename02
 /rename/rename03
testcases/kernel/syscalls/removexattr/removexattr02.c new file +138 -0

138 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/2 removexattr/removexattr02.c: add new testcase

Hi!

Quoted 48 lines
testcases/kernel/syscalls/removexattr/removexattr02.c new file +48 -0
+#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 */
+	{(char *)-1, 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]);
+	}
+

testcases/kernel/syscalls/removexattr/removexattr02.c line 92

Quoted 10 lines
testcases/kernel/syscalls/removexattr/removexattr02.c new file +10 -0
+	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");

If you place return here there is no need for the else branch and the code will end up a bit simpler.

Quoted 23 lines
testcases/kernel/syscalls/removexattr/removexattr02.c new file +23 -0
+	} else {
+		if (TEST_ERRNO != tc->exp_err) {
+			tst_resm(TFAIL | TTERRNO, "removexattr() failed "
+				 "unexpectedly, expected %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);

testcases/kernel/syscalls/removexattr/removexattr02.c line 125

Quoted 10 lines
testcases/kernel/syscalls/removexattr/removexattr02.c new file +10 -0
+
+	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");
+		}
+	}

I doubt that we have to set any attribute for the file in the setup, do we?

testcases/kernel/syscalls/removexattr/removexattr02.c line 131

Quoted 6 lines
testcases/kernel/syscalls/removexattr/removexattr02.c new file +6 -0
+}
+
+static void cleanup(void)
+{
+	tst_rmdir();
+}

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH v3 1/2 removexattr/removexattr01.c: add new testcase

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.

---
 runtest/ltplite                                    |   2 +
 runtest/syscalls                                   |   2 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 testcases/kernel/syscalls/removexattr/Makefile     |  23 ++++
 .../kernel/syscalls/removexattr/removexattr01.c    | 127 +++++++++++++++++++++
 5 files changed, 155 insertions(+)
 create mode 100644 testcases/kernel/syscalls/removexattr/Makefile
 create mode 100644 testcases/kernel/syscalls/removexattr/removexattr01.c
runtest/ltplite +2 -0
index d762ac2..3c4cd05 100644
@@ -649,6 +649,8 @@ recvfrom01 recvfrom01
 
 recvmsg01 recvmsg01
 
+removexattr01 removexattr01
+
 rename01 rename01
 rename01A symlink01 -T rename01
 rename02 rename02
runtest/syscalls +2 -0
index 2d981ed..8078137 100644
@@ -871,6 +871,8 @@ recvmsg02 recvmsg02
 remap_file_pages01 remap_file_pages01
 remap_file_pages02 remap_file_pages02
 
+removexattr01 removexattr01
+
 rename01 rename01
 rename01A symlink01 -T rename01
 rename02 rename02
testcases/kernel/syscalls/.gitignore +1 -0
index f54e065..4392cbe 100644
@@ -721,6 +721,7 @@
 /recvmsg/recvmsg02
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
+/removexattr/removexattr01
 /rename/rename01
 /rename/rename02
 /rename/rename03
testcases/kernel/syscalls/removexattr/Makefile new file +23 -0
new file mode 100644
index 0000000..ed05a48
@@ -0,0 +1,23 @@
+#
+#  Copyright (c) 2016 Fujitsu Ltd.
+#  Author: Xiao Yang <[email protected]>
+#
+#  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
testcases/kernel/syscalls/removexattr/removexattr01.c new file +127 -0

127 lines not on this page · raw message

Signature · 1 line
1.8.3.1
author
#4 lore raw

PATCH v3 2/2 removexattr/removexattr02.c: add new testcase

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.

---
 runtest/ltplite                                    |   1 +
 runtest/syscalls                                   |   1 +
 testcases/kernel/syscalls/.gitignore               |   1 +
 .../kernel/syscalls/removexattr/removexattr02.c    | 125 +++++++++++++++++++++
 4 files changed, 128 insertions(+)
 create mode 100644 testcases/kernel/syscalls/removexattr/removexattr02.c
runtest/ltplite +1 -0
index 3c4cd05..fa52588 100644
@@ -650,6 +650,7 @@ recvfrom01 recvfrom01
 recvmsg01 recvmsg01
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
runtest/syscalls +1 -0
index 8078137..b41c927 100644
@@ -872,6 +872,7 @@ remap_file_pages01 remap_file_pages01
 remap_file_pages02 remap_file_pages02
 
 removexattr01 removexattr01
+removexattr02 removexattr02
 
 rename01 rename01
 rename01A symlink01 -T rename01
testcases/kernel/syscalls/.gitignore +1 -0
index 4392cbe..0540928 100644
@@ -722,6 +722,7 @@
 /remap_file_pages/remap_file_pages01
 /remap_file_pages/remap_file_pages02
 /removexattr/removexattr01
+/removexattr/removexattr02
 /rename/rename01
 /rename/rename02
 /rename/rename03
testcases/kernel/syscalls/removexattr/removexattr02.c new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v3 2/2 removexattr/removexattr02.c: add new testcase

Hi!
Both patches pushed with tst_require_root() removed (since user namespace does not need it) and with one typo fixed. Thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
#6 lore raw

PATCH v2 1/2 removexattr/removexattr01.c: add new testcase

In reply to Xiao Yang

Hi!

testcases/kernel/syscalls/removexattr/removexattr01.c line 42

Quoted 4 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +4 -0
+#ifdef HAVE_ATTR_XATTR_H
+#define USER_KEY	"user.test"
+#define VALUE	"test"
+#define VALUE_SIZE	4
                        ^
			(sizeof(VALUE) - 1)
Quoted 33 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +33 -0
+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];
+
+	n = setxattr("testfile", USER_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);
+	if (n == -1) {
+		if (errno == ENOTSUP) {

testcases/kernel/syscalls/removexattr/removexattr01.c line 86

Quoted 10 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +10 -0
+			tst_brkm(TCONF, cleanup, "no xattr support in fs or "
+				 "mounted without user_xattr option");
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup, "setxattr() failed");
+		}
+	}
+
+	TEST(removexattr("testfile", USER_KEY));
+	if (TEST_RETURN != 0) {
+		tst_resm(TFAIL, "removexattr() failed");
                            ^
			    TTERRNO

testcases/kernel/syscalls/removexattr/removexattr01.c line 92

Quoted 6 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +6 -0
+		return;
+	}
+
+	n = getxattr("testfile", USER_KEY, buf, size);
+	if (n != -1) {
+		tst_resm(TFAIL, "getxattr() succeeded unexpectedly");

This is a bit misleading, since we do not say that it succeded for deleted key. It shoud say something as:

"getxattr() succeded for deleted key"

testcases/kernel/syscalls/removexattr/removexattr01.c line 97

Quoted 5 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +5 -0
+		return;
+	}
+
+	if (errno != ENOATTR)
+		tst_resm(TFAIL | TERRNO, "removexattr() failed");

This message is misleading as well. It was getxattr() what has failed unexpectedly.

Quoted 16 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +16 -0
+	else
+		tst_resm(TPASS, "removexattr() succeeded");
+}
+
+static void setup(void)
+{
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
+}
+
+static void cleanup(void)

testcases/kernel/syscalls/removexattr/removexattr01.c line 123

Quoted 10 lines
testcases/kernel/syscalls/removexattr/removexattr01.c new file +10 -0
+{
+	tst_rmdir();
+}
+
+#else /* HAVE_ATTR_XATTR_H */
+int main(int ac, char **av)
+{
+	tst_brkm(TCONF, NULL, "<attr/xattr.h> does not exist.");
+}
+#endif

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]