lenary retitled this revision from "[lit] Detect Consistent File Access Times" 
to "[lit] Detect Inconsistent File Access Times".
lenary edited the summary of this revision.
lenary updated this revision to Diff 500742.
Herald added a subscriber: krytarowski.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144638/new/

https://reviews.llvm.org/D144638

Files:
  clang/test/Modules/prune.m
  lld/test/COFF/lto-cache.ll
  lld/test/ELF/lto/cache.ll
  lld/test/MachO/lto-cache.ll
  lld/test/wasm/lto/cache.ll
  llvm/test/ThinLTO/X86/cache.ll
  llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
  llvm/utils/lit/lit/llvm/config.py

Index: llvm/utils/lit/lit/llvm/config.py
===================================================================
--- llvm/utils/lit/lit/llvm/config.py
+++ llvm/utils/lit/lit/llvm/config.py
@@ -5,6 +5,7 @@
 import subprocess
 import sys
 import errno
+import tempfile
 
 import lit.util
 from lit.llvm.subst import FindTool
@@ -155,6 +156,42 @@
                 self.with_environment(
                     'DYLD_INSERT_LIBRARIES', gmalloc_path_str)
 
+        if self._has_consistent_atime():
+            features.add('consistent-atime')
+
+    # Some tests use `touch` to set the access time for a file, and expect no
+    # other processes to change this during the test run. This is not always the
+    # case, so we have a way to disable these tests on systems where the access
+    # might not be preserved.
+    def _has_consistent_atime(self):
+        # NetBSD: noatime mounts currently inhibit 'touch -a' updates.
+        if platform.system() == 'NetBSD':
+            return False
+
+        # Windows: the last access time is disabled by default in the OS, and
+        # the check below is written in terms of unix utilities (touch, ls),
+        # which will not work on this platform.
+        if platform.system() == 'Windows':
+            return False
+
+        # Other Platforms: Try to use `touch -a` to set the atime, and then to
+        # read it with `ls`. If they don't match, or either process errors, then
+        # don't claim that atime is consistent.
+        with tempfile.NamedTemporaryFile() as f:
+            # Specific date in the past on purpose, based on what is attempted
+            # in the tests that do the same thing.
+            (_, try_touch_err) = self.get_process_output(["touch", "-a", "-t", "199505050555.55", f.name])
+            if try_touch_err != "":
+                return False
+
+            (touch_res_out, touch_res_err) = self.get_process_output(["ls", "-lu", f.name])
+            if touch_res_err != "":
+                return False
+            if "1995" not in touch_res_out:
+                return False
+
+            return True
+
     def _find_git_windows_unix_tools(self, tools_needed):
         assert(sys.platform == 'win32')
         if sys.version_info.major >= 3:
Index: llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
===================================================================
--- llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
+++ llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
@@ -1,7 +1,5 @@
 # Note: ls -lu prints the accessed timestamp
-# NetBSD: noatime mounts currently inhibit 'touch -a' updates
-# Windows: the last access time is disabled by default in the OS
-# UNSUPPORTED: system-netbsd, system-windows
+# REQUIRES: consistent-atime
 
 # Preserve dates when stripping to an output file.
 # RUN: yaml2obj %s -o %t.1.o
Index: llvm/test/ThinLTO/X86/cache.ll
===================================================================
--- llvm/test/ThinLTO/X86/cache.ll
+++ llvm/test/ThinLTO/X86/cache.ll
@@ -1,5 +1,4 @@
-; NetBSD: noatime mounts currently inhibit 'touch -a' updates
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; The .noindex suffix for output dir is to prevent Spotlight on macOS from
 ; indexing it.
Index: lld/test/wasm/lto/cache.ll
===================================================================
--- lld/test/wasm/lto/cache.ll
+++ lld/test/wasm/lto/cache.ll
@@ -1,8 +1,6 @@
 ; RUN: opt -module-hash -module-summary %s -o %t.o
 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; Windows: no 'touch' command.
-; UNSUPPORTED: system-netbsd, system-windows
+; REQUIRES: consistent-atime
 
 ; RUN: rm -Rf %t.cache && mkdir %t.cache
 ; Create two files that would be removed by cache pruning due to age.
Index: lld/test/MachO/lto-cache.ll
===================================================================
--- lld/test/MachO/lto-cache.ll
+++ lld/test/MachO/lto-cache.ll
@@ -1,6 +1,5 @@
 ; REQUIRES: x86
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; RUN: rm -rf %t; split-file %s %t
 ; RUN: opt -module-hash -module-summary %t/foo.ll -o %t/foo.o
Index: lld/test/ELF/lto/cache.ll
===================================================================
--- lld/test/ELF/lto/cache.ll
+++ lld/test/ELF/lto/cache.ll
@@ -1,6 +1,5 @@
 ; REQUIRES: x86
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; RUN: opt -module-hash -module-summary %s -o %t.o
 ; RUN: opt -module-hash -module-summary %p/Inputs/cache.ll -o %t2.o
Index: lld/test/COFF/lto-cache.ll
===================================================================
--- lld/test/COFF/lto-cache.ll
+++ lld/test/COFF/lto-cache.ll
@@ -1,6 +1,5 @@
 ; REQUIRES: x86
-; NetBSD: noatime mounts currently inhibit 'touch' from updating atime
-; UNSUPPORTED: system-netbsd
+; REQUIRES: consistent-atime
 
 ; RUN: opt -module-hash -module-summary %s -o %t.o
 ; RUN: opt -module-hash -module-summary %p/Inputs/lto-cache.ll -o %t2.o
Index: clang/test/Modules/prune.m
===================================================================
--- clang/test/Modules/prune.m
+++ clang/test/Modules/prune.m
@@ -1,5 +1,4 @@
-// NetBSD: noatime mounts currently inhibit 'touch -a' updates
-// UNSUPPORTED: system-netbsd
+// REQUIRES: consistent-atime
 
 // Test the automatic pruning of module cache entries.
 #ifdef IMPORT_DEPENDS_ON_MODULE
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to