]>
git.saurik.com Git - apple/xnu.git/blob - tests/utimensat.c
13 #include <darwintest.h>
14 #include <darwintest_utils.h>
16 #define FILENAME "utimensat"
18 static const struct timespec tptr
[][2] = {
19 { { 0x12345678, 987654321 }, { 0x15263748, 123456789 }, },
21 { { 0, UTIME_NOW
}, { 0x15263748, 123456789 }, },
22 { { 0x12345678, 987654321 }, { 0, UTIME_NOW
}, },
23 { { 0, UTIME_NOW
}, { 0, UTIME_NOW
}, },
25 { { 0, UTIME_OMIT
}, { 0x15263748, 123456789 }, },
26 { { 0x12345678, 987654321 }, { 0, UTIME_OMIT
}, },
27 { { 0, UTIME_OMIT
}, { 0, UTIME_OMIT
}, },
29 { { 0, UTIME_NOW
}, { 0, UTIME_OMIT
}, },
30 { { 0, UTIME_OMIT
}, { 0, UTIME_NOW
}, },
33 T_DECL(utimensat
, "Try various versions of utimensat")
36 T_ASSERT_POSIX_ZERO(chdir(dt_tmpdir()), NULL
);
37 // Skip the test if the current working directory is not on APFS.
38 struct statfs sfs
= { 0 };
39 T_QUIET
; T_ASSERT_POSIX_SUCCESS(statfs(".", &sfs
), NULL
);
40 if (memcmp(&sfs
.f_fstypename
[0], "apfs", strlen("apfs")) != 0) {
41 T_SKIP("utimensat is APFS-only, but working directory is non-APFS");
45 struct stat pre_st
, post_st
;
48 T_ASSERT_POSIX_SUCCESS((fd
= open(FILENAME
, O_CREAT
|O_RDWR
, 0644)), NULL
);
49 T_ASSERT_POSIX_ZERO(close(fd
), NULL
);
51 for (size_t i
= 0; i
< sizeof(tptr
)/sizeof(tptr
[0]); i
++) {
52 T_LOG("=== {%ld, %ld} {%ld, %ld} ===",
53 tptr
[i
][0].tv_sec
, tptr
[i
][0].tv_nsec
,
54 tptr
[i
][1].tv_sec
, tptr
[i
][1].tv_nsec
);
57 clock_gettime(CLOCK_REALTIME
, &now
);
59 T_ASSERT_POSIX_ZERO(stat(FILENAME
, &pre_st
), NULL
);
60 T_ASSERT_POSIX_ZERO(utimensat(AT_FDCWD
, FILENAME
, tptr
[i
], 0), NULL
);
61 T_ASSERT_POSIX_ZERO(stat(FILENAME
, &post_st
), NULL
);
63 if (tptr
[i
][0].tv_nsec
== UTIME_NOW
) {
64 T_ASSERT_GE(post_st
.st_atimespec
.tv_sec
, now
.tv_sec
, NULL
);
65 } else if (tptr
[i
][0].tv_nsec
== UTIME_OMIT
) {
66 T_ASSERT_EQ(post_st
.st_atimespec
.tv_sec
, pre_st
.st_atimespec
.tv_sec
, NULL
);
67 T_ASSERT_EQ(post_st
.st_atimespec
.tv_nsec
, pre_st
.st_atimespec
.tv_nsec
, NULL
);
69 T_ASSERT_EQ(post_st
.st_atimespec
.tv_sec
, tptr
[i
][0].tv_sec
, NULL
);
70 T_ASSERT_EQ(post_st
.st_atimespec
.tv_nsec
, tptr
[i
][0].tv_nsec
, NULL
);
73 if (tptr
[i
][1].tv_nsec
== UTIME_NOW
) {
74 T_ASSERT_GE(post_st
.st_mtimespec
.tv_sec
, now
.tv_sec
, NULL
);
75 } else if (tptr
[i
][1].tv_nsec
== UTIME_OMIT
) {
76 T_ASSERT_EQ(post_st
.st_mtimespec
.tv_sec
, pre_st
.st_mtimespec
.tv_sec
, NULL
);
77 T_ASSERT_EQ(post_st
.st_mtimespec
.tv_nsec
, pre_st
.st_mtimespec
.tv_nsec
, NULL
);
79 T_ASSERT_EQ(post_st
.st_mtimespec
.tv_sec
, tptr
[i
][1].tv_sec
, NULL
);
80 T_ASSERT_EQ(post_st
.st_mtimespec
.tv_nsec
, tptr
[i
][1].tv_nsec
, NULL
);