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