[libc++] Make sure tests are run in a unique directory
authorLouis Dionne <ldionne@apple.com>
Wed, 10 Jun 2020 18:11:25 +0000 (14:11 -0400)
committerLouis Dionne <ldionne@apple.com>
Wed, 10 Jun 2020 20:19:10 +0000 (16:19 -0400)
This will allow simplifying executors by always just copying the whole
%T, and assuming that all file dependencies are contained in it.

Superseeds https://reviews.llvm.org/D78245, which tried to make %T unique
in Lit, but which encountered push back.

libcxx/test/libcxx/selftest/newformat/tmpdir-exists.sh.cpp [new file with mode: 0644]
libcxx/utils/libcxx/test/dsl.py
libcxx/utils/libcxx/test/newformat.py

diff --git a/libcxx/test/libcxx/selftest/newformat/tmpdir-exists.sh.cpp b/libcxx/test/libcxx/selftest/newformat/tmpdir-exists.sh.cpp
new file mode 100644 (file)
index 0000000..7f9e69d
--- /dev/null
@@ -0,0 +1,11 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// Make sure that the directory represented by %T exists when we run the test.
+
+// RUN: test -d %T
index d449c60..f3add44 100644 (file)
@@ -33,7 +33,7 @@ def _executeScriptInternal(test, commands):
       self.isWindows = platform.system() == 'Windows'
       self.maxIndividualTestTime = 0
   litConfig = FakeLitConfig()
-  _, tmpBase = lit.TestRunner.getTempPaths(test)
+  _, tmpBase = libcxx.test.newformat._getTempPaths(test)
   execDir = os.path.dirname(test.getExecPath())
   if not os.path.exists(execDir):
     os.makedirs(execDir)
index 0bb3be3..43b11a4 100644 (file)
@@ -27,6 +27,19 @@ def _supportsVerify(config):
     result = subprocess.call(command, shell=True, stdout=devNull, stderr=devNull)
     return result == 0
 
+def _getTempPaths(test):
+    """
+    Return the values to use for the %T and %t substitutions, respectively.
+
+    The difference between this and Lit's default behavior is that we guarantee
+    that %T is a path unique to the test being run.
+    """
+    tmpDir, _ = lit.TestRunner.getTempPaths(test)
+    _, testName = os.path.split(test.getExecPath())
+    tmpDir = os.path.join(tmpDir, testName + '.dir')
+    tmpBase = os.path.join(tmpDir, 't')
+    return tmpDir, tmpBase
+
 def parseScript(test, preamble, fileDependencies):
     """
     Extract the script from a test, with substitutions applied.
@@ -47,7 +60,7 @@ def parseScript(test, preamble, fileDependencies):
     """
 
     # Get the default substitutions
-    tmpDir, tmpBase = lit.TestRunner.getTempPaths(test)
+    tmpDir, tmpBase = _getTempPaths(test)
     useExternalSh = True
     substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir, tmpBase,
                                                            normalize_slashes=useExternalSh)
@@ -311,6 +324,6 @@ class CxxStandardLibraryTest(lit.formats.TestFormat):
         if litConfig.noExecute:
             return lit.Test.Result(lit.Test.XFAIL if test.isExpectedToFail() else lit.Test.PASS)
         else:
-            _, tmpBase = lit.TestRunner.getTempPaths(test)
+            _, tmpBase = _getTempPaths(test)
             useExternalSh = True
             return lit.TestRunner._runShTest(test, litConfig, useExternalSh, script, tmpBase)