Use uint16_t to store InstrNameIndices in MCInstrInfo. Add asserts to protect all...
[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                 if litConfig.debug:
54                     litConfig.note('... loaded config %r' % path)
55             except SystemExit,status:
56                 # We allow normal system exit inside a config file to just
57                 # return control without error.
58                 if status.args:
59                     raise
60             f.close()
61         else:
62             if mustExist:
63                 litConfig.fatal('unable to load config from %r ' % path)
64             elif litConfig.debug:
65                 litConfig.note('... config not found  - %r' %path)
66
67         config.finish(litConfig)
68         return config
69
70     def __init__(self, parent, name, suffixes, test_format,
71                  environment, substitutions, unsupported, on_clone,
72                  test_exec_root, test_source_root, excludes,
73                  available_features):
74         self.parent = parent
75         self.name = str(name)
76         self.suffixes = set(suffixes)
77         self.test_format = test_format
78         self.environment = dict(environment)
79         self.substitutions = list(substitutions)
80         self.unsupported = unsupported
81         self.on_clone = on_clone
82         self.test_exec_root = test_exec_root
83         self.test_source_root = test_source_root
84         self.excludes = set(excludes)
85         self.available_features = set(available_features)
86
87     def clone(self, path):
88         # FIXME: Chain implementations?
89         #
90         # FIXME: Allow extra parameters?
91         cfg = TestingConfig(self, self.name, self.suffixes, self.test_format,
92                             self.environment, self.substitutions,
93                             self.unsupported, self.on_clone,
94                             self.test_exec_root, self.test_source_root,
95                             self.excludes, self.available_features)
96         if cfg.on_clone:
97             cfg.on_clone(self, cfg, path)
98         return cfg
99
100     def finish(self, litConfig):
101         """finish() - Finish this config object, after loading is complete."""
102
103         self.name = str(self.name)
104         self.suffixes = set(self.suffixes)
105         self.environment = dict(self.environment)
106         self.substitutions = list(self.substitutions)
107         if self.test_exec_root is not None:
108             # FIXME: This should really only be suite in test suite config
109             # files. Should we distinguish them?
110             self.test_exec_root = str(self.test_exec_root)
111         if self.test_source_root is not None:
112             # FIXME: This should really only be suite in test suite config
113             # files. Should we distinguish them?
114             self.test_source_root = str(self.test_source_root)
115         self.excludes = set(self.excludes)