]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: move xattr-util related tests to test-xattr-util.c
authorRonny Chevalier <chevalier.ronny@gmail.com>
Wed, 2 Mar 2016 23:35:36 +0000 (00:35 +0100)
committerRonny Chevalier <chevalier.ronny@gmail.com>
Thu, 3 Mar 2016 18:04:07 +0000 (19:04 +0100)
.gitignore
Makefile.am
src/test/test-util.c
src/test/test-xattr-util.c [new file with mode: 0644]

index 41162ab553648839da9a97179f5ce9551ea34f0e..3c52e35f757647b2b10426f992be7eee148d46aa 100644 (file)
 /test-verbs
 /test-watchdog
 /test-web-util
+/test-xattr-util
 /test-xml
 /timedatectl
 /udevadm
index 5e536dd9a2847a53e779718d716ee34751437bee..6dbc085a4dcfb6a94f33eef268ae5c26f459fe2a 100644 (file)
@@ -1433,6 +1433,7 @@ tests += \
        test-proc-cmdline \
        test-io-util \
        test-glob-util \
+       test-xattr-util \
        test-fs-util \
        test-web-util \
        test-stat-util \
@@ -1778,6 +1779,12 @@ test_alloc_util_SOURCES = \
 test_alloc_util_LDADD = \
        libbasic.la
 
+test_xattr_util_SOURCES = \
+       src/test/test-xattr-util.c
+
+test_xattr_util_LDADD = \
+       libbasic.la
+
 test_io_util_SOURCES = \
        src/test/test-io-util.c
 
index 3d876ab5e5cc3d1b71bb3c57a9f9e52f55de6b8a..77eac221f735d62c734bb4aa3aa8291b557ab405 100644 (file)
@@ -41,7 +41,6 @@
 #include "strv.h"
 #include "util.h"
 #include "virt.h"
-#include "xattr-util.h"
 
 static void test_align_power2(void) {
         unsigned long i, p2;
@@ -275,38 +274,6 @@ static void test_raw_clone(void) {
         }
 }
 
-static void test_fgetxattrat_fake(void) {
-        char t[] = "/var/tmp/xattrtestXXXXXX";
-        _cleanup_close_ int fd = -1;
-        const char *x;
-        char v[3] = {};
-        int r;
-
-        assert_se(mkdtemp(t));
-        x = strjoina(t, "/test");
-        assert_se(touch(x) >= 0);
-
-        r = setxattr(x, "user.foo", "bar", 3, 0);
-        if (r < 0 && errno == EOPNOTSUPP) /* no xattrs supported on /var/tmp... */
-                goto cleanup;
-        assert_se(r >= 0);
-
-        fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
-        assert_se(fd >= 0);
-
-        assert_se(fgetxattrat_fake(fd, "test", "user.foo", v, 3, 0) >= 0);
-        assert_se(memcmp(v, "bar", 3) == 0);
-
-        safe_close(fd);
-        fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
-        assert_se(fd >= 0);
-        assert_se(fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0) == -ENODATA);
-
-cleanup:
-        assert_se(unlink(x) >= 0);
-        assert_se(rmdir(t) >= 0);
-}
-
 int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
@@ -321,7 +288,6 @@ int main(int argc, char *argv[]) {
         test_log2i();
         test_execute_directory();
         test_raw_clone();
-        test_fgetxattrat_fake();
 
         return 0;
 }
diff --git a/src/test/test-xattr-util.c b/src/test/test-xattr-util.c
new file mode 100644 (file)
index 0000000..267f294
--- /dev/null
@@ -0,0 +1,69 @@
+/***
+  This file is part of systemd.
+
+  Copyright 2010 Lennart Poettering
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/xattr.h>
+#include <unistd.h>
+
+#include "alloc-util.h"
+#include "fd-util.h"
+#include "fs-util.h"
+#include "macro.h"
+#include "string-util.h"
+#include "xattr-util.h"
+
+static void test_fgetxattrat_fake(void) {
+        char t[] = "/var/tmp/xattrtestXXXXXX";
+        _cleanup_close_ int fd = -1;
+        const char *x;
+        char v[3] = {};
+        int r;
+
+        assert_se(mkdtemp(t));
+        x = strjoina(t, "/test");
+        assert_se(touch(x) >= 0);
+
+        r = setxattr(x, "user.foo", "bar", 3, 0);
+        if (r < 0 && errno == EOPNOTSUPP) /* no xattrs supported on /var/tmp... */
+                goto cleanup;
+        assert_se(r >= 0);
+
+        fd = open(t, O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
+        assert_se(fd >= 0);
+
+        assert_se(fgetxattrat_fake(fd, "test", "user.foo", v, 3, 0) >= 0);
+        assert_se(memcmp(v, "bar", 3) == 0);
+
+        safe_close(fd);
+        fd = open("/", O_RDONLY|O_DIRECTORY|O_CLOEXEC|O_NOCTTY);
+        assert_se(fd >= 0);
+        assert_se(fgetxattrat_fake(fd, "usr", "user.idontexist", v, 3, 0) == -ENODATA);
+
+cleanup:
+        assert_se(unlink(x) >= 0);
+        assert_se(rmdir(t) >= 0);
+}
+
+int main(void) {
+        test_fgetxattrat_fake();
+
+        return 0;
+}