aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-01-11 10:03:00 -0500
committerNick Mathewson <nickm@torproject.org>2016-01-11 10:03:00 -0500
commit16840e52e594e221069efc9bf7b65ebfb5e2d639 (patch)
tree41c682bd3d51984a20e95b3eb67db97f94ba7280
parent1d6dd288e1c084a5118785899cca910e8c69fbb1 (diff)
downloadtor-16840e52e594e221069efc9bf7b65ebfb5e2d639.tar.gz
tor-16840e52e594e221069efc9bf7b65ebfb5e2d639.zip
Make the touch_file unit test work around FS/system time sync issues
Sometimes you can call time() and then touch a file, and have the second come out a little before the first. See #18025 for way more information than you necessarily wanted.
-rw-r--r--src/test/test_util.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 863105f002..37f7d938ea 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -4612,18 +4612,23 @@ test_util_touch_file(void *arg)
struct stat st;
write_bytes_to_file(fname, "abc", 3, 1);
tt_int_op(0, OP_EQ, stat(fname, &st));
- tt_i64_op(st.st_mtime, OP_GE, now);
+ /* A subtle point: the filesystem time is not necessarily equal to the
+ * system clock time, since one can be using a monotonic clock, or coarse
+ * monotonic clock, or whatever. So we might wind up with an mtime a few
+ * microseconds ago. Let's just give it a lot of wiggle room. */
+ tt_i64_op(st.st_mtime, OP_GE, now - 1);
const time_t five_sec_ago = now - 5;
struct utimbuf u = { five_sec_ago, five_sec_ago };
tt_int_op(0, OP_EQ, utime(fname, &u));
tt_int_op(0, OP_EQ, stat(fname, &st));
+ /* Let's hope that utime/stat give the same second as a round-trip? */
tt_i64_op(st.st_mtime, OP_EQ, five_sec_ago);
/* Finally we can touch the file */
tt_int_op(0, OP_EQ, touch_file(fname));
tt_int_op(0, OP_EQ, stat(fname, &st));
- tt_i64_op(st.st_mtime, OP_GE, now);
+ tt_i64_op(st.st_mtime, OP_GE, now-1);
done:
;