]>
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"
14 #include "string-util.h"
15 #include "xattr-util.h"
17 static void test_fgetxattrat_fake(void) {
18 char t
[] = "/var/tmp/xattrtestXXXXXX";
19 _cleanup_close_
int fd
= -1;
25 assert_se(mkdtemp(t
));
26 x
= strjoina(t
, "/test");
27 assert_se(touch(x
) >= 0);
29 r
= setxattr(x
, "user.foo", "bar", 3, 0);
30 if (r
< 0 && errno
== EOPNOTSUPP
) /* no xattrs supported on /var/tmp... */
34 fd
= open(t
, O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
37 assert_se(fgetxattrat_fake(fd
, "test", "user.foo", v
, 3, 0, &size
) >= 0);
39 assert_se(memcmp(v
, "bar", 3) == 0);
42 fd
= open("/", O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
44 assert_se(fgetxattrat_fake(fd
, "usr", "user.idontexist", v
, 3, 0, &size
) == -ENODATA
);
47 assert_se(unlink(x
) >= 0);
48 assert_se(rmdir(t
) >= 0);
51 static void test_getcrtime(void) {
53 _cleanup_close_
int fd
= -1;
54 char ts
[FORMAT_TIMESTAMP_MAX
];
59 assert_se(tmp_dir(&vt
) >= 0);
61 fd
= open_tmpfile_unlinkable(vt
, O_RDWR
);
64 r
= fd_getcrtime(fd
, &usec
);
66 log_debug_errno(r
, "btime: %m");
68 log_debug("btime: %s", format_timestamp(ts
, sizeof(ts
), usec
));
70 k
= now(CLOCK_REALTIME
);
72 r
= fd_setcrtime(fd
, 1519126446UL * USEC_PER_SEC
);
73 if (!IN_SET(r
, -EOPNOTSUPP
, -ENOTTY
)) {
74 assert_se(fd_getcrtime(fd
, &usec
) >= 0);
75 assert_se(k
< 1519126446UL * USEC_PER_SEC
||
76 usec
== 1519126446UL * USEC_PER_SEC
);
81 log_set_max_level(LOG_DEBUG
);
82 log_parse_environment();
85 test_fgetxattrat_fake();