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