[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-commits
Subject:    [PATCH] D42755: [libcxx] Fix last_write_time tests for filesystems that don't support very small tim
From:       Volodymyr Sapsai via Phabricator via cfe-commits <cfe-commits () lists ! llvm ! org>
Date:       2018-02-28 23:30:09
Message-ID: f69f6040dec7488201076ee0b30e97e0 () localhost ! localdomain
[Download RAW message or body]

This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326383: [libcxx] Fix last_write_time test for filesystems that \
don&#039;t support very small… (authored by vsapsai, committed by ). Herald added a \
subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42755?vs=135003&id=136410#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42755

Files:
  libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp



Index: libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 ===================================================================
--- libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
                
+++ libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 @@ -116,12 +116,31 @@
     return !ec && new_write_time > max_sec - 1;
 }
 
+bool TestSupportsMinTime() {
+    using namespace std::chrono;
+    using Lim = std::numeric_limits<std::time_t>;
+    auto min_sec = duration_cast<seconds>(file_time_type::min().time_since_epoch()).count();
 +    if (min_sec < Lim::min()) return false;
+    std::error_code ec;
+    std::time_t old_write_time, new_write_time;
+    { // WARNING: Do not assert in this scope.
+      scoped_test_env env;
+      const path file = env.create_file("file", 42);
+      old_write_time = LastWriteTime(file);
+      file_time_type tp = file_time_type::min();
+      fs::last_write_time(file, tp, ec);
+      new_write_time = LastWriteTime(file);
+    }
+    return !ec && new_write_time < min_sec + 1;
+}
+
 #if defined(__clang__)
 #pragma clang diagnostic pop
 #endif
 
 static const bool SupportsNegativeTimes = TestSupportsNegativeTimes();
 static const bool SupportsMaxTime = TestSupportsMaxTime();
+static const bool SupportsMinTime = TestSupportsMinTime();
 
 } // end namespace
 
@@ -140,14 +159,17 @@
 // (B) 'tp' is non-negative or the filesystem supports negative times.
 // (C) 'tp' is not 'file_time_type::max()' or the filesystem supports the max
 //     value.
+// (D) 'tp' is not 'file_time_type::min()' or the filesystem supports the min
+//     value.
 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 (microsec < 0 && !SupportsNegativeTimes) return false;
     else if (tp == file_time_type::max() && !SupportsMaxTime) return false;
+    else if (tp == file_time_type::min() && !SupportsMinTime) return false;
     return true;
 }
 
@@ -355,20 +377,20 @@
         TEST_CHECK(!ec);
         TEST_CHECK(tt >= new_time);
         TEST_CHECK(tt < new_time + Sec(1));
-    }
 
-    ec = GetTestEC();
-    last_write_time(p, Clock::now());
+        ec = GetTestEC();
+        last_write_time(p, Clock::now());
 
-    new_time = file_time_type::min() + MicroSec(1);
+        new_time = file_time_type::min() + MicroSec(1);
 
-    last_write_time(p, new_time, ec);
-    tt = last_write_time(p);
+        last_write_time(p, new_time, ec);
+        tt = last_write_time(p);
 
-    if (TimeIsRepresentableByFilesystem(new_time)) {
-        TEST_CHECK(!ec);
-        TEST_CHECK(tt >= new_time);
-        TEST_CHECK(tt < new_time + Sec(1));
+        if (TimeIsRepresentableByFilesystem(new_time)) {
+            TEST_CHECK(!ec);
+            TEST_CHECK(tt >= new_time);
+            TEST_CHECK(tt < new_time + Sec(1));
+        }
     }
 }
 


["D42755.136410.patch" (text/x-patch)]

Index: libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 ===================================================================
--- libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
                
+++ libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.last_write_time/last_write_time.pass.cpp
 @@ -116,12 +116,31 @@
     return !ec && new_write_time > max_sec - 1;
 }
 
+bool TestSupportsMinTime() {
+    using namespace std::chrono;
+    using Lim = std::numeric_limits<std::time_t>;
+    auto min_sec = duration_cast<seconds>(file_time_type::min().time_since_epoch()).count();
 +    if (min_sec < Lim::min()) return false;
+    std::error_code ec;
+    std::time_t old_write_time, new_write_time;
+    { // WARNING: Do not assert in this scope.
+      scoped_test_env env;
+      const path file = env.create_file("file", 42);
+      old_write_time = LastWriteTime(file);
+      file_time_type tp = file_time_type::min();
+      fs::last_write_time(file, tp, ec);
+      new_write_time = LastWriteTime(file);
+    }
+    return !ec && new_write_time < min_sec + 1;
+}
+
 #if defined(__clang__)
 #pragma clang diagnostic pop
 #endif
 
 static const bool SupportsNegativeTimes = TestSupportsNegativeTimes();
 static const bool SupportsMaxTime = TestSupportsMaxTime();
+static const bool SupportsMinTime = TestSupportsMinTime();
 
 } // end namespace
 
@@ -140,14 +159,17 @@
 // (B) 'tp' is non-negative or the filesystem supports negative times.
 // (C) 'tp' is not 'file_time_type::max()' or the filesystem supports the max
 //     value.
+// (D) 'tp' is not 'file_time_type::min()' or the filesystem supports the min
+//     value.
 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 (microsec < 0 && !SupportsNegativeTimes) return false;
     else if (tp == file_time_type::max() && !SupportsMaxTime) return false;
+    else if (tp == file_time_type::min() && !SupportsMinTime) return false;
     return true;
 }
 
@@ -355,20 +377,20 @@
         TEST_CHECK(!ec);
         TEST_CHECK(tt >= new_time);
         TEST_CHECK(tt < new_time + Sec(1));
-    }
 
-    ec = GetTestEC();
-    last_write_time(p, Clock::now());
+        ec = GetTestEC();
+        last_write_time(p, Clock::now());
 
-    new_time = file_time_type::min() + MicroSec(1);
+        new_time = file_time_type::min() + MicroSec(1);
 
-    last_write_time(p, new_time, ec);
-    tt = last_write_time(p);
+        last_write_time(p, new_time, ec);
+        tt = last_write_time(p);
 
-    if (TimeIsRepresentableByFilesystem(new_time)) {
-        TEST_CHECK(!ec);
-        TEST_CHECK(tt >= new_time);
-        TEST_CHECK(tt < new_time + Sec(1));
+        if (TimeIsRepresentableByFilesystem(new_time)) {
+            TEST_CHECK(!ec);
+            TEST_CHECK(tt >= new_time);
+            TEST_CHECK(tt < new_time + Sec(1));
+        }
     }
 }
 


[Attachment #4 (text/plain)]

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic