All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: add new testcase
@ 2016-01-29  9:08 Xiao Yang
  2016-01-29  9:08 ` [LTP] [PATCH 2/3] llistxattr/llistxattr02.c: " Xiao Yang
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Xiao Yang @ 2016-01-29  9:08 UTC (permalink / raw)
  To: ltp

The testcase checks the basic functionality of the llistxattr(2).
llistxattr(2) retrieves the list of extended attribute names
associated with the link itself 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/llistxattr/Makefile      |  23 +++
 .../kernel/syscalls/llistxattr/llistxattr01.c      | 168 +++++++++++++++++++++
 5 files changed, 196 insertions(+)
 create mode 100644 testcases/kernel/syscalls/llistxattr/Makefile
 create mode 100644 testcases/kernel/syscalls/llistxattr/llistxattr01.c

diff --git a/runtest/ltplite b/runtest/ltplite
index 6ca24c5..0a56c3a 100644
--- a/runtest/ltplite
+++ b/runtest/ltplite
@@ -388,6 +388,8 @@ link08 link08
 
 listen01 listen01
 
+llistxattr01 llistxattr01
+
 llseek01 llseek01
 llseek02 llseek02
 llseek03 llseek03
diff --git a/runtest/syscalls b/runtest/syscalls
index d206831..ffd8be3 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -514,6 +514,8 @@ linkat02 linkat02
 
 listen01 listen01
 
+llistxattr01 llistxattr01
+
 llseek01 llseek01
 llseek02 llseek02
 llseek03 llseek03
diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore
index 1e0a85f..b283761 100644
--- a/testcases/kernel/syscalls/.gitignore
+++ b/testcases/kernel/syscalls/.gitignore
@@ -474,6 +474,7 @@
 /linkat/linkat01
 /linkat/linkat02
 /listen/listen01
+/llistxattr/llistxattr01
 /llseek/llseek01
 /llseek/llseek02
 /llseek/llseek03
diff --git a/testcases/kernel/syscalls/llistxattr/Makefile b/testcases/kernel/syscalls/llistxattr/Makefile
new file mode 100644
index 0000000..ed05a48
--- /dev/null
+++ b/testcases/kernel/syscalls/llistxattr/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/llistxattr/llistxattr01.c b/testcases/kernel/syscalls/llistxattr/llistxattr01.c
new file mode 100644
index 0000000..1f4e6b3
--- /dev/null
+++ b/testcases/kernel/syscalls/llistxattr/llistxattr01.c
@@ -0,0 +1,168 @@
+/*
+* 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: llistxattr01
+*
+* Description:
+* The testcase checks the basic functionality of the llistxattr(2).
+* llistxattr(2) retrieves the list of extended attribute names
+* associated with the given path in the filesystem. In the case of
+* a symbolic, the path associated with the link itself, not the file
+* that it refers to. The list is the set of (NULL-terminated) names,
+* one after the other. The length of the attribute name list is returned.
+*/
+
+#include "config.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <string.h>
+
+#ifdef HAVE_ATTR_XATTR_H
+#include <attr/xattr.h>
+#endif
+
+#include "test.h"
+#include "safe_macros.h"
+#include "safe_file_ops.h"
+
+char *TCID = "llistxattr01";
+
+#ifdef HAVE_ATTR_XATTR_H
+#define SECURITY_KEY	"security.symtest"
+#define SECURITY_KEY_INIT	"security.selinux"
+#define VALUE	"test"
+#define VALUE_SIZE	4
+#define KEY_SIZE    17
+
+static void verify_llistxattr(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_llistxattr();
+	}
+
+	cleanup();
+	tst_exit();
+}
+
+static void verify_llistxattr(void)
+{
+	int n;
+	int se = 1;
+	int size = 64;
+	char buf[size];
+	char cmp_buf1[size];
+	char cmp_buf2[size];
+
+	/* check selinux initialized attr */
+	n = lgetxattr("symlink", SECURITY_KEY_INIT, NULL, 0);
+	if (n == -1) {
+		if (errno == ENOATTR) {
+			se = 0;
+		} else {
+			tst_brkm(TFAIL | TERRNO, cleanup,
+				 "lgetxattr() failed");
+		}
+	}
+
+	TEST(llistxattr("symlink", buf, size));
+	if (TEST_RETURN == -1) {
+		tst_resm(TFAIL | TTERRNO, "llistxattr() failed");
+		return;
+	}
+
+	if (TEST_RETURN != KEY_SIZE*(1 + se)) {
+		tst_resm(TFAIL, "llistxattr() retrieved %li bytes, "
+			 "expected %i", TEST_RETURN, KEY_SIZE*2);
+		return;
+	}
+
+	/*
+	* The list of names is returned as an unordered array of
+	* NULL-terminated character strings.
+	*/
+	if (se == 1) {
+		memcpy(cmp_buf1, SECURITY_KEY, KEY_SIZE);
+		memcpy(cmp_buf1+KEY_SIZE, SECURITY_KEY_INIT, KEY_SIZE);
+		memcpy(cmp_buf2, SECURITY_KEY_INIT, KEY_SIZE);
+		memcpy(cmp_buf2+KEY_SIZE, SECURITY_KEY, KEY_SIZE);
+
+		if (memcmp(buf, cmp_buf1, KEY_SIZE*(1 + se)) && memcmp(buf, cmp_buf2, KEY_SIZE*(1 + se))) {
+			tst_resm(TFAIL, "name list mismatched");
+			return;
+		}
+	} else {
+		if (memcmp(buf, SECURITY_KEY, KEY_SIZE*(1 + se))) {
+			tst_resm(TFAIL, "name list mismatched");
+			return;
+		}
+	}
+
+	tst_resm(TPASS, "llistxattr() succeeded");
+}
+
+static void setup(void)
+{
+	int n;
+
+	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+
+	TEST_PAUSE;
+
+	tst_tmpdir();
+
+	SAFE_TOUCH(cleanup, "testfile", 0644, NULL);
+
+	SAFE_SYMLINK(cleanup, "testfile", "symlink");
+
+	n = lsetxattr("symlink", SECURITY_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,
+				 "lsetxattr() 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] 17+ messages in thread
* [LTP] [PATCH 1/3] epoll_wait/epoll_wait01.c: add new testcase
@ 2016-02-01  5:28 Guangwen Feng
  2016-02-17 10:51 ` [LTP] [PATCH v2 " Guangwen Feng
  0 siblings, 1 reply; 17+ messages in thread
From: Guangwen Feng @ 2016-02-01  5:28 UTC (permalink / raw)
  To: ltp

Hi!

Thanks for your review!
I will modify these test cases according to your suggestion.

Best Regards,
Guangwen Feng

On 01/29/2016 12:19 AM, Cyril Hrubis wrote:
> Hi!
>> diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
>> new file mode 100644
>> index 0000000..46058a2
>> --- /dev/null
>> +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
>> @@ -0,0 +1,263 @@
>> +/*
>> + * Copyright (c) 2015 Fujitsu Ltd.
>> + * Author: 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
>> + * 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.
>> + */
>> +
>> +/*
>> + * Description:
>> + *  Basic test for epoll_wait(2).
>> + *  Check that epoll_wait(2) works for EPOLLOUT and EPOLLIN events
>> + *  on a epoll instance and that struct epoll_event is set correctly.
>> + */
>> +
>> +#include <sys/epoll.h>
>> +#include <unistd.h>
>> +#include <fcntl.h>
>> +#include <poll.h>
>> +#include <errno.h>
>> +
>> +#include "test.h"
>> +#include "safe_macros.h"
>> +#include "lapi/fcntl.h"
>> +
>> +char *TCID = "epoll_wait01";
>> +int TST_TOTAL = 3;
>> +
>> +static int write_size, epfd, fds[2];
>> +static struct epoll_event epevs[2];
>> +
>> +static void setup(void);
>> +static int get_writesize(void);
>> +static void verify_epollout(void);
>> +static void verify_epollin(void);
>> +static void verify_epollio(void);
>> +static void cleanup(void);
>> +
>> +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_epollout();
>> +		verify_epollin();
>> +		verify_epollio();
>> +	}
>> +
>> +	cleanup();
>> +	tst_exit();
>> +}
>> +
>> +static void setup(void)
>> +{
>> +	int pipe_capacity;
>> +
>> +	tst_sig(NOFORK, DEF_HANDLER, cleanup);
>> +
>> +	TEST_PAUSE;
>> +
>> +	SAFE_PIPE(NULL, fds);
>> +
>> +	/* fcntl()'s F_GETPIPE_SZ flag availbility check */
>> +	if ((tst_kvercmp(2, 6, 35)) < 0) {
>> +		write_size = get_writesize();
>> +	} else {
>> +		pipe_capacity = fcntl(fds[1], F_GETPIPE_SZ);
>> +		if (pipe_capacity == -1) {
>> +			tst_brkm(TBROK | TERRNO, cleanup,
>> +				 "failed to get the pipe capacity");
>> +		}
>> +
>> +		write_size = pipe_capacity - getpagesize() + 1;
>> +	}
> 
> I would rather go with runtime detection even for newer kernels. Since
> otherwise we have two different codepaths to test.
> 
>> +	epfd = epoll_create(2);
>> +	if (epfd == -1) {
>> +		tst_brkm(TBROK | TERRNO, cleanup,
>> +			 "failed to create epoll instance");
>> +	}
>> +
>> +	epevs[0].events = EPOLLIN;
>> +	epevs[0].data.fd = fds[0];
>> +	epevs[1].events = EPOLLOUT;
>> +	epevs[1].data.fd = fds[1];
>> +
>> +	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &epevs[0]) ||
>> +		epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[1])) {
>> +		tst_brkm(TBROK | TERRNO, cleanup,
>> +			 "failed to register epoll target");
>> +	}
>> +}
>> +
>> +/*
>> + * fcntl(fd, F_GETPIPE_SZ) not supported on kernels which
>> + * version lower than 2.6.35, so use this function instead
>> + */
>> +static int get_writesize(void)
>> +{
>> +	int nfd, write_size;
>> +
>> +	struct pollfd pfd[] = {
>> +		{.fd = fds[0], .events = POLLIN},
>> +		{.fd = fds[1], .events = POLLOUT},
>> +	};
>> +
>> +	write_size = 0;
>> +	do {
>> +		SAFE_WRITE(cleanup, 1, fds[1], "a", 1);
>> +		write_size++;
>> +		nfd = poll(pfd, 2, -1);
>> +		if (nfd == -1)
>> +			tst_brkm(TBROK | TERRNO, cleanup, "poll failed");
>> +	} while (nfd == 2);
> 
> Why don't we write larger chunks and add the return from SAFE_WRITE to
> the write_size? That should work if we pass 0 as len strict, the last
> write should just end up truncated.
> 
>> +	char buf[write_size];
>> +
>> +	SAFE_READ(cleanup, 1, fds[0], buf, write_size);
>> +
>> +	return write_size;
>> +}
>> +
>> +static void verify_epollout(void)
>> +{
>> +	TEST(epoll_wait(epfd, epevs, 2, -1));
>> +
>> +	if (TEST_RETURN == -1) {
>> +		tst_resm(TFAIL | TTERRNO, "epoll_wait() epollout failed");
>> +		return;
>> +	}
>> +
>> +	if (TEST_RETURN != 1) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to get one fd ready");
>                                        ^
> 				       We should add the TEST_RETURN
> 				       value to the output here
> I would go for:
> 		tst_resm(TFAIL, "epoll_wait() returned %i expected 1",
> 		                TEST_RETURN);
> 
> 
>> +		return;
>> +	}
>> +
>> +	if (epevs[0].data.fd != fds[1]) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to set write fd");
> 
> And maybe write the actuall fds here:
> 
> 		tst_resm(TFAIL, "epoll.data.fd %i expected %i", ...);
> 
>> +		return;
>> +	}
>> +
>> +	if (epevs[0].events != EPOLLOUT) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to set EPOLLOUT");
> 
> And perhaps print the value of events as hexadecimal here.
> 
>> +		return;
>> +	}
>> +
>> +	tst_resm(TPASS, "epoll_wait() epollout");
>> +}
>> +
>> +static void verify_epollin(void)
>> +{
>> +	char write_buf[write_size];
>> +	char read_buf[sizeof(write_buf)];
>> +
>> +	memset(write_buf, 'a', sizeof(write_buf));
>> +
>> +	SAFE_WRITE(cleanup, 1, fds[1], write_buf, sizeof(write_buf));
>> +
>> +	TEST(epoll_wait(epfd, epevs, 2, -1));
>> +
>> +	if (TEST_RETURN == -1) {
>> +		tst_resm(TFAIL | TTERRNO, "epoll_wait() epollin failed");
>> +		goto end;
>> +	}
>> +
>> +	if (TEST_RETURN != 1) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to get one fd ready");
>> +		goto end;
>> +	}
>> +
>> +	if (epevs[0].data.fd != fds[0]) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to set read fd");
>> +		goto end;
>> +	}
>> +
>> +	if (epevs[0].events != EPOLLIN) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to set EPOLLIN");
>> +		goto end;
>> +	}
> 
> And I would be more verbose about the values in these messages as well.
> 
>> +	tst_resm(TPASS, "epoll_wait() epollin");
>> +
>> +end:
>> +	SAFE_READ(cleanup, 1, fds[0], read_buf, sizeof(write_buf));
>> +}
>> +
>> +static void verify_epollio(void)
>> +{
>> +	int i, checked0, checked1;
>> +	char write_buf[] = "Testing";
>> +	char read_buf[sizeof(write_buf)];
>> +
>> +	SAFE_WRITE(cleanup, 1, fds[1], write_buf, sizeof(write_buf));
>> +
>> +	TEST(epoll_wait(epfd, epevs, 2, -1));
>                                      ^
> 			       Shouldn't we pass at least 3 here (and
> 			       declare epevs to have three elements as
> 			       well). Since if there were three events
> 			       queued the epoll_wait() would return just
> 			       2 and the test will pass.
> 
>> +
>> +	if (TEST_RETURN == -1) {
>> +		tst_resm(TFAIL | TTERRNO, "epoll_wait() epollio failed");
>> +		goto end;
>> +	}
>> +
>> +	if (TEST_RETURN != 2) {
>> +		tst_resm(TFAIL, "epoll_wait() failed to get two fds ready");
>> +		goto end;
>> +	}
>> +
>> +	checked0 = 0;
>> +	checked1 = 0;
>> +	for (i = 0; i < TEST_RETURN; i++) {
>> +		if (checked0 == 0 && epevs[i].data.fd == fds[0]) {
>> +			if (epevs[i].events != EPOLLIN) {
>> +				tst_resm(TFAIL, "epoll_wait()"
>> +					 "failed to set EPOLLIN");
>> +				goto end;
>> +			}
>> +			checked0 = 1;
>> +		} else if (checked1 == 0 && epevs[i].data.fd == fds[1]) {
>> +			if (epevs[i].events != EPOLLOUT) {
>> +				tst_resm(TFAIL, "epoll_wait()"
>> +					 "failed to set EPOLLOUT");
>> +				goto end;
>> +			}
>> +			checked1 = 1;
>> +		} else {
>> +			tst_resm(TFAIL, "epoll_wait()"
>> +				 "failed to set write or read fd");
>> +			goto end;
>> +		}
>> +	}
> 
> 
> Hmm, this is kind of messy. I would implement this as function that
> checks if the array has event with specific values and would have called
> it twice once with read fd and once with write fd.
> 
> static int has_event(struct epoll_event *events, int events_len,
>                      int fd, uint32_t events)
> {
> 	...
> }
> 
> ...
> 	if (!has_event(epevs, 2, fds[0], EPOLLIN))
> 		tst_resm(TFAIL, ...);
> 
> 	if (!has_event(epevs, 2, fds[1], EPOLLOUT))
> 		tst_resm(TFAIL, ...);
> ...
> 
> 
> And perhaps we can add a function to dump the epevs array with
> tst_resm(TINFO, "") and call it on the array whenever we find that
> something went wrong before we do tst_resm(TFAIL, ...);
> 
>> +	tst_resm(TPASS, "epoll_wait() epollio");
>> +
>> +end:
>> +	SAFE_READ(cleanup, 1, fds[0], read_buf, sizeof(write_buf));
>> +}
>> +
>> +static void cleanup(void)
>> +{
>> +	if (epfd > 0 && close(epfd))
>> +		tst_resm(TWARN | TERRNO, "failed to close epfd");
>> +
>> +	if (close(fds[0]))
>> +		tst_resm(TWARN | TERRNO, "failed to close fds[0]");
>> +
>> +	if (close(fds[1]))
>> +		tst_resm(TWARN | TERRNO, "failed to close fds[1]");
>> +}
> 
> The rest looks good.
> 



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

