diff --git a/clang/test/Modules/prune.m b/clang/test/Modules/prune.m --- a/clang/test/Modules/prune.m +++ b/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 diff --git a/lld/test/COFF/lto-cache.ll b/lld/test/COFF/lto-cache.ll --- a/lld/test/COFF/lto-cache.ll +++ b/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 diff --git a/lld/test/ELF/lto/cache.ll b/lld/test/ELF/lto/cache.ll --- a/lld/test/ELF/lto/cache.ll +++ b/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 diff --git a/lld/test/MachO/lto-cache.ll b/lld/test/MachO/lto-cache.ll --- a/lld/test/MachO/lto-cache.ll +++ b/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 diff --git a/lld/test/wasm/lto/cache.ll b/lld/test/wasm/lto/cache.ll --- a/lld/test/wasm/lto/cache.ll +++ b/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. diff --git a/llvm/test/ThinLTO/X86/cache.ll b/llvm/test/ThinLTO/X86/cache.ll --- a/llvm/test/ThinLTO/X86/cache.ll +++ b/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. diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test b/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test --- a/llvm/test/tools/llvm-objcopy/ELF/strip-preserve-atime.test +++ b/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 diff --git a/llvm/utils/lit/lit/llvm/config.py b/llvm/utils/lit/lit/llvm/config.py --- a/llvm/utils/lit/lit/llvm/config.py +++ b/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,40 @@ 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 + + return re.search(r'\b1995\b', touch_res_out) is not None + def _find_git_windows_unix_tools(self, tools_needed): assert(sys.platform == 'win32') if sys.version_info.major >= 3: