]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-xattr-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 #include "alloc-util.h"
13 #include "string-util.h"
15 #include "tmpfile-util.h"
16 #include "xattr-util.h"
18 static void test_fgetxattrat_fake(void) {
19 char t
[] = "/var/tmp/xattrtestXXXXXX";
20 _cleanup_close_
int fd
= -1;
26 assert_se(mkdtemp(t
));
27 x
= strjoina(t
, "/test");
28 assert_se(touch(x
) >= 0);
30 r
= setxattr(x
, "user.foo", "bar", 3, 0);
31 if (r
< 0 && errno
== EOPNOTSUPP
) /* no xattrs supported on /var/tmp... */
35 fd
= open(t
, O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
38 assert_se(fgetxattrat_fake(fd
, "test", "user.foo", v
, 3, 0, &size
) >= 0);
40 assert_se(memcmp(v
, "bar", 3) == 0);
43 fd
= open("/", O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
45 assert_se(fgetxattrat_fake(fd
, "usr", "user.idontexist", v
, 3, 0, &size
) == -ENODATA
);
48 assert_se(unlink(x
) >= 0);
49 assert_se(rmdir(t
) >= 0);
52 static void test_getcrtime(void) {
54 _cleanup_close_
int fd
= -1;
55 char ts
[FORMAT_TIMESTAMP_MAX
];
60 assert_se(tmp_dir(&vt
) >= 0);
62 fd
= open_tmpfile_unlinkable(vt
, O_RDWR
);
65 r
= fd_getcrtime(fd
, &usec
);
67 log_debug_errno(r
, "btime: %m");
69 log_debug("btime: %s", format_timestamp(ts
, sizeof(ts
), usec
));
71 k
= now(CLOCK_REALTIME
);
73 r
= fd_setcrtime(fd
, 1519126446UL * USEC_PER_SEC
);
74 if (!IN_SET(r
, -EOPNOTSUPP
, -ENOTTY
)) {
75 assert_se(fd_getcrtime(fd
, &usec
) >= 0);
76 assert_se(k
< 1519126446UL * USEC_PER_SEC
||
77 usec
== 1519126446UL * USEC_PER_SEC
);
82 test_setup_logging(LOG_DEBUG
);
84 test_fgetxattrat_fake();