Index: docs/CommandGuide/lit.rst =================================================================== --- docs/CommandGuide/lit.rst +++ docs/CommandGuide/lit.rst @@ -51,6 +51,12 @@ Run ``N`` tests in parallel. By default, this is automatically chosen to match the number of detected available CPUs. +.. option:: --config=FILE + + Add a test suite configuration to be preloaded into the test suite cache during + test discovery. This option can be used to load configuration files that are + generated by out-of-dir builds. + .. option:: --config-prefix=NAME Search for :file:`{NAME}.cfg` and :file:`{NAME}.site.cfg` when searching for @@ -262,9 +268,18 @@ :program:`lit` identifies test suites as directories containing ``lit.cfg`` or ``lit.site.cfg`` files (see also :option:`--config-prefix`). Test suites are -initially discovered by recursively searching up the directory hierarchy for -all the input files passed on the command line. You can use -:option:`--show-suites` to display the discovered test suites at startup. +initially discovered in two ways. + +1. By loading the suite configurations specified in the :option:`--config` +option and the ``LIT_CONFIG`` enviroment variable. Where ``LIT_CONFIG`` is a +colon separated list of configuration files. + +2. By recursively searching up the directory hierarchy for all the input files +passed on the command line. + + +You can use :option:`--show-suites` to display the discovered test suites at +startup. (Note: Only suites containing tests will be displayed). Once a test suite is discovered, its config file is loaded. Config files themselves are Python modules which will be executed. When the config file is Index: utils/lit/lit/discovery.py =================================================================== --- utils/lit/lit/discovery.py +++ utils/lit/lit/discovery.py @@ -189,7 +189,7 @@ if sub_ts and not N: litConfig.warning('test suite %r contained no tests' % sub_ts.name) -def find_tests_for_inputs(lit_config, inputs): +def find_tests_for_inputs(lit_config, inputs, suite_inputs=[]): """ find_tests_for_inputs(lit_config, inputs) -> [Test] @@ -211,10 +211,34 @@ f.close() else: actual_inputs.append(input) - + # Load the tests from the inputs. tests = [] test_suite_cache = {} + # Preload the test suite cache by filling it with explicitly specified test + # suites. Make sure each test suite is only loaded once by checking that it + # doesn't already exist in the cache and an extra list of seen test suites. + # NOTE: The path that is used as a key in the cache can differ from the + # path that was used to load the suites. + test_suites_seen = set() + for cfgpath in suite_inputs: + cfgpath = os.path.realpath(cfgpath) + if not os.path.isfile(cfgpath): + lit_config.warning('Invalid config file: %s' % cfgpath) + break + if cfgpath in test_suites_seen or \ + cfgpath in test_suite_cache.keys(): + break + if lit_config.debug: + lit_config.note('Loading config file: %s' % cfgpath) + test_suites_seen.add(cfgpath) + cfg = TestingConfig.fromdefaults(lit_config) + cfg.load_from_path(cfgpath, lit_config) + path = os.path.dirname(cfgpath) + source_root = os.path.realpath(cfg.test_source_root or path) + exec_root = os.path.realpath(cfg.test_exec_root or path) + test_suite_cache[source_root] = Test.TestSuite(cfg.name, source_root, exec_root, cfg), () + local_config_cache = {} for input in actual_inputs: prev = len(tests) Index: utils/lit/lit/main.py =================================================================== --- utils/lit/lit/main.py +++ utils/lit/lit/main.py @@ -143,6 +143,9 @@ parser.add_option("-j", "--threads", dest="numThreads", metavar="N", help="Number of testing threads", type=int, action="store", default=None) + parser.add_option('--config', dest="suiteConfigs", + metavar='FILE', help='Extra test suite configs', + type=str, action="append", default=[]) parser.add_option("", "--config-prefix", dest="configPrefix", metavar="NAME", help="Prefix for 'lit' config files", action="store", default=None) @@ -280,9 +283,17 @@ params = userParams, config_prefix = opts.configPrefix) - # Perform test discovery. + # Perform test discovery. Read in an extra list of configuration files + # from the enviroment and the command line and pass that along with the + # tests to do test discovery. + suite_configs = list(opts.suiteConfigs) + env_suites = os.environ.get('LIT_CONFIG') + if env_suites is not None: + env_suites = re.split(r'[:;]', env_suites) + suite_configs += [s.strip() for s in env_suites if s.strip()] run = lit.run.Run(litConfig, - lit.discovery.find_tests_for_inputs(litConfig, inputs)) + lit.discovery.find_tests_for_inputs( + litConfig, inputs, suite_configs)) if opts.showSuites or opts.showTests: # Aggregate the tests by suite.