Details
- Reviewers
EricWF - Commits
- rG5476b86ed302: Merging r292013: --------------------------------------------------------------…
rG0ab3b772940e: Fix last_write_time tests for filesystems that don't support negative and very…
rCXX292013: Fix last_write_time tests for filesystems that don't support negative and very…
rL292341: Merging r292013:
rL292013: Fix last_write_time tests for filesystems that don't support negative and very…
Diff Detail
- Repository
- rL LLVM
Event Timeline
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp | ||
---|---|---|
113–119 ↗ | (On Diff #64272) | Hmm no, this doesn't work for me: fs::last_write_time just takes the negative timestamp and overflows somewhere internally... |
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp | ||
---|---|---|
89–95 ↗ | (On Diff #64272) | Obviously, I meant this part of the code, sorry:
|
Any chance we can get this fixed?
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp | ||
---|---|---|
89–95 ↗ | (On Diff #64272) | Maybe we can use if (ec && new_write_time <= -5)? |
In addition to this patch, my local environment would require the following changes:
diff --git a/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp b/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp index 01b3a67..a01b386 100644 --- a/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp +++ b/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp @@ -86,13 +86,7 @@ bool TestSupportsNegativeTimes() { fs::last_write_time(file, tp, ec); new_write_time = LastWriteTime(file); } - if (ec) { - assert(old_write_time == new_write_time); - return false; - } else { - assert(new_write_time <= -5); - return true; - } + return !ec && new_write_time <= -5; } bool TestSupportsMaxTime() { @@ -110,13 +104,7 @@ bool TestSupportsMaxTime() { fs::last_write_time(file, tp, ec); new_write_time = LastWriteTime(file); } - if (ec) { - assert(new_write_time == old_write_time); - return false; - } else { - assert(new_write_time > old_write_time); - return true; - } + return !ec && new_write_time > max_sec - 1; } static const bool SupportsNegativeTimes = TestSupportsNegativeTimes(); @@ -133,8 +121,9 @@ inline bool TimeIsRepresentableByFilesystem(file_time_type tp) { using namespace std::chrono; using Lim = std::numeric_limits<std::time_t>; auto sec = duration_cast<seconds>(tp.time_since_epoch()).count(); + auto microsec = duration_cast<microseconds>(tp.time_since_epoch()).count(); if (sec < Lim::min() || sec > Lim::max()) return false; - else if (sec < 0 && !SupportsNegativeTimes) return false; + else if (microsec < 0 && !SupportsNegativeTimes) return false; else if (tp == file_time_type::max() && !SupportsMaxTime) return false; return true; } @@ -273,15 +262,17 @@ TEST_CASE(set_last_write_time_dynamic_env_test) file_time_type got_time = last_write_time(TC.p); - TEST_CHECK(got_time != old_time); - if (TC.new_time < epoch_time) { - TEST_CHECK(got_time <= TC.new_time); - TEST_CHECK(got_time > TC.new_time - Sec(1)); - } else { - TEST_CHECK(got_time <= TC.new_time + Sec(1)); - TEST_CHECK(got_time >= TC.new_time - Sec(1)); + if (TimeIsRepresentableByFilesystem(TC.new_time)) { + TEST_CHECK(got_time != old_time); + if (TC.new_time < epoch_time) { + TEST_CHECK(got_time <= TC.new_time); + TEST_CHECK(got_time > TC.new_time - Sec(1)); + } else { + TEST_CHECK(got_time <= TC.new_time + Sec(1)); + TEST_CHECK(got_time >= TC.new_time - Sec(1)); + } + TEST_CHECK(LastAccessTime(TC.p) == old_times.first); } - TEST_CHECK(LastAccessTime(TC.p) == old_times.first); } } @@ -334,11 +325,7 @@ TEST_CASE(test_write_min_time) last_write_time(p, new_time, ec); file_time_type tt = last_write_time(p); - if (!TimeIsRepresentableByFilesystem(new_time)) { - TEST_CHECK(ec); - TEST_CHECK(ec != GetTestEC()); - TEST_CHECK(tt == last_time); - } else { + if (TimeIsRepresentableByFilesystem(new_time)) { TEST_CHECK(!ec); TEST_CHECK(tt >= new_time); TEST_CHECK(tt < new_time + Sec(1)); @@ -353,11 +340,7 @@ TEST_CASE(test_write_min_time) last_write_time(p, new_time, ec); tt = last_write_time(p); - if (!TimeIsRepresentableByFilesystem(new_time)) { - TEST_CHECK(ec); - TEST_CHECK(ec != GetTestEC()); - TEST_CHECK(tt == last_time); - } else { + if (TimeIsRepresentableByFilesystem(new_time)) { TEST_CHECK(!ec); TEST_CHECK(tt >= new_time); TEST_CHECK(tt < new_time + Sec(1)); @@ -383,11 +366,7 @@ TEST_CASE(test_write_min_max_time) last_write_time(p, new_time, ec); file_time_type tt = last_write_time(p); - if (!TimeIsRepresentableByFilesystem(new_time)) { - TEST_CHECK(ec); - TEST_CHECK(ec != GetTestEC()); - TEST_CHECK(tt == last_time); - } else { + if (TimeIsRepresentableByFilesystem(new_time)) { TEST_CHECK(!ec); TEST_CHECK(tt > new_time - Sec(1)); TEST_CHECK(tt <= new_time);
However, this disables some of the tests if the filesystem behaves wrongly...
Sorry no progress yet. I've been working on bigger bugs relating to our handling of file times. Once I get those worked out I'll fix this.
LGTM. Do you need somebody to commit this for you?
Let me know once you've committed it and I'll merge it into the 4.0 branch.