summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/utils/lit/lit/TestingConfig.py13
-rwxr-xr-xllvm/utils/lit/lit/main.py26
2 files changed, 28 insertions, 11 deletions
diff --git a/llvm/utils/lit/lit/TestingConfig.py b/llvm/utils/lit/lit/TestingConfig.py
index 1e39a000c90..f3c0b11faaf 100644
--- a/llvm/utils/lit/lit/TestingConfig.py
+++ b/llvm/utils/lit/lit/TestingConfig.py
@@ -25,7 +25,8 @@ class TestingConfig:
pass_vars = ['LIBRARY_PATH', 'LD_LIBRARY_PATH', 'SYSTEMROOT', 'TERM',
'LD_PRELOAD', 'ASAN_OPTIONS', 'UBSAN_OPTIONS',
'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL',
- 'SANITIZER_IGNORE_CVE_2016_2143']
+ 'SANITIZER_IGNORE_CVE_2016_2143', 'TMPDIR', 'TMP', 'TEMP',
+ 'TEMPDIR']
for var in pass_vars:
val = os.environ.get(var, '')
# Check for empty string as some variables such as LD_PRELOAD cannot be empty
@@ -42,16 +43,6 @@ class TestingConfig:
'TMP' : os.environ.get('TMP',''),
})
- # The option to preserve TEMP, TMP, and TMPDIR.
- # This is intended to check how many temporary files would be generated
- # (and be not cleaned up) in automated builders.
- if 'LIT_PRESERVES_TMP' in os.environ:
- environment.update({
- 'TEMP' : os.environ.get('TEMP',''),
- 'TMP' : os.environ.get('TMP',''),
- 'TMPDIR' : os.environ.get('TMPDIR',''),
- })
-
# Set the default available features based on the LitConfig.
available_features = []
if litConfig.useValgrind:
diff --git a/llvm/utils/lit/lit/main.py b/llvm/utils/lit/lit/main.py
index 30ae8b3e533..243a9dddb46 100755
--- a/llvm/utils/lit/lit/main.py
+++ b/llvm/utils/lit/lit/main.py
@@ -8,6 +8,8 @@ See lit.pod for more information.
from __future__ import absolute_import
import math, os, platform, random, re, sys, time
+import tempfile
+import shutil
import lit.ProgressBar
import lit.LitConfig
@@ -132,6 +134,30 @@ def sort_by_incremental_cache(run):
run.tests.sort(key = lambda t: sortIndex(t))
def main(builtinParameters = {}):
+ # Create a temp directory inside the normal temp directory so that we can
+ # try to avoid temporary test file leaks. The user can avoid this behavior
+ # by setting LIT_PRESERVES_TMP in the environment, so they can easily use
+ # their own temp directory to monitor temporary file leaks or handle them at
+ # the buildbot level.
+ lit_tmp = None
+ if 'LIT_PRESERVES_TMP' not in os.environ:
+ lit_tmp = tempfile.mkdtemp(prefix="lit_tmp_")
+ os.environ.update({
+ 'TMPDIR': lit_tmp,
+ 'TMP': lit_tmp,
+ 'TEMP': lit_tmp,
+ 'TEMPDIR': lit_tmp,
+ })
+ # FIXME: If Python does not exit cleanly, this directory will not be cleaned
+ # up. We should consider writing the lit pid into the temp directory,
+ # scanning for stale temp directories, and deleting temp directories whose
+ # lit process has died.
+ try:
+ main_with_tmp(builtinParameters)
+ finally:
+ shutil.rmtree(lit_tmp)
+
+def main_with_tmp(builtinParameters):
global options
from optparse import OptionParser, OptionGroup
parser = OptionParser("usage: %prog [options] {file-or-path}")
OpenPOWER on IntegriCloud