From 400436cd1af6aef8892ac899eb0844892fc5e54c Mon Sep 17 00:00:00 2001 From: vivek Date: Wed, 6 May 2015 08:32:04 +0200 Subject: [PATCH] eina_xattr: Fixed T2381, eina xattr tests failing Summary: This fixes the case where the system runs with SELinux enabled and enforced. In this scenario the system does add a selinux attribute to new files which we need to handle during our testing. @Fix Signed-off-by: vivek Reviewers: cedric, stefan_schmidt Subscribers: stefan_schmidt, cedric Maniphest Tasks: T2381 Differential Revision: https://phab.enlightenment.org/D2467 --- src/tests/eina/eina_test_file.c | 17 ++++++++--- src/tests/eina/eina_test_xattr.c | 52 ++++++++++++++++++++++++-------- src/tests/eio/eio_test_xattr.c | 8 ++--- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/src/tests/eina/eina_test_file.c b/src/tests/eina/eina_test_file.c index 5fa4a6862c..766ff46b67 100644 --- a/src/tests/eina/eina_test_file.c +++ b/src/tests/eina/eina_test_file.c @@ -525,7 +525,7 @@ START_TEST(eina_test_file_xattr) Eina_Bool ret; Eina_Tmpstr *test_file_path; Eina_Iterator *it; - int fd; + int fd, count=0; Eina_Xattr *xattr; eina_init(); @@ -549,20 +549,27 @@ START_TEST(eina_test_file_xattr) { for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); i++) if (strcmp(attribute[i], ret_str) == 0) - break ; - fail_if(i == sizeof (attribute) / sizeof (attribute[0])); + { + count++; + break; + } } + fail_if(count != sizeof (attribute) / sizeof (attribute[0])); eina_iterator_free(it); + count = 0; it = eina_file_xattr_value_get(ef); EINA_ITERATOR_FOREACH(it, xattr) { for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) if (strcmp(attribute[i], xattr->name) == 0 && strcmp(data[i], xattr->value) == 0) - break ; - fail_if(i == sizeof (data) / sizeof (data[0])); + { + count++; + break; + } } + fail_if(count != sizeof (data) / sizeof (data[0])); eina_iterator_free(it); unlink(test_file_path); diff --git a/src/tests/eina/eina_test_xattr.c b/src/tests/eina/eina_test_xattr.c index 50e1ad01eb..43a315aee3 100644 --- a/src/tests/eina/eina_test_xattr.c +++ b/src/tests/eina/eina_test_xattr.c @@ -87,6 +87,7 @@ START_TEST(eina_test_xattr_set) ret = eina_xattr_fd_del(fd, attribute1); fail_if(ret != EINA_TRUE); + close(fd); unlink(test_file_path); eina_tmpstr_del(test_file_path); @@ -112,7 +113,7 @@ START_TEST(eina_test_xattr_list) "This file has extra attributes" }; char *ret_str; - int fd, fd1; + int fd, fd1, count=0; unsigned int i; Eina_Bool ret; Eina_Tmpstr *test_file_path, *cp_file_path; @@ -134,61 +135,81 @@ START_TEST(eina_test_xattr_list) ret = eina_xattr_set(test_file_path, attribute[i], data[i], strlen(data[i]), EINA_XATTR_INSERT); fail_if(ret != EINA_TRUE); } + it = eina_xattr_ls(test_file_path); EINA_ITERATOR_FOREACH(it, ret_str) { for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); i++) if (strcmp(attribute[i], ret_str) == 0) - break ; - fail_if(i == sizeof (attribute) / sizeof (attribute[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (attribute) / sizeof (attribute[0])); eina_iterator_free(it); + count = 0; it = eina_xattr_value_ls(test_file_path); EINA_ITERATOR_FOREACH(it, xattr) { for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) if (strcmp(attribute[i], xattr->name) == 0 && strcmp(data[i], xattr->value) == 0) - break ; - fail_if(i == sizeof (data) / sizeof (data[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (data) / sizeof (data[0])); eina_iterator_free(it); + count = 0; it = eina_xattr_fd_ls(fd); EINA_ITERATOR_FOREACH(it, ret_str) { for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); i++) if (strcmp(attribute[i], ret_str) == 0) - break ; - fail_if(i == sizeof (attribute) / sizeof (attribute[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (attribute) / sizeof (attribute[0])); eina_iterator_free(it); + count = 0; it = eina_xattr_value_fd_ls(fd); EINA_ITERATOR_FOREACH(it, xattr) { for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) if (strcmp(attribute[i], xattr->name) == 0 && strcmp(data[i], xattr->value) == 0) - break ; - fail_if(i == sizeof (data) / sizeof (data[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (data) / sizeof (data[0])); eina_iterator_free(it); /* Test case for eina_xattr_copy and eina_xattr_fd_copy */ ret = eina_xattr_copy(test_file_path, cp_file_path); fail_if(ret != EINA_TRUE); + count = 0; it = eina_xattr_value_ls(cp_file_path); EINA_ITERATOR_FOREACH(it, xattr) { for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) if (strcmp(attribute[i], xattr->name) == 0 && strcmp(data[i], xattr->value) == 0) - break ; - fail_if(i == sizeof (data) / sizeof (data[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (data) / sizeof (data[0])); eina_iterator_free(it); for (i = 0; i < sizeof(attribute) / sizeof(attribute[0]); ++i) @@ -199,15 +220,20 @@ START_TEST(eina_test_xattr_list) ret = eina_xattr_fd_copy(fd, fd1); fail_if(ret != EINA_TRUE); + + count = 0; it = eina_xattr_value_fd_ls(fd1); EINA_ITERATOR_FOREACH(it, xattr) { for (i = 0; i < sizeof (data) / sizeof (data[0]); i++) if (strcmp(attribute[i], xattr->name) == 0 && strcmp(data[i], xattr->value) == 0) - break ; - fail_if(i == sizeof (data) / sizeof (data[0])); + { + count++; + break ; + } } + fail_if(count != sizeof (data) / sizeof (data[0])); eina_iterator_free(it); close(fd); diff --git a/src/tests/eio/eio_test_xattr.c b/src/tests/eio/eio_test_xattr.c index b832eb001e..dfc5894045 100644 --- a/src/tests/eio/eio_test_xattr.c +++ b/src/tests/eio/eio_test_xattr.c @@ -58,10 +58,10 @@ _main_cb(void *data EINA_UNUSED, Eio_File *handler EINA_UNUSED, const char *attr for (i = 0; i < sizeof (attribute) / sizeof (attribute[0]); ++i) if (strcmp(attr, attribute[i]) == 0) - break; - - fail_if(i == sizeof (attribute) / sizeof (attribute[0])); - (*num_of_attr)++; + { + (*num_of_attr)++; + break; + } } static void