Pass LSAN_OPTIONS down so that it is possible to add suppressions.
[oota-llvm.git] / utils / lit / lit / TestingConfig.py
1 import os
2 import sys
3
4 OldPy = sys.version_info[0] == 2 and sys.version_info[1] < 7
5
6 class TestingConfig:
7     """"
8     TestingConfig - Information on the tests inside a suite.
9     """
10
11     @staticmethod
12     def fromdefaults(litConfig):
13         """
14         fromdefaults(litConfig) -> TestingConfig
15
16         Create a TestingConfig object with default values.
17         """
18         # Set the environment based on the command line arguments.
19         environment = {
20             'PATH' : os.pathsep.join(litConfig.path +
21                                      [os.environ.get('PATH','')]),
22             'LLVM_DISABLE_CRASH_REPORT' : '1',
23             }
24
25         pass_vars = ['LIBRARY_PATH', 'LD_LIBRARY_PATH', 'SYSTEMROOT', 'TERM',
26                      'LD_PRELOAD', 'ASAN_OPTIONS', 'UBSAN_OPTIONS',
27                      'LSAN_OPTIONS']
28         for var in pass_vars:
29             environment[var] = os.environ.get(var, '')
30
31         if sys.platform == 'win32':
32             environment.update({
33                     'INCLUDE' : os.environ.get('INCLUDE',''),
34                     'PATHEXT' : os.environ.get('PATHEXT',''),
35                     'PYTHONUNBUFFERED' : '1',
36                     'TEMP' : os.environ.get('TEMP',''),
37                     'TMP' : os.environ.get('TMP',''),
38                     })
39
40         # The option to preserve TEMP, TMP, and TMPDIR.
41         # This is intended to check how many temporary files would be generated
42         # (and be not cleaned up) in automated builders.
43         if 'LIT_PRESERVES_TMP' in os.environ:
44             environment.update({
45                     'TEMP' : os.environ.get('TEMP',''),
46                     'TMP' : os.environ.get('TMP',''),
47                     'TMPDIR' : os.environ.get('TMPDIR',''),
48                     })
49
50         # Set the default available features based on the LitConfig.
51         available_features = []
52         if litConfig.useValgrind:
53             available_features.append('valgrind')
54             if litConfig.valgrindLeakCheck:
55                 available_features.append('vg_leak')
56
57         return TestingConfig(None,
58                              name = '<unnamed>',
59                              suffixes = set(),
60                              test_format = None,
61                              environment = environment,
62                              substitutions = [],
63                              unsupported = False,
64                              test_exec_root = None,
65                              test_source_root = None,
66                              excludes = [],
67                              available_features = available_features,
68                              pipefail = True)
69
70     def load_from_path(self, path, litConfig):
71         """
72         load_from_path(path, litConfig)
73
74         Load the configuration module at the provided path into the given config
75         object.
76         """
77
78         # Load the config script data.
79         data = None
80         if not OldPy:
81             f = open(path)
82             try:
83                 data = f.read()
84             except:
85                 litConfig.fatal('unable to load config file: %r' % (path,))
86             f.close()
87
88         # Execute the config script to initialize the object.
89         cfg_globals = dict(globals())
90         cfg_globals['config'] = self
91         cfg_globals['lit_config'] = litConfig
92         cfg_globals['__file__'] = path
93         try:
94             if OldPy:
95                 execfile(path, cfg_globals)
96             else:
97                 exec(compile(data, path, 'exec'), cfg_globals, None)
98             if litConfig.debug:
99                 litConfig.note('... loaded config %r' % path)
100         except SystemExit:
101             e = sys.exc_info()[1]
102             # We allow normal system exit inside a config file to just
103             # return control without error.
104             if e.args:
105                 raise
106         except:
107             import traceback
108             litConfig.fatal(
109                 'unable to parse config file %r, traceback: %s' % (
110                     path, traceback.format_exc()))
111
112         self.finish(litConfig)
113
114     def __init__(self, parent, name, suffixes, test_format,
115                  environment, substitutions, unsupported,
116                  test_exec_root, test_source_root, excludes,
117                  available_features, pipefail):
118         self.parent = parent
119         self.name = str(name)
120         self.suffixes = set(suffixes)
121         self.test_format = test_format
122         self.environment = dict(environment)
123         self.substitutions = list(substitutions)
124         self.unsupported = unsupported
125         self.test_exec_root = test_exec_root
126         self.test_source_root = test_source_root
127         self.excludes = set(excludes)
128         self.available_features = set(available_features)
129         self.pipefail = pipefail
130
131     def finish(self, litConfig):
132         """finish() - Finish this config object, after loading is complete."""
133
134         self.name = str(self.name)
135         self.suffixes = set(self.suffixes)
136         self.environment = dict(self.environment)
137         self.substitutions = list(self.substitutions)
138         if self.test_exec_root is not None:
139             # FIXME: This should really only be suite in test suite config
140             # files. Should we distinguish them?
141             self.test_exec_root = str(self.test_exec_root)
142         if self.test_source_root is not None:
143             # FIXME: This should really only be suite in test suite config
144             # files. Should we distinguish them?
145             self.test_source_root = str(self.test_source_root)
146         self.excludes = set(self.excludes)
147
148     @property
149     def root(self):
150         """root attribute - The root configuration for the test suite."""
151         if self.parent is None:
152             return self
153         else:
154             return self.parent.root
155