<html>Ok, now I see I've missed a changes here.<pre>Need to rebase this.
</pre><br />-------- Original Message --------<br />Subject: [LTP] [PATCH v4 3/5] llistxattr: improved code readability and stability<br />Date: Monday, November 14, 2016 13:13 CET<br />From: Dejan Jovicevic <dejan.jovicevic@rt-rk.com><br />To: ltp@lists.linux.it<br />References: <1479125614-24731-1-git-send-email-dejan.jovicevic@rt-rk.com><br /><br /><br /> <blockquote type="cite" cite="1479125614-24731-4-git-send-email-dejan.jovicevic@rt-rk.com">Changed bits of code, such as hardcoded magic constants,<br />unnecessary else branches, way of passing array size to<br />a function, removed unnecessary comments, moved to using<br />macros instead of string literals where seemed to be fit.<br /><br />This was done to make the code easier to read and understand,<br />and make it easier to maintain in case of changes<br /><br />Signed-off-by: Dejan Jovicevic <dejan.jovicevic@rt-rk.com><br />---<br />.../kernel/syscalls/llistxattr/llistxattr01.c | 30 ++++++++++++----------<br />.../kernel/syscalls/llistxattr/llistxattr02.c | 23 ++++++++---------<br />.../kernel/syscalls/llistxattr/llistxattr03.c | 12 ++++-----<br />3 files changed, 32 insertions(+), 33 deletions(-)<br /><br />diff --git a/testcases/kernel/syscalls/llistxattr/llistxattr01.c b/testcases/kernel/syscalls/llistxattr/llistxattr01.c<br />index f352032..0176893 100644<br />--- a/testcases/kernel/syscalls/llistxattr/llistxattr01.c<br />+++ b/testcases/kernel/syscalls/llistxattr/llistxattr01.c<br />@@ -37,11 +37,14 @@<br /><br />#ifdef HAVE_SYS_XATTR_H<br /><br />-#define SECURITY_KEY1 "security.ltptest1"<br />-#define SECURITY_KEY2 "security.ltptest2"<br />-#define VALUE "test"<br />-#define VALUE_SIZE 4<br />-#define KEY_SIZE 17<br />+#define SECURITY_KEY1 "security.ltptest1"<br />+#define SECURITY_KEY2 "security.ltptest2"<br />+#define VALUE "test"<br />+#define VALUE_SIZE (sizeof(VALUE) - 1)<br />+#define KEY_SIZE (sizeof(SECURITY_KEY1) - 1)<br />+#define TESTFILE "testfile"<br />+#define SYMLINK "symlink"<br />+<br /><br />static int has_attribute(const char *list, int llen, const char *attr)<br />{<br />@@ -56,22 +59,21 @@ static int has_attribute(const char *list, int llen, const char *attr)<br /><br />static void verify_llistxattr(void)<br />{<br />- int size = 64;<br />- char buf[size];<br />+ char buf[64];<br /><br />- TEST(llistxattr("symlink", buf, size));<br />+ TEST(llistxattr(SYMLINK, buf, sizeof(buf)));<br />if (TEST_RETURN == -1) {<br />tst_res(TFAIL | TTERRNO, "llistxattr() failed");<br />return;<br />}<br /><br />- if (has_attribute(buf, size, SECURITY_KEY1)) {<br />+ if (has_attribute(buf, sizeof(buf), SECURITY_KEY1)) {<br />tst_res(TFAIL, "get file attribute %s unexpectlly",<br />SECURITY_KEY1);<br />return;<br />}<br /><br />- if (!has_attribute(buf, size, SECURITY_KEY2)) {<br />+ if (!has_attribute(buf, sizeof(buf), SECURITY_KEY2)) {<br />tst_res(TFAIL, "missing attribute %s", SECURITY_KEY2);<br />return;<br />}<br />@@ -81,13 +83,13 @@ static void verify_llistxattr(void)<br /><br />static void setup(void)<br />{<br />- SAFE_TOUCH("testfile", 0644, NULL);<br />+ SAFE_TOUCH(TESTFILE, 0644, NULL);<br /><br />- SAFE_SYMLINK("testfile", "symlink");<br />+ SAFE_SYMLINK(TESTFILE, SYMLINK);<br /><br />- SAFE_LSETXATTR("testfile", SECURITY_KEY1, VALUE, VALUE_SIZE, XATTR_CREATE);<br />+ SAFE_LSETXATTR(TESTFILE, SECURITY_KEY1, VALUE, VALUE_SIZE, XATTR_CREATE);<br /><br />- SAFE_LSETXATTR("symlink", SECURITY_KEY2, VALUE, VALUE_SIZE, XATTR_CREATE);<br />+ SAFE_LSETXATTR(SYMLINK, SECURITY_KEY2, VALUE, VALUE_SIZE, XATTR_CREATE);<br />}<br /><br />static struct tst_test test = {<br />diff --git a/testcases/kernel/syscalls/llistxattr/llistxattr02.c b/testcases/kernel/syscalls/llistxattr/llistxattr02.c<br />index 2812838..ed3ace3 100644<br />--- a/testcases/kernel/syscalls/llistxattr/llistxattr02.c<br />+++ b/testcases/kernel/syscalls/llistxattr/llistxattr02.c<br />@@ -41,20 +41,19 @@<br /><br />#ifdef HAVE_SYS_XATTR_H<br /><br />-#define SECURITY_KEY "security.ltptest"<br />-#define VALUE "test"<br />-#define VALUE_SIZE 4<br />+#define SECURITY_KEY "security.ltptest"<br />+#define VALUE "test"<br />+#define VALUE_SIZE (sizeof(VALUE) - 1)<br />+#define TESTFILE "testfile"<br />+#define SYMLINK "symlink"<br /><br />static struct test_case {<br />const char *path;<br />size_t size;<br />int exp_err;<br />} tc[] = {<br />- /* test1 */<br />- {"symlink", 1, ERANGE},<br />- /* test2 */<br />+ {SYMLINK, 1, ERANGE},<br />{"", 20, ENOENT},<br />- /* test3 */<br />{(char *)-1, 20, EFAULT}<br />};<br /><br />@@ -63,8 +62,8 @@ static void verify_llistxattr(unsigned int n)<br />struct test_case *t = tc + n;<br />char buf[t->size];<br /><br />- TEST(llistxattr(t->path, buf, t->size));<br />- if (TEST_RETURN != -1) {<br />+ TEST(llistxattr(t->path, buf, sizeof(buf)));<br />+ if (TEST_RETURN == 0) {<br />tst_res(TFAIL, "llistxattr() succeeded unexpectedly");<br />} else {<br />if (TEST_ERRNO != t->exp_err) {<br />@@ -80,11 +79,11 @@ static void verify_llistxattr(unsigned int n)<br /><br />static void setup(void)<br />{<br />- SAFE_TOUCH("testfile", 0644, NULL);<br />+ SAFE_TOUCH(TESTFILE, 0644, NULL);<br /><br />- SAFE_SYMLINK("testfile", "symlink");<br />+ SAFE_SYMLINK(TESTFILE, SYMLINK);<br /><br />- SAFE_LSETXATTR("symlink", SECURITY_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);<br />+ SAFE_LSETXATTR(SYMLINK, SECURITY_KEY, VALUE, VALUE_SIZE, XATTR_CREATE);<br />}<br /><br />static struct tst_test test = {<br />diff --git a/testcases/kernel/syscalls/llistxattr/llistxattr03.c b/testcases/kernel/syscalls/llistxattr/llistxattr03.c<br />index 475375e..6a1cb6b 100644<br />--- a/testcases/kernel/syscalls/llistxattr/llistxattr03.c<br />+++ b/testcases/kernel/syscalls/llistxattr/llistxattr03.c<br />@@ -36,8 +36,8 @@<br />#ifdef HAVE_SYS_XATTR_H<br /><br />#define SECURITY_KEY "security.ltptest"<br />-#define VALUE "test"<br />-#define VALUE_SIZE 4<br />+#define VALUE "test"<br />+#define VALUE_SIZE (sizeof(VALUE) - 1)<br /><br />static const char *filename[] = {"testfile1", "testfile2"};<br /><br />@@ -46,11 +46,9 @@ static int check_suitable_buf(const char *name, long size)<br />int n;<br />char buf[size];<br /><br />- n = llistxattr(name, buf, size);<br />- if (n == -1)<br />- return 0;<br />- else<br />- return 1;<br />+ n = llistxattr(name, buf, sizeof(buf));<br />+<br />+ return n != -1;<br />}<br /><br />static void verify_llistxattr(unsigned int n)<br />--<br />1.9.1<br /><br /><br />--<br />Mailing list info: https://lists.linux.it/listinfo/ltp</blockquote><br /> </html>