* tests/test-utimens-common.h (ctime_compare): Define.
* tests/test-futimens.h (test_futimens): Replace open-coded equivalent.
* tests/test-lutimens.h (test_lutimens): Likewise.
* tests/test-utimens.h (test_utimens): Likewise.
2011-11-17 Jim Meyering <meyering@redhat.com>
+ tests: factor st_ctime-comparison out of two headers
+ * tests/test-utimens-common.h (ctime_compare): Define.
+ * tests/test-futimens.h (test_futimens): Replace open-coded equivalent.
+ * tests/test-lutimens.h (test_lutimens): Likewise.
+ * tests/test-utimens.h (test_utimens): Likewise.
+
test-getcwd: don't leave behind a confdir3/ directory upon interrupt
Invoke the test program via an init.sh-using wrapper.
* tests/test-getcwd.sh: New file.
source. */
ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE));
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
{
/* On some NFS systems, the 'now' timestamp of creat or a NULL
timespec is determined by the server, but the 'now' timestamp
ASSERT (0 <= get_stat_mtime_ns (&st2));
ASSERT (get_stat_mtime_ns (&st2) < BILLION);
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
}
/* Play with UTIME_OMIT, UTIME_NOW. */
ASSERT (get_stat_atime_ns (&st3) <= BILLION / 2);
ASSERT (utimecmp (BASE "file", &st1, &st3, 0) <= 0);
if (check_ctime)
- ASSERT (st2.st_ctime < st3.st_ctime
- || (st2.st_ctime == st3.st_ctime
- && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3)));
+ ASSERT (ctime_compare (&st2, &st3) < 0);
nap ();
ts[0].tv_nsec = 0;
ts[1].tv_nsec = UTIME_OMIT;
ASSERT (st3.st_mtime == st2.st_mtime);
ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2));
if (check_ctime)
- ASSERT (st3.st_ctime < st2.st_ctime
- || (st3.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st3, &st2) < 0);
}
/* Cleanup. */
ASSERT (st2.st_atime == Y2K);
ASSERT (st2.st_mtime == Y2K);
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
/* Play with symlink timestamps. */
if (symlink (BASE "file", BASE "link"))
ASSERT (0 <= get_stat_mtime_ns (&st2));
ASSERT (get_stat_mtime_ns (&st2) < BILLION);
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
}
/* Play with UTIME_OMIT, UTIME_NOW. */
}
ASSERT (utimecmp (BASE "link", &st1, &st3, 0) <= 0);
if (check_ctime)
- ASSERT (st2.st_ctime < st3.st_ctime
- || (st2.st_ctime == st3.st_ctime
- && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3)));
+ ASSERT (ctime_compare (&st2, &st3) < 0);
nap ();
ts[0].tv_nsec = 0;
ts[1].tv_nsec = UTIME_OMIT;
ASSERT (st3.st_mtime == st2.st_mtime);
ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2));
if (check_ctime)
- ASSERT (st3.st_ctime < st2.st_ctime
- || (st3.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st3, &st2) < 0);
}
/* Symlink to directory. */
# define check_ctime 1
# endif
+/* Compare two st_ctime values. Return -1, 0 or 1, respectively
+ when A's st_ctime is smaller than, equal to or greater than B's. */
+static inline int
+ctime_compare (struct stat const *a, struct stat const *b)
+{
+ if (a->st_ctime < b->st_ctime)
+ return -1;
+ else if (b->st_ctime < a->st_ctime)
+ return 1;
+ else if (get_stat_ctime_ns (a) < get_stat_ctime_ns (b))
+ return -1;
+ else if (get_stat_ctime_ns (b) < get_stat_ctime_ns (a))
+ return 1;
+ else
+ return 0;
+}
+
#endif /* GL_TEST_UTIMENS_COMMON */
ASSERT (stat (BASE "file", &st2) == 0);
ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE));
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
{
/* On some NFS systems, the 'now' timestamp of creat or a NULL
timespec is determined by the server, but the 'now' timestamp
ASSERT (0 <= get_stat_mtime_ns (&st2));
ASSERT (get_stat_mtime_ns (&st2) < BILLION);
if (check_ctime)
- ASSERT (st1.st_ctime < st2.st_ctime
- || (st1.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st1) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st1, &st2) < 0);
}
/* Play with UTIME_OMIT, UTIME_NOW. */
/* See comment above about this utimecmp call. */
ASSERT (0 <= utimecmp (BASE "file", &st3, &st1, UTIMECMP_TRUNCATE_SOURCE));
if (check_ctime)
- ASSERT (st2.st_ctime < st3.st_ctime
- || (st2.st_ctime == st3.st_ctime
- && get_stat_ctime_ns (&st2) < get_stat_ctime_ns (&st3)));
+ ASSERT (ctime_compare (&st2, &st3) < 0);
nap ();
ts[0].tv_nsec = 0;
ts[1].tv_nsec = UTIME_OMIT;
ASSERT (st3.st_mtime == st2.st_mtime);
ASSERT (get_stat_mtime_ns (&st3) == get_stat_mtime_ns (&st2));
if (check_ctime)
- ASSERT (st3.st_ctime < st2.st_ctime
- || (st3.st_ctime == st2.st_ctime
- && get_stat_ctime_ns (&st3) < get_stat_ctime_ns (&st2)));
+ ASSERT (ctime_compare (&st3, &st2) < 0);
}
/* Make sure this dereferences symlinks. */