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