]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-xattr-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
10 #include <sys/types.h>
11 #include <sys/xattr.h>
14 #include "alloc-util.h"
19 #include "string-util.h"
20 #include "xattr-util.h"
22 static void test_fgetxattrat_fake(void) {
23 char t
[] = "/var/tmp/xattrtestXXXXXX";
24 _cleanup_close_
int fd
= -1;
30 assert_se(mkdtemp(t
));
31 x
= strjoina(t
, "/test");
32 assert_se(touch(x
) >= 0);
34 r
= setxattr(x
, "user.foo", "bar", 3, 0);
35 if (r
< 0 && errno
== EOPNOTSUPP
) /* no xattrs supported on /var/tmp... */
39 fd
= open(t
, O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
42 assert_se(fgetxattrat_fake(fd
, "test", "user.foo", v
, 3, 0, &size
) >= 0);
44 assert_se(memcmp(v
, "bar", 3) == 0);
47 fd
= open("/", O_RDONLY
|O_DIRECTORY
|O_CLOEXEC
|O_NOCTTY
);
49 assert_se(fgetxattrat_fake(fd
, "usr", "user.idontexist", v
, 3, 0, &size
) == -ENODATA
);
52 assert_se(unlink(x
) >= 0);
53 assert_se(rmdir(t
) >= 0);
56 static void test_getcrtime(void) {
58 _cleanup_close_
int fd
= -1;
59 char ts
[FORMAT_TIMESTAMP_MAX
];
64 assert_se(tmp_dir(&vt
) >= 0);
66 fd
= open_tmpfile_unlinkable(vt
, O_RDWR
);
69 r
= fd_getcrtime(fd
, &usec
);
71 log_debug_errno(r
, "btime: %m");
73 log_debug("btime: %s", format_timestamp(ts
, sizeof(ts
), usec
));
75 k
= now(CLOCK_REALTIME
);
77 r
= fd_setcrtime(fd
, 1519126446UL * USEC_PER_SEC
);
78 if (!IN_SET(r
, -EOPNOTSUPP
, -ENOTTY
)) {
79 assert_se(fd_getcrtime(fd
, &usec
) >= 0);
80 assert_se(k
< 1519126446UL * USEC_PER_SEC
||
81 usec
== 1519126446UL * USEC_PER_SEC
);
86 log_set_max_level(LOG_DEBUG
);
87 log_parse_environment();
90 test_fgetxattrat_fake();