[TableGen] Fix a bug introduced in r256627. If the switch was not emitted we still...
[oota-llvm.git] / utils / lit / lit / TestingConfig.py
index d1492aff567d2ab932a8996ac53256b7e0d4fa95..7441b94b9f0871f2664a477e094a7e1306d45843 100644 (file)
@@ -1,7 +1,7 @@
 import os
 import sys
 
-PY2 = sys.version_info[0] < 3
+OldPy = sys.version_info[0] == 2 and sys.version_info[1] < 7
 
 class TestingConfig:
     """"
@@ -11,21 +11,27 @@ class TestingConfig:
     @staticmethod
     def fromdefaults(litConfig):
         """
-        fromdefaults(litConfig -> TestingConfig
+        fromdefaults(litConfig) -> TestingConfig
 
         Create a TestingConfig object with default values.
         """
         # Set the environment based on the command line arguments.
         environment = {
-            'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''),
-            'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
             'PATH' : os.pathsep.join(litConfig.path +
                                      [os.environ.get('PATH','')]),
-            'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
-            'TERM' : os.environ.get('TERM',''),
             'LLVM_DISABLE_CRASH_REPORT' : '1',
             }
 
+        pass_vars = ['LIBRARY_PATH', 'LD_LIBRARY_PATH', 'SYSTEMROOT', 'TERM',
+                     'LD_PRELOAD', 'ASAN_OPTIONS', 'UBSAN_OPTIONS',
+                     'LSAN_OPTIONS', 'ADB', 'ANDROID_SERIAL']
+        for var in pass_vars:
+            val = os.environ.get(var, '')
+            # Check for empty string as some variables such as LD_PRELOAD cannot be empty
+            # ('') for OS's such as OpenBSD.
+            if val:
+                environment[var] = val
+
         if sys.platform == 'win32':
             environment.update({
                     'INCLUDE' : os.environ.get('INCLUDE',''),
@@ -35,6 +41,16 @@ 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:
@@ -64,24 +80,25 @@ class TestingConfig:
         """
 
         # Load the config script data.
-        f = open(path)
-        try:
-            data = f.read()
-        except:
-            litConfig.fatal('unable to load config file: %r' % (path,))
-        f.close()
+        data = None
+        if not OldPy:
+            f = open(path)
+            try:
+                data = f.read()
+            except:
+                litConfig.fatal('unable to load config file: %r' % (path,))
+            f.close()
 
         # Execute the config script to initialize the object.
         cfg_globals = dict(globals())
         cfg_globals['config'] = self
-        cfg_globals['lit'] = litConfig
         cfg_globals['lit_config'] = litConfig
         cfg_globals['__file__'] = path
         try:
-            if PY2:
-                exec("exec data in cfg_globals")
+            if OldPy:
+                execfile(path, cfg_globals)
             else:
-                exec(data, cfg_globals)
+                exec(compile(data, path, 'exec'), cfg_globals, None)
             if litConfig.debug:
                 litConfig.note('... loaded config %r' % path)
         except SystemExit:
@@ -101,7 +118,7 @@ class TestingConfig:
     def __init__(self, parent, name, suffixes, test_format,
                  environment, substitutions, unsupported,
                  test_exec_root, test_source_root, excludes,
-                 available_features, pipefail):
+                 available_features, pipefail, limit_to_features = []):
         self.parent = parent
         self.name = str(name)
         self.suffixes = set(suffixes)
@@ -114,17 +131,10 @@ class TestingConfig:
         self.excludes = set(excludes)
         self.available_features = set(available_features)
         self.pipefail = pipefail
-
-    def clone(self):
-        # FIXME: Chain implementations?
-        #
-        # FIXME: Allow extra parameters?
-        return TestingConfig(self, self.name, self.suffixes, self.test_format,
-                             self.environment, self.substitutions,
-                             self.unsupported,
-                             self.test_exec_root, self.test_source_root,
-                             self.excludes, self.available_features,
-                             self.pipefail)
+        # This list is used by TestRunner.py to restrict running only tests that
+        # require one of the features in this list if this list is non-empty.
+        # Configurations can set this list to restrict the set of tests to run.
+        self.limit_to_features = set(limit_to_features)
 
     def finish(self, litConfig):
         """finish() - Finish this config object, after loading is complete."""