end of thread, other threads:[~2016-02-25 13:52 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-29  9:08 [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: add new testcase Xiao Yang
2016-01-29  9:08 ` [LTP] [PATCH 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-10 13:41   ` Cyril Hrubis
2016-01-29  9:08 ` [LTP] [PATCH 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-10 14:12   ` Cyril Hrubis
2016-02-10 14:04 ` [LTP] [PATCH 1/3] llistxattr/llistxattr01.c: " Cyril Hrubis
2016-02-18 10:02   ` Xiao Yang
2016-02-18 12:03     ` Cyril Hrubis
2016-02-19  4:55       ` [LTP] [PATCH v2 " Xiao Yang
2016-02-19  4:55         ` [LTP] [PATCH v2 2/3] llistxattr/llistxattr02.c: " Xiao Yang
2016-02-24 13:54           ` Cyril Hrubis
2016-02-19  4:55         ` [LTP] [PATCH v2 3/3] llistxattr/llistxattr03.c: " Xiao Yang
2016-02-24 14:28           ` Cyril Hrubis
2016-02-25  3:55             ` [LTP] [PATCH v3] " Xiao Yang
2016-02-25 11:21               ` Cyril Hrubis
2016-02-24 13:38         ` [LTP] [PATCH v2 1/3] llistxattr/llistxattr01.c: " Cyril Hrubis
  -- strict thread matches above, loose matches on Subject: below --
2016-02-01  5:28 [LTP] [PATCH 1/3] epoll_wait/epoll_wait01.c: " Guangwen Feng
2016-02-17 10:51 ` [LTP] [PATCH v2 " Guangwen Feng
2016-02-17 10:51   ` [LTP] [PATCH v2 3/3] epoll_wait/epoll_wait03.c: " Guangwen Feng
2016-02-25 13:52     ` [LTP] [PATCH v2 3/3] llistxattr/llistxattr03.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.