This is an archive of the discontinued LLVM Phabricator instance.

Filesystem tests: un-confuse write time
ClosedPublic

Authored by jfb on May 30 2018, 2:10 PM.

Details

Summary

The filesystem test was confused about access versus write / modification time. The spec says:

file_time_type last_write_time(const path& p, error_code& ec) noexcept;
Returns: The time of last data modification of p, determined as if by the value of the POSIX stat structure member st_mtime obtained as if by POSIX stat(). The signature with argument ec returns file_time_type::min() if an error occurs.

The test was looking at st_atime, not st_mtime, when comparing the result from last_write_time. That was probably due to using a pair instead of naming things nicely or using types. I opted to rename things so it's clearer.

This caused test bot failures.

rdar://problem/40648859

Diff Detail

Repository
rL LLVM

Event Timeline

jfb created this revision.May 30 2018, 2:10 PM
jfb edited the summary of this revision. (Show Details)May 30 2018, 2:11 PM
vsapsai added inline comments.
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
257–258 ↗(On Diff #149199)

We need a comment explaining the intention of this check. Do you know what are the values when the test fails?

I have another (not tested) interpretation of the test that consistently compares write times with write times and access times with access times.

TEST_CHECK(LastAccessTime(file) == file_access_time ||
           LastWriteTime(file) == Clock::to_time_t(ftime2));

I am suspicious about the suggested condition LastWriteTime(file) == file_write_time as I expect it to be false all the time.

vsapsai added inline comments.May 30 2018, 5:03 PM
test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
257–258 ↗(On Diff #149199)

After checking the last commit that touched this code https://reviews.llvm.org/rL278357 I'm not sure that was a mistake. Looks like the intention was indeed to check LastAccessTime.

What do you think about removing these LastAccessTime checks, including the one for dir? There is no function last_access_time, so we aren't testing the library but idiosyncrasies of file systems.

EricWF added a comment.EditedMay 31 2018, 10:44 AM

So the reason there are atime tests at all is due to the implementation details of __last_write_time here. Essentially we have to do extra work trying to maintain the access time. https://github.com/llvm-mirror/libcxx/blob/master/src/experimental/filesystem/operations.cpp#L855

I'm OK with this patches rename. first and second were certainly not clear.

That being said, I'm not sure we should be removing the access time tests, they were intentional.

jfb updated this revision to Diff 149377.May 31 2018, 3:52 PM
  • Remove access time checks, simplify existing check, after talking to EricWF on IRC.
jfb marked 2 inline comments as done.May 31 2018, 3:53 PM
EricWF accepted this revision.May 31 2018, 6:23 PM

LGTM after addressing inline comments.

test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
257 ↗(On Diff #149377)

What happened to the test for the directory? Can we add

TEST_CHECK(LastWriteTime(dir) == Clock::to_time_t(dtime2));
This revision is now accepted and ready to land.May 31 2018, 6:23 PM
jfb updated this revision to Diff 149398.May 31 2018, 10:02 PM
  • Add back directory test
This revision was automatically updated to reflect the committed changes.
jfb marked an inline comment as done.May 31 2018, 10:04 PM