annotate tests/test-utimens.h @ 40186:8964917f9574

autoupdate
author Karl Berry <karl@freefriends.org>
date Mon, 18 Feb 2019 08:02:49 -0800
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Test of file timestamp modification functions.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 39833
diff changeset
2 Copyright (C) 2009-2019 Free Software Foundation, Inc.
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
12520
e84eea643139 tests: fix license on several tests
Eric Blake <ebb9@byu.net>
parents: 12495
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 19059
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
17 #include "test-utimens-common.h"
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
19 /* This file is designed to test both utimens(a,b) and
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
20 utimensat(AT_FDCWD,a,b,0). FUNC is the function to test. Assumes
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
21 that BASE and ASSERT are already defined. If PRINT, warn before
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
22 skipping tests with status 77. */
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 static int
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
24 test_utimens (int (*func) (char const *, struct timespec const *), bool print)
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 {
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 struct stat st1;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27 struct stat st2;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 ASSERT (close (creat (BASE "file", 0600)) == 0);
39833
4c9d0c898076 timespec: fix resolution confusion
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
30 /* If utimens truncates to worse resolution than the file system
12165
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
31 supports, then time can appear to go backwards between now and a
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
32 follow-up utimens with UTIME_NOW or a NULL timespec. Use
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
33 UTIMECMP_TRUNCATE_SOURCE to compensate, with st1 as the
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
34 source. */
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 ASSERT (stat (BASE "file", &st1) == 0);
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
36 nap ();
12165
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
37 ASSERT (func (BASE "file", NULL) == 0);
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
38 ASSERT (stat (BASE "file", &st2) == 0);
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
39 ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE));
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
40 if (check_ctime)
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
41 ASSERT (ctime_compare (&st1, &st2) < 0);
12165
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
42 {
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
43 /* On some NFS systems, the 'now' timestamp of creat or a NULL
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
44 timespec is determined by the server, but the 'now' timestamp
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
45 determined by gettime() (as is done when using UTIME_NOW) is
12165
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
46 determined by the client; since the two machines are not
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
47 necessarily on the same clock, this is another case where time
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
48 can appear to go backwards. The rest of this test cares about
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
49 client time, so manually use gettime() to set both times. */
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
50 struct timespec ts[2];
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
51 gettime (&ts[0]);
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
52 ts[1] = ts[0];
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
53 ASSERT (func (BASE "file", ts) == 0);
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
54 ASSERT (stat (BASE "file", &st1) == 0);
12171
47c9f1788846 test-stat-time, test-utimens: improve portability
Eric Blake <ebb9@byu.net>
parents: 12165
diff changeset
55 nap ();
12165
c5a8a8e67e6f utimens-tests: port to NFS file systems
Eric Blake <ebb9@byu.net>
parents: 12156
diff changeset
56 }
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 /* Invalid arguments. */
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 errno = 0;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 ASSERT (func ("no_such", NULL) == -1);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 ASSERT (errno == ENOENT);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 errno = 0;
12194
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
63 ASSERT (func ("no_such/", NULL) == -1);
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
64 ASSERT (errno == ENOENT || errno == ENOTDIR);
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
65 errno = 0;
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 ASSERT (func ("", NULL) == -1);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 ASSERT (errno == ENOENT);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 {
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
69 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
70 ts[0].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
71 ts[0].tv_nsec = UTIME_BOGUS_POS;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
72 ts[1].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
73 ts[1].tv_nsec = 0;
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 errno = 0;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 ASSERT (func (BASE "file", ts) == -1);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 ASSERT (errno == EINVAL);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 }
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 {
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
79 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
80 ts[0].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
81 ts[0].tv_nsec = 0;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
82 ts[1].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
83 ts[1].tv_nsec = UTIME_BOGUS_NEG;
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 errno = 0;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 ASSERT (func (BASE "file", ts) == -1);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 ASSERT (errno == EINVAL);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 }
12194
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
88 {
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
89 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
90 ts[0].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
91 ts[0].tv_nsec = 0;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
92 ts[1] = ts[0];
12194
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
93 errno = 0;
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
94 ASSERT (func (BASE "file/", ts) == -1);
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
95 ASSERT (errno == ENOTDIR || errno == EINVAL);
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
96 }
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 ASSERT (stat (BASE "file", &st2) == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98 ASSERT (st1.st_atime == st2.st_atime);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
99 ASSERT (get_stat_atime_ns (&st1) == get_stat_atime_ns (&st2));
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
100 ASSERT (utimecmp (BASE "file", &st1, &st2, 0) == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
101
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
102 /* Set both times. */
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
103 {
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
104 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
105 ts[0].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
106 ts[0].tv_nsec = BILLION / 2 - 1;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
107 ts[1].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
108 ts[1].tv_nsec = BILLION - 1;
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
109 ASSERT (func (BASE "file", ts) == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
110 ASSERT (stat (BASE "file", &st2) == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
111 ASSERT (st2.st_atime == Y2K);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
112 ASSERT (0 <= get_stat_atime_ns (&st2));
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
113 ASSERT (get_stat_atime_ns (&st2) < BILLION / 2);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
114 ASSERT (st2.st_mtime == Y2K);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
115 ASSERT (0 <= get_stat_mtime_ns (&st2));
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
116 ASSERT (get_stat_mtime_ns (&st2) < BILLION);
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
117 if (check_ctime)
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
118 ASSERT (ctime_compare (&st1, &st2) < 0);
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
119 }
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
120
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
121 /* Play with UTIME_OMIT, UTIME_NOW. */
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
122 {
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
123 struct stat st3;
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
124 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
125 ts[0].tv_sec = BILLION;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
126 ts[0].tv_nsec = UTIME_OMIT;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
127 ts[1].tv_sec = 0;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
128 ts[1].tv_nsec = UTIME_NOW;
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
129 nap ();
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
130 ASSERT (func (BASE "file", ts) == 0);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
131 ASSERT (stat (BASE "file", &st3) == 0);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
132 ASSERT (st3.st_atime == Y2K);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
133 ASSERT (0 <= get_stat_atime_ns (&st3));
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
134 ASSERT (get_stat_atime_ns (&st3) < BILLION / 2);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
135 /* See comment above about this utimecmp call. */
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
136 ASSERT (0 <= utimecmp (BASE "file", &st3, &st1, UTIMECMP_TRUNCATE_SOURCE));
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
137 if (check_ctime)
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
138 ASSERT (ctime_compare (&st2, &st3) < 0);
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
139 nap ();
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
140 ts[0].tv_nsec = 0;
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
141 ts[1].tv_nsec = UTIME_OMIT;
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
142 ASSERT (func (BASE "file", ts) == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
143 ASSERT (stat (BASE "file", &st2) == 0);
12466
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
144 ASSERT (st2.st_atime == BILLION);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
145 ASSERT (get_stat_atime_ns (&st2) == 0);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
146 ASSERT (st3.st_mtime == st2.st_mtime);
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
147 ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2));
e31a9e90d604 utimens: check for ctime update
Eric Blake <ebb9@byu.net>
parents: 12194
diff changeset
148 if (check_ctime)
16092
936e267d6906 tests: factor out st_ctime-comparison code (a dozen uses)
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
149 ASSERT (ctime_compare (&st3, &st2) < 0);
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 }
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
152 /* Make sure this dereferences symlinks. */
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
153 if (symlink (BASE "file", BASE "link"))
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
154 {
12495
16a0ada3a101 Fix indentation.
Bruno Haible <bruno@clisp.org>
parents: 12466
diff changeset
155 ASSERT (unlink (BASE "file") == 0);
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
156 if (print)
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
157 fputs ("skipping test: symlinks not supported on this file system\n",
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
158 stderr);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
159 return 77;
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
160 }
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
161 ASSERT (lstat (BASE "link", &st1) == 0);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
162 ASSERT (st1.st_mtime != Y2K);
12194
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
163 errno = 0;
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
164 ASSERT (func (BASE "link/", NULL) == -1);
16c7c4fa9754 utimensat: work around Solaris 9 bug
Eric Blake <ebb9@byu.net>
parents: 12173
diff changeset
165 ASSERT (errno == ENOTDIR);
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
166 {
19059
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
167 struct timespec ts[2];
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
168 ts[0].tv_sec = Y2K;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
169 ts[0].tv_nsec = 0;
8e51de943f6b futimens: don’t assume struct timespec layout
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
170 ts[1] = ts[0];
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
171 ASSERT (func (BASE "link", ts) == 0);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
172 ASSERT (lstat (BASE "link", &st2) == 0);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
173 /* Can't compare atimes, since lstat() changes symlink atime on cygwin. */
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
174 ASSERT (st1.st_mtime == st2.st_mtime);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
175 ASSERT (stat (BASE "link", &st2) == 0);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
176 ASSERT (st2.st_mtime == Y2K);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
177 ASSERT (get_stat_mtime_ns (&st2) == 0);
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
178 }
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
179
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
180 /* Cleanup. */
12173
efdb2ab5743f utimens: let lutimens work on non-symlinks
Eric Blake <ebb9@byu.net>
parents: 12171
diff changeset
181 ASSERT (unlink (BASE "link") == 0);
12156
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
182 ASSERT (unlink (BASE "file") == 0);
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
183 return 0;
3c7d1f073266 utimens: add test
Eric Blake <ebb9@byu.net>
parents:
diff changeset
184 }