Disable the crash reporter when running lit tests.
[oota-llvm.git] / utils / lit / lit / TestingConfig.py
1 import os
2 import sys
3
4 class TestingConfig:
5     """"
6     TestingConfig - Information on the tests inside a suite.
7     """
8
9     @staticmethod
10     def frompath(path, parent, litConfig, mustExist, config = None):
11         if config is None:
12             # Set the environment based on the command line arguments.
13             environment = {
14                 'LIBRARY_PATH' : os.environ.get('LIBRARY_PATH',''),
15                 'LD_LIBRARY_PATH' : os.environ.get('LD_LIBRARY_PATH',''),
16                 'PATH' : os.pathsep.join(litConfig.path +
17                                          [os.environ.get('PATH','')]),
18                 'SYSTEMROOT' : os.environ.get('SYSTEMROOT',''),
19                 'LLVM_DISABLE_CRASH_REPORT' : '1',
20                 }
21
22             if sys.platform == 'win32':
23                 environment.update({
24                         'PATHEXT' : os.environ.get('PATHEXT',''),
25                         'PYTHONUNBUFFERED' : '1',
26                         'TEMP' : os.environ.get('TEMP',''),
27                         'TMP' : os.environ.get('TMP',''),
28                         })
29
30             config = TestingConfig(parent,
31                                    name = '<unnamed>',
32                                    suffixes = set(),
33                                    test_format = None,
34                                    environment = environment,
35                                    substitutions = [],
36                                    unsupported = False,
37                                    on_clone = None,
38                                    test_exec_root = None,
39                                    test_source_root = None,
40                                    excludes = [],
41                                    available_features = [])
42
43         if os.path.exists(path):
44             # FIXME: Improve detection and error reporting of errors in the
45             # config file.
46             f = open(path)
47             cfg_globals = dict(globals())
48             cfg_globals['config'] = config
49             cfg_globals['lit'] = litConfig
50             cfg_globals['__file__'] = path
51             try:
52                 exec f in cfg_globals
53             except SystemExit,status:
54                 # We allow normal system exit inside a config file to just
55                 # return control without error.
56                 if status.args:
57                     raise
58             f.close()
59         elif mustExist:
60             litConfig.fatal('unable to load config from %r ' % path)
61
62         config.finish(litConfig)
63         return config
64
65     def __init__(self, parent, name, suffixes, test_format,
66                  environment, substitutions, unsupported, on_clone,
67                  test_exec_root, test_source_root, excludes,
68                  available_features):
69         self.parent = parent
70         self.name = str(name)
71         self.suffixes = set(suffixes)
72         self.test_format = test_format
73         self.environment = dict(environment)
74         self.substitutions = list(substitutions)
75         self.unsupported = unsupported
76         self.on_clone = on_clone
77         self.test_exec_root = test_exec_root
78         self.test_source_root = test_source_root
79         self.excludes = set(excludes)
80         self.available_features = set(available_features)
81
82     def clone(self, path):
83         # FIXME: Chain implementations?
84         #
85         # FIXME: Allow extra parameters?
86         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
87                             self.environment, self.substitutions,
88                             self.unsupported, self.on_clone,
89                             self.test_exec_root, self.test_source_root,
90                             self.excludes, self.available_features)
91         if cfg.on_clone:
92             cfg.on_clone(self, cfg, path)
93         return cfg
94
95     def finish(self, litConfig):
96         """finish() - Finish this config object, after loading is complete."""
97
98         self.name = str(self.name)
99         self.suffixes = set(self.suffixes)
100         self.environment = dict(self.environment)
101         self.substitutions = list(self.substitutions)
102         if self.test_exec_root is not None:
103             # FIXME: This should really only be suite in test suite config
104             # files. Should we distinguish them?
105             self.test_exec_root = str(self.test_exec_root)
106         if self.test_source_root is not None:
107             # FIXME: This should really only be suite in test suite config
108             # files. Should we distinguish them?
109             self.test_source_root = str(self.test_source_root)
110         self.excludes = set(self.excludes)