Fix passed env var name in lit for Android tests.
[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', 'ADB', 'ANDROID_SERIAL']
28         for var in pass_vars:
29             val = os.environ.get(var, '')
30             # Check for empty string as some variables such as LD_PRELOAD cannot be empty
31             # ('') for OS's such as OpenBSD.
32             if val:
33                 environment[var] = val
34
35         if sys.platform == 'win32':
36             environment.update({
37                     'INCLUDE' : os.environ.get('INCLUDE',''),
38                     'PATHEXT' : os.environ.get('PATHEXT',''),
39                     'PYTHONUNBUFFERED' : '1',
40                     'TEMP' : os.environ.get('TEMP',''),
41                     'TMP' : os.environ.get('TMP',''),
42                     })
43
44         # The option to preserve TEMP, TMP, and TMPDIR.
45         # This is intended to check how many temporary files would be generated
46         # (and be not cleaned up) in automated builders.
47         if 'LIT_PRESERVES_TMP' in os.environ:
48             environment.update({
49                     'TEMP' : os.environ.get('TEMP',''),
50                     'TMP' : os.environ.get('TMP',''),
51                     'TMPDIR' : os.environ.get('TMPDIR',''),
52                     })
53
54         # Set the default available features based on the LitConfig.
55         available_features = []
56         if litConfig.useValgrind:
57             available_features.append('valgrind')
58             if litConfig.valgrindLeakCheck:
59                 available_features.append('vg_leak')
60
61         return TestingConfig(None,
62                              name = '<unnamed>',
63                              suffixes = set(),
64                              test_format = None,
65                              environment = environment,
66                              substitutions = [],
67                              unsupported = False,
68                              test_exec_root = None,
69                              test_source_root = None,
70                              excludes = [],
71                              available_features = available_features,
72                              pipefail = True)
73
74     def load_from_path(self, path, litConfig):
75         """
76         load_from_path(path, litConfig)
77
78         Load the configuration module at the provided path into the given config
79         object.
80         """
81
82         # Load the config script data.
83         data = None
84         if not OldPy:
85             f = open(path)
86             try:
87                 data = f.read()
88             except:
89                 litConfig.fatal('unable to load config file: %r' % (path,))
90             f.close()
91
92         # Execute the config script to initialize the object.
93         cfg_globals = dict(globals())
94         cfg_globals['config'] = self
95         cfg_globals['lit_config'] = litConfig
96         cfg_globals['__file__'] = path
97         try:
98             if OldPy:
99                 execfile(path, cfg_globals)
100             else:
101                 exec(compile(data, path, 'exec'), cfg_globals, None)
102             if litConfig.debug:
103                 litConfig.note('... loaded config %r' % path)
104         except SystemExit:
105             e = sys.exc_info()[1]
106             # We allow normal system exit inside a config file to just
107             # return control without error.
108             if e.args:
109                 raise
110         except:
111             import traceback
112             litConfig.fatal(
113                 'unable to parse config file %r, traceback: %s' % (
114                     path, traceback.format_exc()))
115
116         self.finish(litConfig)
117
118     def __init__(self, parent, name, suffixes, test_format,
119                  environment, substitutions, unsupported,
120                  test_exec_root, test_source_root, excludes,
121                  available_features, pipefail, limit_to_features = []):
122         self.parent = parent
123         self.name = str(name)
124         self.suffixes = set(suffixes)
125         self.test_format = test_format
126         self.environment = dict(environment)
127         self.substitutions = list(substitutions)
128         self.unsupported = unsupported
129         self.test_exec_root = test_exec_root
130         self.test_source_root = test_source_root
131         self.excludes = set(excludes)
132         self.available_features = set(available_features)
133         self.pipefail = pipefail
134         # This list is used by TestRunner.py to restrict running only tests that
135         # require one of the features in this list if this list is non-empty.
136         # Configurations can set this list to restrict the set of tests to run.
137         self.limit_to_features = set(limit_to_features)
138
139     def finish(self, litConfig):
140         """finish() - Finish this config object, after loading is complete."""
141
142         self.name = str(self.name)
143         self.suffixes = set(self.suffixes)
144         self.environment = dict(self.environment)
145         self.substitutions = list(self.substitutions)
146         if self.test_exec_root is not None:
147             # FIXME: This should really only be suite in test suite config
148             # files. Should we distinguish them?
149             self.test_exec_root = str(self.test_exec_root)
150         if self.test_source_root is not None:
151             # FIXME: This should really only be suite in test suite config
152             # files. Should we distinguish them?
153             self.test_source_root = str(self.test_source_root)
154         self.excludes = set(self.excludes)
155
156     @property
157     def root(self):
158         """root attribute - The root configuration for the test suite."""
159         if self.parent is None:
160             return self
161         else:
162             return self.parent.root
163